Hello everybody!
I have a light and a PIR that detects movement and I'm trying to create a script that turns on the light after PIR detects movement, waits 120 seconds (without using os.sleep, it does extensive load on logic machine) and then turns off the light. The catch is that I need those 120 seconds to reset as soon as PIR detects another movement while the light is ON and the 120 seconds are already running.
TL;DR: Light needs to be ON while there's movement, without it turning off after 120 seconds and without using os.sleep. Could anybody please help me?
This is what i came up with, it works but the timer doesn't reset at all. After 120 seconds light turns off and then turns on again when there's movement.
PIR object (movement detection):
Countdown object:
Thank you for any tips.
I have a light and a PIR that detects movement and I'm trying to create a script that turns on the light after PIR detects movement, waits 120 seconds (without using os.sleep, it does extensive load on logic machine) and then turns off the light. The catch is that I need those 120 seconds to reset as soon as PIR detects another movement while the light is ON and the 120 seconds are already running.
TL;DR: Light needs to be ON while there's movement, without it turning off after 120 seconds and without using os.sleep. Could anybody please help me?
This is what i came up with, it works but the timer doesn't reset at all. After 120 seconds light turns off and then turns on again when there's movement.
PIR object (movement detection):
Quote:value = event.getvalue()
switch = grp.getvalue('1/1/20')
light = grp.getvalue('1/1/6')
if (switch == false and light == false) then
if (value == true) then
grp.write('1/1/6', true)
grp.write('1/1/10', 120)
end
end
Countdown object:
Quote:value = event.getvalue()
switch = grp.getvalue('1/1/20')
while (value >= 1) do
if (switch == true) then
break
end
value = value - 1
os.sleep(1)
if (value == 0) then
grp.write('1/1/6', false)
break
end
end
Thank you for any tips.