So I was testing a LUUP function to ramp up these GE lights. It works great if they are individual scenes per room. I decided to go ahead and make the function portable so I would be able to call in from anywhere, and that’s where things go south. LUUP code in the scene :
local device = 20
local LightState = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, device)
local rampVal = LightState
local rampRate = 2
local rampTarget = 100
local sleepTime = 6
for i = 1,100 do
if (tonumber(rampVal) > tonumber(rampTarget)) then
rampVal=rampTarget
end
if (tonumber(rampVal) < tonumber(rampTarget)) then
rampVal=rampVal + rampRate
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = rampVal}, device)
luup.sleep(sleepTime)
end
end
The function :
function local_functions.ramp_up(device,rampTarget,rampRate,rampDelay)
local LightState = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, device)
local rampVal=LightState
for i = 1,100 do
if (tonumber(rampVal) > tonumber(rampTarget)) then
rampVal=rampTarget
end
if (tonumber(rampVal) < tonumber(rampTarget)) then
rampVal=rampVal + rampRate
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = rampVal}, device)
luup.log("Ramping up to level : " … rampVal)
if (tonumber(rampVal) == tonumber(rampTarget)) then
i = 100
end
luup.sleep(sleepTime)
end
end
luup.log(“We are done”)
end
So I call the function, and it does mostly what I ask of it, though there is a difference. After the last call, the dimmer goes to a random value, then back to 100(or whatever the ramp target is). From the logs :
04 11/12/13 23:58:27.303 <0x2e8cc680>
50 11/12/13 23:58:27.304 luup_log:0: Ramping up to level : 100 <0x2e8cc680>
50 11/12/13 23:58:27.306 luup_log:0: We are done <0x2e8cc680>
02 11/12/13 23:58:27.373 UPDATE MANUAL ROUTE2 11=0xb7e1c7 <0x2c25f680>
02 11/12/13 23:58:27.374 ZW_Send_Data node 11 USING ROUTE 8.0.0.0 <0x2c25f680>
02 11/12/13 23:58:27.483 UPDATE MANUAL ROUTE2 11=0xb7e1c7 <0x2c25f680>
02 11/12/13 23:58:27.484 ZW_Send_Data node 11 USING ROUTE 8.0.0.0 <0x2c25f680>
06 11/12/13 23:58:27.592 Device_Variable::m_szValue_set device: 20 service: urn:upnp-org:serviceId:Dimming1 variable: LoadLevelStatus was: 0 now: 10 #hooks: 2 upnp: 0 v:0xb97628/NONE duplicate:0 <0x2c05f680>
06 11/12/13 23:58:27.593 Device_Variable::m_szValue_set device: 20 service: urn:upnp-org:serviceId:SwitchPower1 variable: Status was: 0 now: 1 #hooks: 0 upnp: 0 v:0xbab4c0/NONE duplicate:0 <0x2c05f680>
04 11/12/13 23:58:27.594 <0x2c05f680>
02 11/12/13 23:58:27.596 UPDATE MANUAL ROUTE2 11=0xb7e1c7 <0x2c25f680>
02 11/12/13 23:58:27.596 ZW_Send_Data node 11 USING ROUTE 8.0.0.0 <0x2c25f680>
06 11/12/13 23:58:27.702 Device_Variable::m_szValue_set device: 20 service: urn:upnp-org:serviceId:Dimming1 variable: LoadLevelStatus was: 10 now: 100 #hooks: 2 upnp: 0 v:0xb97628/NONE duplicate:0 <0x2c05f680>
06 11/12/13 23:58:27.703 Device_Variable::m_szValue_set device: 20 service: urn:upnp-org:serviceId:SwitchPower1 variable: Status was: 1 now: 1 #hooks: 0 upnp: 0 v:0xbab4c0/NONE duplicate:1 <0x2c05f680>
04 11/12/13 23:58:27.704 <0x2c05f680>
So in this example, I just copied the last “setTarget” that sets it to 100%, you see the log entry for “we are all done”, meaning the loop count it done. Then right after that it send the target from what it thinks is “0” to 10, then from 10 back to 100. Obviously this is not right, but I’m not sure why.
Any ideas?