Legrand Lighting Control

Greetings,

Long story short, I’m a novice with Vera but will be trying to implement a plug-in to control Legrand lighting. (I’ll be doing this via a serial interface to a to RF controller that Legrand makes). I originally posted in the lighting forum, but I believe it’s more appropriate to document my progress here…since I’m more apt to get questions answered / suggestions made.

At this point, I’m still just trying to educate myself on uPnP, luup, Vera and the UI / json. All of this is new to me but I’m a pretty quick study. I should be receiving the the USB - Serial cable and legrand RF hardware over the next couple days, and then I’ll be able to begin in relative earnest.

I’ll be creating a parent device for the RF Controller, and then child devices representing the Legrand device groups. Initially I’ll be using the stock dimmer device for the child control, but I believe would like to eventually create my own. Being new to uPnP, luup, and JS, I think my biggest challenges will be on the programming language semantics so I can handle the incoming messages, parse them, create tables / arrays, etc.

Anyway, my first step will be just to create a simple device that can set a lighting group to a specific level, and then I’ll continue on from there.

Unfortunately, my vera is UI7 which I’m hearing lots of “complaints” about from UI5 veterans. I may try and implement with UI5 compatibility in mind, but I won’t be able to test it…so my focus will of course be on UI7.

Just got the serial to RF gateway device for Legrand, and I can successfuly connect it to my PC via usb–>serial connection and it appears to work as expected. (Though the lighting devices themselves are sometimes flaky…but that’s another story.)

I will probably try connecting it directly to the Vera, (though I don’t have one of the “approved” USB-Serial cables yet, so don’t know if it will work). Is there a way for Vera to virtually see the device attached to my PC? I thought SerProxy would do it, but while it does create a COM port device in Vera, I am not able to go to the Apps section and set the serial port parameters (it says the serial port is not available).

Should this be something relatively easy to do?

Making progress slowly but surely.

I’m definitely feeling like a novice when trying to make use of the logs. (Both my Linux and how the vera logs work.) Apparently, there’s a “verbose” setting in UI5 that doesn’t seem to exist in UI7 (or else I can’t find it.) I can ssh into my box, view the log as it’s running, etc., but I need to learn more about “grep”, and the structure of the log file itself so I can limit my viewing to more of exactly what I’m looking for. Right now I feel like when something goes wrong, I’m just “scanning” the file hoping to see something that looks out of place.

Is there a resource that documents the log file? (What the color coding is, etc.) Brief googling turned up little for me. This is what I have at the moment, but it’s pretty lacking.

I’m feeling much more confident though about the device file structure.

I’ve created (pretty bare bones) parent device, implementation, service, and json files. And the parent start-up json creates a couple ‘hard coded’ children devices (dimmer controls). I should be getting my “compatible” USB–>serial dongle some time today and so later today I hope to have my first “hello world” moment of actually turning off a light via one of the dimmer controls.

Once I’m able to do that, the fun will really begin. Ultimately, I will not be using the standard dimmer control, but I will be modifying it to specifically support how the legrand controls work. (Strip out all the services I don’t need, add in one or two relevant ones, customize the json to include a “full on” button…)

I have some thinking to do to come up with exactly what services I want to implement (what actions and events)…

“Hello World!”

I’ve finally got the plug-in up and running and functional at a basic level:

[ul][li]A parent device (the RF controller) is added, and paired with a serial controller.[/li]
[li]Once paired, It spawns child devices based on hard coded group IDs. (The groupID is Legrand’s internal identifier for lighting controls.)[/li]
[li]The child devices are standard DimmableLights used in Vera’s UI7.[/li]
[li]The UI control correctly turns on/off and dims the lights.[/li]
[li]The UI control correctly responds to external control. (When someone physically turns on or off, or dims a light, the UI changes accordingly.)[/li][/ul]

Next up, in no particular order…

Be able to “confirm” commands that are sent by examining the echo response of the controller. I need to figure out how to pass interrupted input back to the main incoming handler before I implement this.

Child device management, including

  1. Automatically scan for and add lighting groups. This is tricky because in my experience (either due to flaky RF lighting devices, spottiness of the network, who knows…), the hardware auto scanning capability is not terribly reliable in properly picking up and reporting lighting groups.
  2. Because of inhernet unreliability of 1, implement a “pseudo” automatic child device addition. (Put the Vera controller in “listen” mode for example, press a switch, and have Vera add the group when it senses the input)

Custom UI
A couple reasons:

  1. For the legrand lights, I need to have an additional control button, for “Full On”. The Vera interface sends a “ramp to 100%” when you switch the UI to “on”. However, what should happen when you “turn on” a light, is that it goes to its “last ramp state.” In other words, if the light was dimmed at 50% when you turned it off last, turning it on again should put it back to 50%, not 100%.

But there are times when you do want to “turn it on at full power regardless of the last state.” That’s what the “full on” button is for. (On the physical lighting controls, “double tapping” them performs this function.)

  1. Is it me, or is the UI7 “multi-state-button” control (the one that is used for on/off switches) slow? It’s not that the command it sends out is slow, it’s that you click on it, the event happens, but you get a “spinner” for several seconds before the UI control visually updates. The slider doesn’t do this…it works as you would expect.

Respond to hand-held controllers
Legrand sells small hand-held remote control devices. When these are used special handling will be required in order to pick up what lighting changes were made in order to properly update the Vera UI.

Custom programming / binding groups to room and house scenes.
Legrand has physical way to program lighting groups into “rooms” so they can be controlled with certain remotes. It’s a hit and miss process that can be better handled with the serial controller.

I’m at the point where I essentially have a beta version:

Child Device Management: Functionality is now in place. You can either “auto scan” for legrand devices, or put Vera into “manual pairing mode” where Vera will “listen” for your devices as you turn them on and off.

Respond to Hand-Held controllers: Functionality is now in place. Due to the nature of how legrand implemented their system, the best that can be done in response to someone issuing a lighting command from a hand-held legrand controller is to poll all of the lighting devices for their current levels. Right now, when a hand-held controller command is sensed, the plug-in will poll every lighting device (1 device every 5 seconds) to get the lighting level for all devices in the house.

Custom programming / binding groups to room and house scenes: This is half-way done. There is now UI to guide you through binding devices to “house” scenes. I have not implemented a UI for “room” scenes yet for a couple reasons. 1, it’s more complicated and would greatly benefit from a more custom UI (custom javascript), see below. 2. Room binding is fairly intuitive from the hand-held device itself.

Some general comments:

Currently, all of the UI7 tabs I created are of the “flash” type. That is, they use only the standard Vera components for the UI. While functional, the use of other types of controls (drop-downs, check-boxes, radio buttons) would make for a nicer interface. At some point I will put effort into learning enough java script to create my own .js files.

None of this has been tested in UI5, since I don’t have it!

I am still considering using a custom device instead of the standard “dimmable light” device for the children. I have two issues with the standard dimmable light device:

  1. The multi-state button is slow. Turning a device on or off causes the UI to “spin / pause” for several seconds.
  2. When a dimmer is off, there are two different actions that the user might want to happen when switching it “on”…either:

a) “I want to turn the light on at full brightness”
or
b) “I want to turn the light on, but at the brightness level it was at when it was last turned off.”

With the standard dimmable light, I can only code the “on” behavior to be one or the other…and there are pros and cons of doing it either way. Ideally two “on” buttons will be needed…one to handle each case.

I know there’s a good chance that I’m the only person in existence that has a Vera, Legrand whole-house lighting devices, and the Legrand serial controller. But if there is someone else out there who wants to try this out, I’m comfortable enough to release it in a beta state. Otherwise, I’ll just keep developing and not publish it until it’s more polished.

(edited for more clarity)

I now have what I would consider to be a 1.0 release candidate. Improvements from the previous version:

  1. My implementation now more fully supports both the Dimming and SwitchPower services. This should allow greater compatibility with different remote clients. In particular, the Vera android app now works as you would expect.

  2. I now support both dimmer and binary type switches. (Previously, I used the dimmer device as a universal type control to manipulate both binary and dimming switches.) When paring, the plug-in is smart enough (most of the time) to determine if each legrand “group” you are paring with should be represented with a dimmer or a binary switch:
    a) If all members of the group are switches, then it will be represented with a switch.
    b) If at least one member of the group is a dimmer, it will be represented with a dimmer.

I say the plug-in is smart enough to detect the proper device “most of the time” due to limitations in the way that Legrand reports lighting groups. I’ll spare you the gory details unless anyone wants them.

  1. The interface to pair the Legrand devices with Vera will allow you to “force” the kind of device (dimmer or binary switch) to represent your physical group. (This is in the rare case that Vera cannot correctly determine it.)

I’m not going to officially publish this right now since:

  1. there is no UI7 app store…
  2. I do not have UI5 available to test this on to be comfortable publishing it to the UI5 app store.

But if anyone want’s it…just PM me.

Next update…

I’m now becoming more “intimately familiar” with the limitations of communcations over the serial interface (or at least with my particular serial device.) For example, I created some scenes that used several of my light devices, but my serial device could not handle all the commands coming at it at once. It doesn’t buffer them in any way…

My solution was to implement a “command queue” (my own buffer of sorts)…once my implementation receives a command, it does not pass it on to the serial device itself until a set period of time after the next command in the queue. In my case, it works out that I need 2 seconds between commands to be virtually sure that all commands will be processed.

The practical consequence is that if I have a scene to “turn off 10 lights”…they will ultimately be turned off sequentially…one light every 2 seconds.

Congratulations, JoeyD, that’s a really good effort. Feel free to attach the source files to a thread in the forum; that’s what we all used to do before apps.mios.com.

Edit: spelling

I will…once I clean up the code a bit. ;D It’s functioning fine at the moment, but as this was my first experience with vera / luup, etc, I did some pretty messy things along the way.