Hi, newbie here ;D
I am trying to configure this scene to turn on the lights and TV when it detects movement and turn off the lights and TV when it doesn’t detect movement for a while.
Im using this luup code
local sensorDeviceNo = 23 – Motion Sensor device number
local lCacifos = 12 – Luzes Cacifos device number
local tTv = 11 – Tomada TV device number
local period = 300 – Seconds
local SS_SID = “urn:micasaverde-com:serviceId:SecuritySensor1” – Security Sensor Service ID
local SP_SID = “urn:upnp-org:serviceId:SwitchPower1” – Switch Power Service ID
function checkLastTrip()
local lastTrip = luup.variable_get (SS_SID, “LastTrip”, sensorDeviceNo) or os.time()
if (os.difftime (os.time(), tonumber (lastTrip)) >= period) then
luup.call_action (SP_SID, “SetTarget”, {[“newTargetValue”] = 0}, lCacifos) – Turn off Luzes Cacifos.
luup.call_action (SP_SID, “SetTarget”, {[“newTargetValue”] = 0}, tTv) – Turn off Tomada TV.
else
luup.call_delay (“checkLastTrip”, period) – Check when the sensor was last tripped every seconds.
end
end
luup.call_delay (“checkLastTrip”, period)
return true
The problem is while the sensor its detecting movement the lights and the tv keep turning off and they don’t turn on after that.
What i am doing wrong?
Thanks in advance