Can some one help me out.
I have a script to turn on a light when there is motion, and turn it of after no motion has been detected for a while.
Problem is, the script works flawlessly when I test it with one scene, once I set it up on many scenes and walk a across multiple sensor , they all turn on but usually the last scene to trigger doesnt turn off.
local DEVICE_NO_SENS_L = 29 – the light sensor device number
local DEVICE_NO_SENS_M = 32 – the motion sensor device number
local DEVICE_NO_DIM = 20 – the dimmer device number
local DELAY = 30 – time the light remains on
local LOW_LEVEL = 100 – the light level threshold for night
local DIM_LEVEL = 35 – Dimmer load level threshold
local LS_SID = “urn:micasaverde-com:serviceId:LightSensor1” – the LightSensor service ID
local SS_SID = “urn:micasaverde-com:serviceId:SecuritySensor1” – Security Sensor Service ID
local DIM_SID = “urn:upnp-org:serviceId:Dimming1” – the Dimmer service ID
local currentLevel = luup.variable_get (LS_SID, “CurrentLevel”, DEVICE_NO_SENS_L) or 0
local lightLevel = luup.variable_get(DIM_SID, “LoadLevelStatus”, DEVICE_NO_DIM) or 0
currentLevel = tonumber(currentLevel)
lightLevel = tonumber(lightLevel)
if (currentLevel >= LOW_LEVEL or lightLevel >= DIM_LEVEL) then return false end
luup.call_action(DIM_SID,“SetLoadLevelTarget”,{ newLoadlevelTarget=DIM_LEVEL }, DEVICE_NO_DIM)
function checkLastTrip()
local lastTrip = luup.variable_get (SS_SID, “LastTrip”, DEVICE_NO_SENS_M) or os.time()
local lightLevel = luup.variable_get(DIM_SID, “LoadLevelStatus”, DEVICE_NO_DIM) or 0
lightLevel = tonumber(lightLevel)
if (lightLevel ~= DIM_LEVEL) then return false end
if (os.difftime (os.time(), tonumber (lastTrip)) >= DELAY) then
luup.call_action(DIM_SID,“SetLoadLevelTarget”,{ newLoadlevelTarget=“100” },DEVICE_NO_DIM)
luup.sleep(100)
luup.call_action(DIM_SID,“SetLoadLevelTarget”,{ newLoadlevelTarget=“0” },DEVICE_NO_DIM)
else
luup.call_delay (“checkLastTrip”, DELAY) – Check when the sensor was last tripped every seconds.
end
end
luup.call_delay (“checkLastTrip”, DELAY)
return true