Piston has "1 more job pending" and doesn't execute next task


#1

This piston controls my outside lights: they should come on at sunset and stay on until 10:30pm. In addition, they should come on during the day if anyone gets home, doors get unlocked or the doorbell rings. If triggered by an event, they should stay on for 20 mins.

Issue is that the light stays on all day. We open the door before sunrise, the lights come on, but they don’t turn off.

Here is my piston and log. What could be happening?

12/28/2021, 8:11:22 AM +44ms
+2ms ╔Received event [Door Lock - Front].lock = locked with a delay of 88ms
+213ms ║Setting up scheduled job for Tue, Dec 28 2021 @ 5:36:00 PM EST (in 33877s), with 1 more job pending
+224ms ╚Event processed successfully (224ms)
12/28/2021, 8:11:00 AM +668ms
+2ms ╔Received event [Door Lock - Front].lock = unlocked with a delay of 92ms
+234ms ║Setting up scheduled job for Tue, Dec 28 2021 @ 5:36:00 PM EST (in 33899s), with 1 more job pending
+242ms ╚Event processed successfully (242ms)
12/28/2021, 8:07:42 AM +166ms
+2ms ╔Received event [Michael’s iPhone X].presence = present with a delay of 191ms
+208ms ║8:07 Someone came home or door lock opened
+247ms ║Setting up scheduled job for Tue, Dec 28 2021 @ 8:27:42 AM EST (in 1199s), with 2 more jobs pending
+258ms ╚Event processed successfully (258ms)
12/28/2021, 7:38:32 AM +434ms
+2ms ╔Received event [Door Lock - Front].lock = locked with a delay of 118ms
+10144ms ║Piston waited at a semaphore for 10046ms
+10203ms ║Setting up scheduled job for Tue, Dec 28 2021 @ 5:36:00 PM EST (in 35837s), with 1 more job pending
+10214ms ╚Event processed successfully (10214ms)
12/28/2021, 7:38:32 AM +394ms
+1ms ╔Received event [Door Lock - Front].lock = locked with a delay of 78ms
+132ms ║Setting up scheduled job for Tue, Dec 28 2021 @ 5:36:00 PM EST (in 35847s), with 1 more job pending
+143ms ╚Event processed successfully (143ms)
12/28/2021, 7:38:01 AM +237ms
+2ms ╔Received event [Door Lock - Front].lock = unlocked with a delay of 119ms
+229ms ║7:38 Someone came home or door lock opened
+309ms ║Setting up scheduled job for Tue, Dec 28 2021 @ 7:58:01 AM EST (in 1199s), with 2 more jobs pending
+352ms ╚Event processed successfully (352ms)


#2

you can monitor with full logging.

I don’t think you want to set the variable ‘counter’ to 0 in the define section. You want to leave it unset, so that it holds the value across runs.

As is - this means any time the piston runs it will get zeroed.

Also changing counter at the bottom of the piston does not reset the Every block schedules above (ordering of execution). You may want the every blocks at the end.

Do note that for every blocks, when a timer fires for a block, it only executes that 1 block of code ( that every, not the entire piston - you can think of it as if there is an exit command at the end of each ‘every’ block). You can also think of it as the code inside the every block will only run when the timer fires.


#3

There may, or may not, be other issues, but what you are encountering is the Task Cancellation Policy in action.

Someone unlocks the door and the lights are turned on followed by 20 minute wait. That is implemented by setting a timer for 20 minutes time and exiting the piston. If no other events come along in those 20 minutes the piston will start a new instance, fast forward to where it was, and continue after the wait. The timer is known as a ‘scheduled task’.

An event does happen during the wait though … the door gets locked. As the piston isn’t already running it can start a new instance. This time the conditional group at the bottom of the piston returns false so the piston has a dilemma. What does it do about the scheduled task? It was created when the conditional was true so is it still needed? By default the Task Cancellation Policy assumes not.

If you had had full logging on you should have been able to see the timer event still happened but the piston did nothing.

If you edit either the wait action or the enclosing with, you will see you can set the Task Cancellation Policy to ‘Never Cancel’ (click on the cog icon in the edit box) and that will make sure the scheduled task still runs.


#4

[quote=“orangebucket, post:3, topic:20374”]

Thank you much! I didn’t know about the task cancellation policy. I set it, so hopefully it will work correctly.

Appreciate all the help from everyone! Happy New Year!