I have a scene which runs on a schedule trigger. Before running at the scheduled time I would like to check the status of a switch. if that switch is on then I don’t want the schedule to run. How can I achieve this.
I cant have a schedule and switch as a trigger as then the scene would run if either condition is true. I tried adding some code in the LUA section of the scene, but by then the scene has already run.
local dID = 32 -- Device ID of your VirtualSwitch
local allow = true -- true runs scene if switch is on, false blocks it
local status = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",dID)
return ((status == "1") == allow)
I understand all lines apart from the last one. How does that work?
It doesn’t. At least, not the way that I suspect it was intended
The problem with
return ((status == "1") == allow)
is that if the switch status is “0” and allow has, in fact, been set to false, then this statement returns true, and the scene is run.
What you probably want is
return (status == "1") and allow
Thank you Akbooer. Your prediction was correct. I tested that scenario of status ) and allow = false and I did get a false positive. I implemented your code and it works perfectly. Thank you very much.