Lua PIR problem - Switching off too early
Posted: Friday 12 May 2017 18:26
Hi
I have a PIR PIRCeiling and a script script_device_PIRCeiling.lua that should be updating a user variable TIMERCeiling to the value of a var ceilingTimer each time it switches to 'On'. If the switch Ceiling is not already 'On', it should switch it on.
A timer script script_time_Ceiling.lua should check the value of the user variable TIMERCeiling each time it fires and if it equals 1 should switch-off Ceiling. Otherwise, it should decrement TIMERCeiling by 1.
So, the theory is that each time there's a movement, TIMERCeiling is reset to 6 and if no movement is detected for 5-6 minutes Ceiling should be switched off.
The problem is that although the switch on happens correctly (but with a few seconds delay - any ideas about that would be welcome), even though there's significant movement that seems to be triggering the PIR, the timer is switching off the light before people leave the room. Any ideas please? (I'm hoping there's something really stupid that I am missing here, so please be brutal!
)
I have a PIR PIRCeiling and a script script_device_PIRCeiling.lua that should be updating a user variable TIMERCeiling to the value of a var ceilingTimer each time it switches to 'On'. If the switch Ceiling is not already 'On', it should switch it on.
Code: Select all
commandArray={}
ceilingTimer=6
if (deviceChanged['PIRCeiling']=='On' then
if (other devices['Ceiling']=='Off') then
commandArray['Ceiling']='On'
end
commandArray['Variable:TIMERCeiling']=tostring(ceilingTimer)
end
return commandArray
Code: Select all
commandArray={}
if (uservariables['TIMERCeiling']==1) then
if (otherdevices['Ceiling']=='On') then
commandArray['Ceiling']='Off'
end
else
commandArray['Variable:TIMERCeiling']=tostring(uservariables['TIMERCeiling']-1)
end
return commandArray
The problem is that although the switch on happens correctly (but with a few seconds delay - any ideas about that would be welcome), even though there's significant movement that seems to be triggering the PIR, the timer is switching off the light before people leave the room. Any ideas please? (I'm hoping there's something really stupid that I am missing here, so please be brutal!
