Hi,
What is wrong with this? I am trying to switch off after a delay but only if another device is off:
local lul_tmp = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 18)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },20)
if (lul_tmp == “0”) then
luup.call_delay( ‘switch_off’, 2) – Call the switch off function after a delay of 2 seconds
function switch_off()
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },20)
end
Thanks,
Your switch_off fonction must be global and so not d?clare inside your if then end
That makes sense. Thank you. But what to do. I tried this, but it also doesn’t work:
local lul_tmp = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 18)
function switch_off()
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },20)
if (lul_tmp == “0”) then
luup.call_delay( ‘switch_off’, 2) – Call the switch off function after a delay of 2 seconds
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },20)
end
I put my global functions in my startup Lua so that all of my scenes can share the code. I’m not sure if this’ll fix what you’re doing.
I’m no pro, but I think you’ve got a issue where you declare a variable local - and that makes it so that it can’t be seen in the switchoff() function.
lul_tmp can’t be seen inside the function unless you pass it as an argument
[quote=“clausnilsson, post:3, topic:177746”]That makes sense. Thank you. But what to do. I tried this, but it also doesn’t work:
local lul_tmp = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 18)
function switch_off()
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },20)
if (lul_tmp == “0”) then
luup.call_delay( ‘switch_off’, 2) – Call the switch off function after a delay of 2 seconds
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },20)
end[/quote]
A 'end" is missing for your function.
Yes! This code is working. Thank you very much for very good input. Very helpful considering my current skill level in this area.
local lul_tmp = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 18)
function switch_off()
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },20)
end
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },20)
if (lul_tmp == “0”) then
luup.call_delay( ‘switch_off’, 120) – Call the switch off function after a delay of 2 minutes
end