1) Give a description of the problem
I have a piston to control the light in my garage that’s working perfectly, but I don’t understand why it’s working, specifically with respect to the Task Cancellation Policy and the Task Scheduling Policy. The green snapshot for the two relevant pistons are shown below, but here’s the intent of it:
If the overhead door is open:
Turn the light off during the day.
Turn the light on at night.
If the overhead door is closed:
If the entry door (into the house) is opened, turn the light on.
If the entry door is closed and the light is still on, check for motion for 4 minutes.
If motion was detected, leave the light on.
If no motion was detected, turn the light off.
2 & 3) What is the expected behavior? & What is happening/not happening?
For this piston, the Task Cancellation Policy has been left at “Cancel tasks on condition state change (default)” for all tasks, and the Task Scheduling Policy has been left at “Override any existing scheduled tasks (default)” for all tasks.
On lines 64-67, I’m checking to see if a variable is set to true, and then immediately setting it to false:
Why doesn’t the Task Cancellation Policy cause this to cancel all the remaining tasks in this if-block? I thought that maybe this only gets evaluated after a Wait task resumes execution, but there is a Wait task in this block and all of the tasks after the Wait still get executed correctly. I’ve seen this example used in other pistons, which is why I did it this way, but I don’t understand why it works.
Then, I have this sequence of events, where the initial state is all doors closed and the light off:
Entry door is opened.
Light turns on.
Entry door is closed.
Wait starts.
Overhead door is opened.
Wait is canceled.
Is the Wait canceled because of the Task Cancellation Policy or the Task Scheduling Policy (or something else)? The only condition surrounding the Wait is the startTimer
variable. This was set to false, but it didn’t seem to cancel the tasks in the previous scenario, so why did it do it in this one? For the Task Scheduling Policy, does it cancel any existing schedules every time the piston executes, or is it only when a subsequent execution creates a new schedule? Do the every
blocks in this particular piston cause the piston to create a new schedule every time it executes?
4) Post a Green Snapshot of the piston