Problems with motion sensor scene


I have a problem with a scene where I wan’t a light to turn on if it’s day and movement is detected of my SP103. Added a luup script for it to turn of after 45 seconds but if anyone remain in the room after 45 seconds it doesn’t seem to react again until I leave the room and come back again. I want it to trip again directly after the 45 seconds have gone if there is still movement in the room

Any ideas?

Luup script below


[code]local sensorDeviceNo = 29 – Motion Sensor device number
local lightDeviceNo = 5 – Light device number
local period = 45 – 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}, lightDeviceNo) – Turn off the light.
luup.call_delay (“checkLastTrip”, period) – Check when the sensor was last tripped every seconds.

luup.call_delay (“checkLastTrip”, period)

return true[/code]

Mikael, can I clarify what you are trying to do? You want the light to turn off 45 seconds after motion activity in the room ceases? (But only during daytime.) So, if someone stays in the room and keeps tripping the sensor, the 45 seconds starts again?

Thanks’ for your reply

Your assumtion is correct


If you are on UI5, see my new plugin “Countdown Timer” (sorry, using phone forum client so can’t get you a clickable link; look for it in the Scene Scripting forum). It can do this pretty much without needing Luup at all.

Edit: Here

Thank You!

Will try that