Inactive motion sensor not turning off light switch


#1

1) Give a description of the problem
The following piston does not turn off the light switch. I am trying to use a motion sensor to turn a light off when no motion is detected. It works fine if I trigger the motion sensor and exit the room. But if I never enter the room then the light never turns off.

2) What is the expected behaviour?
The light turns on and motion sensor is never triggered. After a set amount of time, the light turns off.

3) What is happening/not happening?
This piston works as expected when I use the Test function. But it never turns off the light otherwise.

4) Post a Green Snapshot of the pistonimage

5) Attach logs after turning logging level to Full
(PASTE YOUR LOGS HERE THEN HIGHLIGHT ALL OF THE LOGS AND CLICK ON THE </> ICON TO FORMAT THEM CORRECTLY)
|+0ms|╔Starting piston… (v0.3.113.20210203)|
|—|---|
|+174ms|║╔Subscribing to devices…|
|+208ms|║║Subscribing to Garage Motion Sensor.motion…|
|+268ms|║║Subscribing to Garage…|
|+269ms|║╚Finished subscribing (108ms)|
|+305ms|║Comparison (enum) on is (string) on = true (2ms)|
|+316ms|║Comparison (enum) inactive stays (string) inactive = true (1ms)|
|+328ms|╚Piston successfully started (327ms)|


#2

You need to invert the order of the ‘is’ vs. ‘stays’ (ie make the trigger first in the if)

webcore does if optimization that if the first part of the AND fails, it won’t execute the rest.

The stays needs to be ‘execute’ or ‘run over’ every time an event occurs or else it can’t keep track


#3

The stays condition is classed as a trigger and because it is your only explicit trigger your piston only runs automatically when there is a motion event.

I’d suggest something like:

if switch is on
and motion is inactive
then
  wait 20 seconds
  turn switch off
end if

There aren’t any trigger conditions so webCoRE looks to ordinary conditions to see what to subscribe to and so your piston would run whenever either the switch or motion changes. If the switch is on and motion is inactive when the piston runs the timer is started. If not the timer will be cancelled automatically by webCoRE.


#4

This works but the issue with this approach is that the light flickers off/on if I walk in the room during the 20s WAIT period.


#5

OK but what is making it do that? It isn’t the piston.


#6

The way I see it, if motion is not active and I turn the light on, then the IF condition is met. Therefore, 20 seconds later the switch turns off no matter what. It does not matter if if motion becomes active in those 20 seconds. Motion turns it back on again immediately, flickering the light.

I think I need a fancier way to do this or maybe use something like Node Red.


#7

A wait over five seconds is implemented by setting a wake-up timer and exiting the piston. This is called a scheduled task. If the piston doesn’t run during that wait the timer will fire the piston which will fast forward past the wait and continue where it left off, so turning the light off.

if the motion goes active during the twenty second wait the piston will be fired and as there isn’t an instance already running it will start executing and will return false for the if condition. As the condition result has changed since the piston last ran the default Task Cancellation Policy will be applied and any existing Scheduled Tasks will be cancelled as it is assumed they are no longer needed. This means that when the timer fires the piston it will wake up, find there isn’t anything to do, and exit again. So the light will be not be turned off.


#8

Looks like you’re right, your suggestion works. I was pretty sure I had already tried it before with the off/on flicker as the result but guess not.