Simple Piston to turn on light for 5 minutes when door opens or with motion turns on but doesn't turn off!


#1

1) Give a description of the problem
It’s really a simple piston. Have outdoor light come on for 5 minutes if the door opens or motion is sensed: Light turns on just fine but the piston never executes turning off the light.

2) What is the expected behaviour?
to just run this simple execution:
‘Turn On’
‘Wait 5 minutes’
‘Turn off’

3) What is happening/not happening?
The light turns on just fine and the log shows a wake-up set for 300seconds (5min) later, but then the piston never executes the wake-up to turn the light off!

**4) Post a Green Snapshot of the piston![image|45x37]

5) Attach logs after turning logging level to Full
You can see with the log below that the door opens and the light turns on at 7:32pm. As well a wake-up is set for 300 seconds later (7:37pm), but then the wakeup never takes place:

12/10/2019, 8:03:05 PM +310ms
+1ms ╔Received event [Front Door].contact = open with a delay of 114ms
+106ms ║RunTime Analysis CS > 18ms > PS > 38ms > PE > 50ms > CE
+108ms ║Runtime (41770 bytes) successfully initialized in 38ms (v0.3.110.20191009) (107ms)
+109ms ║╔Execution stage started
+126ms ║║Comparison (time) 72185424 is_between (time) 1576025460000 … (time) 1575990720000 = true (9ms)
+127ms ║║Time restriction check passed
+128ms ║║Condition #1 evaluated true (15ms)
+129ms ║║Cancelling condition #11’s schedules…
+130ms ║║Condition group #11 evaluated true (state changed) (17ms)
+134ms ║║Comparison (enum) open changes_to (string) open = true (1ms)
+135ms ║║Cancelling condition #12’s schedules…
+136ms ║║Condition #12 evaluated true (5ms)
+137ms ║║Condition group #11 evaluated true (state did not change) (6ms)
+139ms ║║Cancelling statement #13’s schedules…
+147ms ║║Skipped execution of physical command [Front Porch Light].on([]) because it would make no change to the device. (4ms)
+147ms ║║Executed [Front Porch Light].on (6ms)
+150ms ║║Cancelling statement #33’s schedules…
+153ms ║║Executed virtual command wait (0ms)
+154ms ║║Requesting a wake up for Tue, Dec 10 2019 @ 8:08:05 PM PST (in 300.0s)
+158ms ║╚Execution stage complete. (49ms)
+160ms ║Setting up scheduled job for Tue, Dec 10 2019 @ 8:08:05 PM PST (in 299.995s), with 1 more job pending
+171ms ╚Event processed successfully (170ms)
12/10/2019, 7:32:46 PM +761ms
+1ms ╔Received event [Front Door].contact = closed with a delay of 117ms
+108ms ║RunTime Analysis CS > 19ms > PS > 35ms > PE > 53ms > CE
+111ms ║Runtime (41765 bytes) successfully initialized in 35ms (v0.3.110.20191009) (108ms)
+112ms ║╔Execution stage started
+129ms ║║Comparison (time) 70366877 is_between (time) 1576025460000 … (time) 1575990720000 = true (9ms)
+130ms ║║Time restriction check passed
+132ms ║║Condition #1 evaluated true (16ms)
+133ms ║║Condition group #11 evaluated true (state did not change) (17ms)
+137ms ║║Comparison (enum) closed changes_to (string) open = false (1ms)
+138ms ║║Cancelling condition #12’s schedules…
+139ms ║║Condition #12 evaluated false (5ms)
+140ms ║║Cancelling condition #11’s schedules…
+141ms ║║Condition group #11 evaluated false (state changed) (7ms)
+153ms ║║Comparison (time) 70366904 is_between (time) 1576025460000 … (time) 0 = true (7ms)
+154ms ║║Time restriction check passed
+156ms ║║Condition #27 evaluated true (13ms)
+157ms ║║Cancelling condition #17’s schedules…
+158ms ║║Condition group #17 evaluated true (state changed) (14ms)
+166ms ║║Condition #18 evaluated false (7ms)
+173ms ║║Condition #26 evaluated false (6ms)
+174ms ║║Condition group #25 evaluated false (state did not change) (15ms)
+175ms ║║Cancelling condition #17’s schedules…
+176ms ║║Condition group #17 evaluated false (state changed) (17ms)
+181ms ║║Comparison (time) 70366940 happens_daily_at (time) 1575990720000 = false (1ms)
+182ms ║║Condition #29 evaluated false (4ms)
+183ms ║║Cancelling statement #29’s schedules…
+188ms ║║Requesting time schedule wake up at Wed, Dec 11 2019 @ 7:17:00 AM PST
+190ms ║║Condition group #28 evaluated false (state did not change) (12ms)
+193ms ║╚Execution stage complete. (81ms)
+194ms ║Setting up scheduled job for Wed, Dec 11 2019 @ 7:17:00 AM PST (in 42253.046s)
+204ms ╚Event processed successfully (204ms)
12/10/2019, 7:32:44 PM +112ms
+1ms ╔Received event [Front Door].contact = open with a delay of 115ms
+117ms ║RunTime Analysis CS > 24ms > PS > 39ms > PE > 55ms > CE
+120ms ║Runtime (41770 bytes) successfully initialized in 39ms (v0.3.110.20191009) (119ms)
+121ms ║╔Execution stage started
+139ms ║║Comparison (time) 70364237 is_between (time) 1576025460000 … (time) 1575990720000 = true (10ms)
+140ms ║║Time restriction check passed
+142ms ║║Condition #1 evaluated true (17ms)
+143ms ║║Cancelling condition #11’s schedules…
+144ms ║║Condition group #11 evaluated true (state changed) (19ms)
+148ms ║║Comparison (enum) open changes_to (string) open = true (0ms)
+150ms ║║Cancelling condition #12’s schedules…
+151ms ║║Condition #12 evaluated true (6ms)
+152ms ║║Condition group #11 evaluated true (state did not change) (7ms)
+154ms ║║Cancelling statement #13’s schedules…
+161ms ║║Skipped execution of physical command [Front Porch Light].on([]) because it would make no change to the device. (2ms)
+161ms ║║Executed [Front Porch Light].on (4ms)
+164ms ║║Cancelling statement #33’s schedules…
+168ms ║║Executed virtual command wait (0ms)
+169ms ║║Requesting a wake up for Tue, Dec 10 2019 @ 7:37:44 PM PST (in 300.0s)
+174ms ║╚Execution stage complete. (53ms)
+176ms ║Setting up scheduled job for Tue, Dec 10 2019 @ 7:37:44 PM PST (in 299.995s), with 1 more job pending
+187ms ╚Event processed successfully (188ms)


#2

Have you tried setting the “Task Cancellation Policy” on each of the “With” statements to Never?


#3

I have not but hopefully that is the problem! I just did some troubleshooting and light turns does turn off if the front door contact does not close first! but if the door opens, then shuts, for some reason the piston does not finish the ‘wait’.

Not sure how to change the task cancellation policy of the ‘wait’ . The advanced options wheel does NOT show how to do that. Can you please let me know.


#4

Never mind. Found it. It is both under the master ‘if’ statement (which did not fix the problem) and under the swich itself (which DID fix the problem)

Thank you for the help! For me this is the most difficult part of WebCore to understand and remember to play with if things are not working right…


#5

You may also want to consider a slight change to your code to simplify it.

With
Switch 3
Do
Turn on
End with
Wait 5 minutes
With
Switch 3
Do
Turn off
End with

Instead try

With
switch 3
Do
Turn on
Wait 5 minutes
Turn off
End with

:slight_smile:

When you start writing much larger pistons you will like this better


#6

Personally, I like to break stuff like this up to avoid the semaphores and cancellation stuff.

Turn stuff on using whatever criteria you want. I would get rid of everything after the WAITs and just add this to the bottom…

If switch stays on for 5 minutes
AND motion is inactive
then turn off.


#7

I also prefer this method…

No WAITs, and no messing with Task Cancellation Policy.


#8

Yeah, @jkp I did do as you show originally and changed it to what I have now thinking it may make the difference but it obviously did not until I fixed the Task Cancellation Policy. Works both ways but your right it is better as you explain.

@Equis @WCmore I like the creative way around using the WAIT’s and dealing with the Task Cancellation issues… That is the cool thing about WebCore. More than one way to skin a cat…


#9

The way I ACTUALLY do it is to use the motion sensor as the trigger…

If motion stays inactive for 5 minutes
and switch is on
Then turn off.

Poor cat. :wink: