Fundamental question on how pistons work


#1

I have a fundamental question. Best to 1st. give as an example. Assume I have the following code:
If motion_sensor#1 changes to active
switch on light.
If motion_sensor#1 changes to inactive
wait for 20 min.
switch off light.
If this is in 1 piston, then as I enter - the motion_sensor#1 detects me and turns on the light. Now, I sit quietly for (say) 3 min. and the sensor changes to inactive. The piston - when triggered realizes it and goes to if condition #2 and triggers the wait for 20 min. after which will switch off the light.

In between (this 30 min wait) however, I start to move around and each time the 1st. IF condition triggers OR the piston is in a limbo state as it’s waiting (wait - 20 min. condition)?

What I fail to understand is how will the system realize that wait for 20 min. now is no more valid since I continue to be in the room - moving?

Please assist in understanding this fundamental architecture.


#2

Ok, let me take a shot at this…

  1. You move in room, motion detected light turns on.
  2. You sit still, motion changes to inactive, timer starts
  3. If you move again within timer count down. Motion triggers again and attempt to turn on light, but will not do anything since it is already on.
    3a. Since motion is active at this moment timer will not change and continue to countdown.

However once motion 1 goes inactive again, because you moved around. It will start that timer over again from 20 minutes.

Once there has been no motion for a complete 20 minutes it will turn off the light

Now; if you would add another task to the first trigger to cancel all pending tasks, it should stop the timer entirely until there is no motion, then the timer will kick in again


#3

You should have your motion sensor STAYING inactive for 20 minutes turning off your light. Not waiting 20 minutes after it goes inactive. That’s just going to get all kinds of crazy.
If you’re working with dimmers, and using the “set level” command, you might want to also check that the switch is off on the light you want to turn on. That way, if youre in the room and have dimmed the light and don’t want it to go bright again, it won’t, because the switch is still on. Even if you don’t move for a few minutes, it will still not trigger the piston.
Also, check the timeout on your motion sensor. Most will have an adjustable time so that they will report active for x minutes after motion stops. This way you don’t need any timers in your piston.