Hi, very new to lua/luup programming so I imagine that I’m doing something wrong here, but for the life of me I can’t figure out what. (USA vera edge, firmware 1.7.1181, the latest as of this writing.)
What I’m trying to do is turn on a binary light, then have my scene pause until it’s confirmed that the light is on, then continue execution.
The code that I have works in the ‘test luup code’, and also works if put in a scene and launched from the web:
local mydevice=50
local counter=0
local switchOnOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", mydevice)
luup.log("switchOnOff before:" .. switchOnOff)
luup.call_action("urn:upnp-org:serviceId:SwitchPower1", "SetTarget", {newTargetValue = "1"}, mydevice)
while (switchOnOff == "0" and counter < 10) do
luup.sleep (1000)
switchOnOff = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", mydevice)
luup.log ("counter: " .. counter .. " switchOnOff: " .. switchOnOff)
counter = counter + 1
end
if (counter == 10) then
luup.log ("***TIMEOUT!***")
end
If launched via the web attached to a scene, it works every time (typical output):
50 06/25/15 12:12:41.774 luup_log:0: switchOnOff before:0 <0x7491f520>
50 06/25/15 12:12:42.799 luup_log:0: counter: 0 switchOnOff: 1 <0x7491f520>
(Occasionally I’ll get counter incrementing to 1 or 2, depending on exactly how busy the vera is. To be expected.)
The problem happens when I trigger that scene from a scene controller, such as my aeon minimote or my wall scene controller. It seems as though switchOnOff will never changes state! (This is despite the light turning on right away!)
50 06/25/15 12:14:15.397 luup_log:0: switchOnOff before:0 <0x7731f520>
50 06/25/15 12:14:16.419 luup_log:0: counter: 0 switchOnOff: 0 <0x7731f520>
50 06/25/15 12:14:17.421 luup_log:0: counter: 1 switchOnOff: 0 <0x7731f520>
50 06/25/15 12:14:18.423 luup_log:0: counter: 2 switchOnOff: 0 <0x7731f520>
50 06/25/15 12:14:19.424 luup_log:0: counter: 3 switchOnOff: 0 <0x7731f520>
50 06/25/15 12:14:20.426 luup_log:0: counter: 4 switchOnOff: 0 <0x7731f520>
50 06/25/15 12:14:21.427 luup_log:0: counter: 5 switchOnOff: 0 <0x7731f520>
50 06/25/15 12:14:22.429 luup_log:0: counter: 6 switchOnOff: 0 <0x7731f520>
50 06/25/15 12:14:23.431 luup_log:0: counter: 7 switchOnOff: 0 <0x7731f520>
50 06/25/15 12:14:24.432 luup_log:0: counter: 8 switchOnOff: 0 <0x7731f520>
50 06/25/15 12:14:25.433 luup_log:0: counter: 9 switchOnOff: 0 <0x7731f520>
50 06/25/15 12:14:25.433 luup_log:0: ***TIMEOUT!*** <0x7731f520>
So… what am I doing wrong here? Why is this luup code behaving differently seemingly based solely on what is calling it? (Web vs. scene controller)
Thanks in advance!
Random things that might (not) matter… this is for a fibaro rgbw LED controller. The device I’m controlling & probing is technically a child device, as the parent device doesn’t respond to binarylight commands, nor does the parent honor status requests.