Motion triggers patio light, wait 5 min, turn off. What an I doing wrong here?


#1

1) Give a description of the problem
My patio light is not shutting off after 5 min

2) What is the expected behaviour?
It should shut off

3) What is happening/not happening?
It’s staying on

4) Post a Green Snapshot of the pistonimage

5) Attach logs after turning logging level to Full
2/2020, 1:08:23 AM +107ms
+0ms ╔Received event [Steelsmith Haus].time = 1580634504692 with a delay of -1586ms
+166ms ║RunTime Analysis CS > 42ms > PS > 73ms > PE > 51ms > CE
+168ms ║Runtime (37732 bytes) successfully initialized in 73ms (v0.3.110.20191009) (167ms)
+169ms ║╔Execution stage started
+170ms ║╚Execution stage complete. (1ms)
+171ms ╚Event processed successfully (171ms)
2/2/2020, 1:04:43 AM +276ms
+1ms ╔Received event [Patio Motion].motion = inactive with a delay of 150ms
+146ms ║RunTime Analysis CS > 25ms > PS > 73ms > PE > 48ms > CE
+148ms ║Runtime (37717 bytes) successfully initialized in 73ms (v0.3.110.20191009) (146ms)
+149ms ║╔Execution stage started
+157ms ║║Comparison (enum) inactive changes_to (string) active = false (1ms)
+158ms ║║Cancelling condition #2’s schedules…
+159ms ║║Condition #2 evaluated false (5ms)
+160ms ║║Cancelling condition #1’s schedules…
+161ms ║║Condition group #1 evaluated false (state changed) (8ms)
+163ms ║╚Execution stage complete. (14ms)
+165ms ╚Event processed successfully (164ms)
2/2/2020, 1:03:24 AM +528ms
+2ms ╔Received event [Patio Motion].motion = active with a delay of 127ms
+132ms ║RunTime Analysis CS > 18ms > PS > 69ms > PE > 44ms > CE
+134ms ║Runtime (37722 bytes) successfully initialized in 69ms (v0.3.110.20191009) (130ms)
+134ms ║╔Execution stage started
+141ms ║║Comparison (enum) active changes_to (string) active = true (1ms)
+142ms ║║Cancelling condition #2’s schedules…
+143ms ║║Condition #2 evaluated true (5ms)
+147ms ║║Comparison (string) :abbcdbd4ba75bfb189796f03741cf0ba: is (string) :abbcdbd4ba75bfb189796f03741cf0ba: = true (2ms)
+148ms ║║Condition #3 evaluated true (4ms)
+149ms ║║Cancelling condition #1’s schedules…
+150ms ║║Condition group #1 evaluated true (state changed) (12ms)
+152ms ║║Cancelling statement #4’s schedules…
+159ms ║║Skipped execution of physical command [Patio Light Switch].on([]) because it would make no change to the device. (2ms)
+159ms ║║Executed [Patio Light Switch].on (4ms)
+162ms ║║Executed virtual command [Patio Light Switch].wait (0ms)
+163ms ║║Requesting a wake up for Sun, Feb 2 2020 @ 1:08:24 AM PST (in 300.0s)
+167ms ║╚Execution stage complete. (33ms)
+168ms ║Setting up scheduled job for Sun, Feb 2 2020 @ 1:08:24 AM PST (in 299.996s)
+180ms ╚Event processed successfully (180ms)
2/2/2020, 1:02:49 AM +966ms
+1ms ╔Received event [Patio Motion].motion = inactive with a delay of 131ms
+138ms ║RunTime Analysis CS > 24ms > PS > 70ms > PE > 45ms > CE
+141ms ║Runtime (37717 bytes) successfully initialized in 70ms (v0.3.110.20191009) (138ms)
+142ms ║╔Execution stage started
+148ms ║║Comparison (enum) inactive changes_to (string) active = false (0ms)
+150ms ║║Cancelling condition #2’s schedules…
+151ms ║║Condition #2 evaluated false (5ms)
+152ms ║║Cancelling condition #1’s schedules…
+152ms ║║Condition group #1 evaluated false (state changed) (7ms)
+154ms ║╚Execution stage complete. (13ms)
+155ms ╚Event processed successfully (155ms)
2/2/2020, 1:01:41 AM +530ms
+1ms ╔Received event [Patio Motion].motion = active with a delay of 131ms
+135ms ║RunTime Analysis CS > 24ms > PS > 68ms > PE > 43ms > CE
+137ms ║Runtime (37723 bytes) successfully initialized in 68ms (v0.3.110.20191009) (135ms)
+138ms ║╔Execution stage started
+145ms ║║Comparison (enum) active changes_to (string) active = true (1ms)
+146ms ║║Cancelling condition #2’s schedules…
+147ms ║║Condition #2 evaluated true (5ms)
+151ms ║║Comparison (string) :abbcdbd4ba75bfb189796f03741cf0ba: is (string) :abbcdbd4ba75bfb189796f03741cf0ba: = true (1ms)
+152ms ║║Cancelling condition #3’s schedules…
+153ms ║║Condition #3 evaluated true (5ms)
+154ms ║║Cancelling condition #1’s schedules…
+155ms ║║Condition group #1 evaluated true (state changed) (13ms)
+157ms ║║Cancelling statement #4’s schedules…
+172ms ║║Executed physical command [Patio Light Switch].on() (11ms)
+173ms ║║Executed [Patio Light Switch].on (13ms)
+176ms ║║Executed virtual command [Patio Light Switch].wait (1ms)
+177ms ║║Requesting a wake up for Sun, Feb 2 2020 @ 1:06:41 AM PST (in 300.0s)
+181ms ║╚Execution stage complete. (43ms)
+182ms ║Setting up scheduled job for Sun, Feb 2 2020 @ 1:06:41 AM PST (in 299.996s)
+190ms ╚Event processed successfully (191ms)

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

You just weren’t aware of the Task Cancellation Policy. If you want your piston to behave as you described, edit your piston, click on the ‘with’, open the settings (the cog at the bottom) and set the Task Cancellation Policy to Never Cancel.

The longer explanation is that, to implement the five minute wait (or indeed any of over five seconds), the piston schedules a new run of the piston and exits. If the piston isn’t fired again in those five minutes, it wakes up, fast forwards to the end of the wait, and continues. So it turns the light off.

In your case the piston is fired again because the motion changed to inactive. The piston now assumes that you will no longer need to do anything when the previously scheduled wake up occurs as the condition that made it happen is no longer true. It cancels the ‘scheduled task’. So the light doesn’t turn off. This is called the Task Cancellation Policy (TCP).


#3

Rather than using a wait here, you can keep the light on until the motion stops with the following:

if motion changes to active
   and
   location mode is sleep
then
   turn on
endif
if motion stays inactive for 5 minutes
then
   turn off
endif

#4

Thanks. I’ll give it a shot.


#5

I like this idea. I’ll try this first thanks.


#6

Does this look right?


#7

Sorry @guxdude
I just jumped in - I assumed you were not around to answer - and when I first started I was keep refreshing my screen to get an answer fast and feeling frustrated if answers didn’t come :))))

@CaptainDrew
You need to get that second IF block line #29 and put it AFTER line #38
they have to be seperate/indepented 2 IF blocks.

Once again sorry to jump in.


#8

@ike2018 don’t ever worry about jumping in. Yes, I was out so didn’t see this until now.

@CaptainDrew glad you got what you needed. If you made the changes suggested above you should be good to go.


#9

Thanks! I was wondering why it didn’t work last night. I keep doing that when selecting the group conditions. I can’t figure it the line after 38 one, but do I need it now?


#10

This looks the same. You need to get the second if down below the endif for the first condition.

if motion changes to active
   and
   location mode is sleep
then
   turn on
endif

if motion stays inactive for 5 minutes
then
   turn off
endif

#11

Alright how’s this one?


#12

Thanks yours made sense after I read it a second time. Here’s V26


#13

V26 should work perfectly:)