14.04.2017, 21:18
Hi,
I am struggling getting a script related to a presence sensor to work. I have made an event based script, but it does not turn out the way I like.
value = event.getvalue()
val1 = 15
if value == true then
grp.write('2/2/2', 1)
elseif value == false then
os.sleep(300)
grp.write('2/2/2', 0)
end
If the presence sensor (1/1/1) is triggered and writes a 1, then I would like the light (2/2/2) to be turned on.
When presence is no longer detected it writes a 0, and I would like the light to be turned off. However, I do not want the light to be turned of straight away, I would like to wait 5 min before the light is turned off.
So far so good...
This is where I am struggling, if presence again is detected before the 5 min expires, the presence sensor writes another 1. However, the previous script is still running so the light gets turned off before the last 5 min expires.
I would like a solution where another 1 from the presence detector resets the timer. So if someone constantly walks in and out of the room within a time frame of less then 5 minutes, then the light constantly stays on.
I am not sure if an event based script is the way to go...
BR
Mr. D
I am struggling getting a script related to a presence sensor to work. I have made an event based script, but it does not turn out the way I like.
value = event.getvalue()
val1 = 15
if value == true then
grp.write('2/2/2', 1)
elseif value == false then
os.sleep(300)
grp.write('2/2/2', 0)
end
If the presence sensor (1/1/1) is triggered and writes a 1, then I would like the light (2/2/2) to be turned on.
When presence is no longer detected it writes a 0, and I would like the light to be turned off. However, I do not want the light to be turned of straight away, I would like to wait 5 min before the light is turned off.
So far so good...
This is where I am struggling, if presence again is detected before the 5 min expires, the presence sensor writes another 1. However, the previous script is still running so the light gets turned off before the last 5 min expires.
I would like a solution where another 1 from the presence detector resets the timer. So if someone constantly walks in and out of the room within a time frame of less then 5 minutes, then the light constantly stays on.
I am not sure if an event based script is the way to go...
BR
Mr. D