How can I extend a motion sensor timer.

Kim T. Nielsen shared this question 11 years ago
Answered

When I use a motion sensor (Vision ZP3102) to control an on/off switch module, and want to delay switching the switch to off after the motion sensor signaled no_motion, how can this be fulfilled?


I have created a rule that turns the switch on when the sensor signals 'motion'. Then I created another rule that is trigged when the sensor signals 'no_motion', that just waited 5 minutes and if the sensor still was in state 'no_motion' it turns off the switch - but it is not working.


I want to turn off the switch if the sensor has been in state 'no_motion' for at least 5 minutes (no 'motion' in the 5 minutes).


I tried to use your stairway timer example, but without any luck - it always turns the switch off after 5 minutes.

Best Answer
photo

The problem with your rule is that the state of the a sensor doesn't get updated during the execution of a rule. We make a 'snapshot' of all states and variables present on the system at the time of the event and use it for that rule.


The idea was to save us from the concurrent programming troubles. Example of a trouble would be if you had a rule like this:

  1. when sensor1=on or sensor2=on
  2. ...
  3. if sensor1=on
  4. then do_something

There would be no guarantee that sensor1 preserved the state between these 2 lines, and we'd have a possibly unpredictable result. So, if you use something like

  1. when state_of_some_sensor = true
  2. wait 300
  3. if state_of_some_sensor = true
  4. then do_something

then the last something will ALWAYS be executed. Also same thing if you use variables.


Somewhere in the process we forgot about 'refresh' puzzles that update the snapshot used by the rule with current states and variables, but we'll add them ASAP.


Meanwhile, something like this should work

  1. when sensor=any
  2. join
  3. if sensor=motion
  4. then
  5. turn on
  6. else
  7. wait 300
  8. turn off

That 'when sensor=any' checks if the event was a change of the sensor's state, but doesn't care about the actual state of the sensor. The same thing could be achieved with 'when sensor=motion or sensor=no_motion'...

Replies (7)

photo
1

The problem with your rule is that the state of the a sensor doesn't get updated during the execution of a rule. We make a 'snapshot' of all states and variables present on the system at the time of the event and use it for that rule.


The idea was to save us from the concurrent programming troubles. Example of a trouble would be if you had a rule like this:

  1. when sensor1=on or sensor2=on
  2. ...
  3. if sensor1=on
  4. then do_something

There would be no guarantee that sensor1 preserved the state between these 2 lines, and we'd have a possibly unpredictable result. So, if you use something like

  1. when state_of_some_sensor = true
  2. wait 300
  3. if state_of_some_sensor = true
  4. then do_something

then the last something will ALWAYS be executed. Also same thing if you use variables.


Somewhere in the process we forgot about 'refresh' puzzles that update the snapshot used by the rule with current states and variables, but we'll add them ASAP.


Meanwhile, something like this should work

  1. when sensor=any
  2. join
  3. if sensor=motion
  4. then
  5. turn on
  6. else
  7. wait 300
  8. turn off

That 'when sensor=any' checks if the event was a change of the sensor's state, but doesn't care about the actual state of the sensor. The same thing could be achieved with 'when sensor=motion or sensor=no_motion'...

photo
1

I have tried the above suggested solution, and it works perfectly, thank you.


Yes, it would be a nice thing to have some kind of a 'Refresh' puzzle, that will update the status of the sensors to be used by subsequent puzzles.

photo
1

I tried to use your stairway timer example


Where did you find this example?

photo
1

DK wrote:

I tried to use your stairway timer example


Where did you find this example?

It was in the answer to my question: "How does the controls 'Join' and 'Stop' function" - http://community.zipato.com/responses/how-does-the-controls-join-and-stop-function.

photo
1

When do you think this "oversight" (refresh puzzles) will be updated ?

photo
1

since 2 eek the any state doesn't work ? wath is wrong ?

photo
1

Marcel FAGNOUL wrote:

since 2 eek the any state doesn't work ? wath is wrong ?
I have the same problem!

Leave a Comment
 
Attach a file