Leviton Scene Controller questions

I have Leviton VRCS2 and RZCS4, 2-button and 4-button controllers. They are interacting with a Vera Lite (UI5). They are all controlling some scenes and updating their LEDs well, with

luup.call_action(servicename, “SetLight”,{ [“newValue”] = 1, Indicator=“1” },device)

Currently, they’re all just simple, binary, on/off toggles. But some of them would be more useful as three-state toggles. Since there’s a few colours of LED in the units, I thought it might be nice to do some sort of progression of off->green->orange on a single button. But I can’t seem to see any way of querying the LED status on the device. Looking at the services that are defined on the Vera, I don’t see any sort of respective GetLight command. And I don’t really see any of the device’s variables (under the “Advanced” tab in the device properties) that correspond to the LEDs.

Is there any way to actually query the vera/device for it’s LED states?

Currently, no, the LED state is not tracked anywhere by Vera. There is a bug report on this, but no movement lately.
[url=http://bugs.micasaverde.com/view.php?id=1470]http://bugs.micasaverde.com/view.php?id=1470[/url]

Someone was mentioned creating internal LUUP variables to track status, but I never pursued that.

Ah, thanks. Didn’t know of the bugtracker.

To work around it, I’ve just started creating a global lua object that can house them that gets initiated in the startup luup, where I was putting common functions anyway.

Apparently, it is tracked, it’s just in a bitmap, so it’s not obvious from a first glance. So if you look at

local ls =luup.variable_get(“urn:micasaverde-com:serviceId:SceneControllerLED1”, “LightSettings”, device_id)

and convert it to bits, each bit will correspond with the colour and button, so for a 4 button Leviton, ls bit 3 will be set if button 3 is set to green. Bit 5 would be button 1 set to red. And so on.

I’d write out the function to do this, but it’s late and apparently lua doesn’t have any bitwise operators.

http://forum.micasaverde.com/index.php/topic,4992.msg28171.html#msg28171

Oh. Thanks guessed, that makes things easier.

It’s a little more complicated than I originally claimed it would be, but the following lua function should figure out what a particular LED is set to on the leviton devices. I’ve tested it with a 4-button, but it should work in the n-button case.

[code]
bit = require(“bit”)
function btn_val(button, value, num_buttons)
cbit = 0
tot = 0
for i=0,16 do
if (bit.band(2^i, value) ~= 0) then
tot = tot + (2 ^ (button-1) * 2 ^ (num_buttons*(i)))
end
end
return tot
end

function find_led_value(button, device_id)
local NumButtons = luup.variable_get(“urn:micasaverde-com:serviceId:SceneController1”, “NumButtons”, device_id)
NumButtons = tonumber(NumButtons)
if (button > NumButtons) then
luup.log(“find_led_value: Button requested cannot exceed NumButtons (”…NumButtons…“)”)
return -1
end
local ls = luup.variable_get(“urn:micasaverde-com:serviceId:SceneControllerLED1”, “LightSettings”, device_id)
ls = tonumber(ls)

for v=3,1,-1 do
b = btn_val(button,v,NumButtons)
if bit.band(b, ls) == b then
return v
end
end
return 0
end[/code]

To use it, do something like this:

value = find_led_val(2,device_id)

Where the first number is the LED in question that you would normally pass to the set led action. It will return what the led is currently set to. I’ll post this to the bug as well, I guess, so hopefully MCV can add it to the appropriate file and put it in a subsequent release.

A post was split to a new topic: Error accessing bit library