Remove buttons from a lua device

While running through the tutorial for RS232 lua plugin development, a controller device is created, and several child devices - one for each blind defined in the controller.

http://wiki.micasaverde.com/index.php/Luup_Somfy_Walkthrough

The problem is, that the devices created for the blinds have 4 buttons:

  • Close
  • Open
  • Up
  • Down
  • Stop

When I read the lua code, I see the actions & code behind the buttons ‘up’, ‘down’, ‘stop’, and I am able to add/remove these buttons. However I am unable to remove the ‘close’ and ‘open’ buttons as they seem to be part of the generic device used as template.

How can I either remove or hide the ‘close’ and ‘open’ buttons?

I am still at loss here. I have read up on the wiki documentation to get a handle on UPnP and how that is implemented in Vera. Still something keeps going wrong so clearly I have not ‘gotten it’ yet…

I want to be able to create a device and add/remove as many buttons as I like. E.g. for the device created with the somfy blind interface. I would like to remove the “up” and “down” buttons, but keep “stop” and “open” and “close”. First I tried to modify the existing files, but it seems I could not overwrite at least some of them, so I decided to work on a new set of files that are a copy of the original just with a different name “Ank” added in front (my initials if you wonder…) So the files

D_SomfyBlinds.xml → D_AnkSomfyBlinds.xml
I_SomfyBlinds.xml → I_AnkSomfyBlinds.xml
D_WindowCovering1 → D_AnkWindowCovering1.xml
S_WindowCovering1 → S_AnkWindowCovering1.xml

When working with the new files, the first step is to get them to work as good as the original functional device. Hence I only renamed references inside the files so that they point to the new file names (with ‘Ank’) and not the old ones.

I then added the device manually through the WEB UI by adding D_AnkSomfyBlinds.xml

This DID in fact create the device and with all the buttons, but when I click a button it reports an error, so something was still wrong…

I then suspected that the UPnP definitions where colliding with the original files, so I renamed these references:
urn:micasaverde-com:serviceId:SomfyBlinds1 → urn:ank-com:serviceId:SomfyBlinds1

Still the same problem, so I continued and did this renaming:
urn:schemas-micasaverde-com:device:WindowCovering:1 → urn:schemas-ank-com:device:WindowCovering:1

Now all the buttons on my child devices disappeared.

What am I missing here? Am I far from the goal or close?

Can you ZIP and upload both versions (before and after changes), and maybe a screenshot of the error referenced here:

This DID in fact create the device and with all the buttons, but when I click a button it reports an error, so something was still wrong...

I’ll see if I can look at it over the weekend. I’m assuming you attached your Device to the Serial port after this step:

I then added the device manually through the WEB UI by adding D_AnkSomfyBlinds.xml

It’ll definitely error out if it’s not explicltly attached to the specific serial port (via Devices → Luup Devices → Serial Port Config … [Attached])

@guessed

Thanks a bunch for helping. This is more than I could ask for and much appreciated!! I’ll let you know in case I find a solution too, as I will continue digging to learn this stuff.

Attached the files before and after the change.

This issue is not related to the serial port, which I am connecting to fine. It is related to my lacking understanding of the UPnP structure. I learned a ton in the somfy walkthrough http://wiki.micasaverde.com/index.php/Luup_Somfy_Walkthrough, but at the end, they skipped all the steps involved in going from

luup.chdev.append(lul_device,child_devices,s,“Blind #”…s,“urn:schemas-upnp-org:device:BinaryLight:1”,“”,“”,“”,true)

to

luup.chdev.append(lul_device,child_devices,s,“Blind #”…s,“urn:schemas-micasaverde-com:device:WindowCovering:1”,“D_WindowCovering1.xml”,“”,“”,false)

That puzzled me a lot. I tried first to understand this by removing the implemenation for “up” and “down”, but when I did, the open & close suddenly told me that they were no longer implemented. This lead me to wonder where the code behind open & close resides… I still have not found it. However it seems like the open/close code must call the up/down implementation as when up/down is removed open/close stops working…

Also I noticed in the final files, that there was a bunch of code in D_WindowCovering.xml under tags. I still have no idea what that sceneList is all about, and this was also skipped in the otherwise excellent tutorial

I have found the error in the files!

So, my learning here is, that in the file that describe the child devices (in this case D_AnkWindowCovering), the device type must be a known UPnP type. With known it means either defined by MCV or UPnP. I used a custom name as device type and that made the rest fail. Changing the type back to “urn:schemas-micasaverde-com:device:WindowCovering:1” made it work.

Another learning was that although the documentation claims that the luup.chdev.append command will override the specified type (parameter 5) with the type defined in the device file (parameter 6), then this can’t be completely true. If a proper UPnP device is used in the device file and a custom device is used in the command parameter like this:

    [code] luup.chdev.append(lul_device,child_devices,s,"AnkBlind #"..s,"urn:schemas-ank-com:device:WindowCovering:1","D_AnkWindowCovering1.xml","","",false)[/code]

then the startup sequence will never end - it seems to loop forever.
In fact, it locked up on me so bad, that I could not even upload new files. When trying that, a popup box daid “Delivery failed”. I avoided flashing vera completely by deleting the device which seemed to unlock the deadlock.

With this I am now eager to figure out:

  • how I can modify the buttons, and remove some of them (the original goal).
  • where the code behind “open” and “close” is
  • what is used for

The [tt][/tt] block declares each of the named Scene “Actions” that can be performed against your Plugin. This is typically the list you see when you create a scene defn, and want to “do” something with the device.

There are a number of blocks in the [tt][/tt] XML block, and each looks like:

"group_1":{ ..., "cmd_4": { "label": "Up", "serviceId": "urn:upnp-org:serviceId:WindowCovering1", "action": "Up" }, ...
btw, I’m not sure where the [tt]OPEN[/tt], [tt]CLOSE[/tt] and [tt]Set Level[/tt] ones came from in the “original” code in the ZIP. I’m not expecting that a Blind is either a Switch, or a Dimmer. The source file I had from before only lists [tt]Up[/tt], [tt]Down[/tt] and [tt]Stop[/tt] as actions.

Anyhow, each is a snippet of JSON that [effectively] gets loaded by the Browser component. Not sure why they don’t use XML everywhere, and just “transcribe” to JSON after upload, but that’s another story.

Each of these “entries” maps a Scene “action” (like “Up”, “Down” or “Stop” in the case of the original [tt]D_WindowCovering1.xml[/tt]) to a specific Lua/Luup serviceId/Action.

As your Parent Device has indicated that it handles child events ([tt][/tt] value of 1), then these Action handlers are expected in the Parent’s implementation ([tt]I_SomfyBlinds.xml[/tt]) file and you’ll see something like:

[code]

urn:upnp-org:serviceId:WindowCovering1
Up

local lul_command = lul_prefix … luup.devices[lul_device].id … ‘U\r’
local lul_reverse = luup.variable_get(“urn:micasaverde-com:serviceId:HaDevice1”,“ReverseOnOff”,lul_device)
if( lul_reverse==“1” ) then
lul_command = lul_prefix … luup.devices[lul_device].id … ‘D\r’
end
luup.log("ANK-Somfy-Up: " … tostring(lul_command),1)

    if luup.io.write(lul_command)==false then
      luup.log("cannot send: " .. tostring(lul_command),1)
      luup.set_failure(true)
      return false
    end
</run>
...[/code]

You’ll see that the Service Id and Name match exactly between these two. This is required, since it’s part of how one “invokes” the other at runtime.

Note that Vera’s UI’s are often hardwired to either the [tt]ServiceType[/tt], or the [tt]ServiceId[/tt], so you cannot typically add/remove “Buttons” at will. Typically you’ll be stuck with the ones provided for a given [tt]ServiceType[/tt]/[tt]ServiceId[/tt], although there’s some talk about making that more flexible in the future.

For my Alarm code, I had them write a temporary UI until the Flex/Flash one comes along.

In the short term though, each Plugin can expose as many [tt][/tt] sections as it wants. If these happen to be parameterLess, then you can register a Scene using them, and you’ll have a Button that performs that “action”, similar to Turning on a light, except it performs the “named” action in your Plugin instead (which might open a blind, send an SMS etc)

I should draw a picture, but I hope you get what I mean.