I tried my original code at home last night and got mixed results. After reviewing it more carefully, I think the logic is sound, but I made some poor choices in code when trying to write something off the cuff for you. With that in mind, I’d like to submit another attempt. This works much more reliably for me, and I believe it will for you as well. You can either use this to setup your scene to execute the commands as you already have them, or you can build the commands right into the code if you prefer. Here is the new code:
function checkdoorstatus()
if( luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped",38)=="0" ) then
luup.log("Sensor Not Tripped, ending scene")
stilltripped = "0"
else
luup.log("Sensor is still tripped!")
stilltripped = "1"
end
end
luup.call_timer("checkdoorstatus", 1, "5m", "", "")
if (stilltripped == "0") then
return false
end
Note: This code uses the call_timer function to implement a cleaner/friendlier 5 minute delay (see the 5m designation in there). You can change “5m” to just “2” if you want to go back to a 2 second delay for testing.
If you want to build the command right into the code, just replace the last bit with something like this:
if (stilltripped == "1") then
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },37)
end
This would turn off a switch with the device # 37 if the sensor is still tripped.