Can't get the piston to execute all tasks if condition changes


#1

1) Give a description of the problem
The statements in the then block should run to completion, but don’t

2) What is the expected behavior?
See above - I set the if block to “Never Cancel” but that doesn’t keep the tasks from canceling

3) What is happening/not happening?
The light should be restored, but the then block is canceled when the condition changes

**4) Post a Green Snapshot of the piston!

5) Attach any logs (From ST IDE and by turning logging level to Full)
1/9/2018, 9:57:53 PM +294ms +0ms ╔Received event [NFP].time = 1515553073490 with a delay of -197ms +90ms ║RunTime Analysis CS > 12ms > PS > 42ms > PE > 37ms > CE +93ms ║Runtime (39040 bytes) successfully initialized in 42ms (v0.2.101.20171227) (91ms) +94ms ║╔Execution stage started +95ms ║╚Execution stage complete. (1ms) +96ms ╚Event processed successfully (97ms) 1/9/2018, 9:57:47 PM +68ms +1ms ╔Received event [Back door open sensor 1].contact = closed with a delay of 70ms +106ms ║RunTime Analysis CS > 15ms > PS > 50ms > PE > 41ms > CE +108ms ║Runtime (39048 bytes) successfully initialized in 50ms (v0.2.101.20171227) (106ms) +109ms ║╔Execution stage started +119ms ║║Comparison (enum) closed stays (string) open = false (1ms) +121ms ║║Cancelling any timed trigger schedules for condition 4 +122ms ║║Cancelling statement #4's schedules... +123ms ║║Cancelling condition #4's schedules... +123ms ║║Condition #4 evaluated false (8ms) +124ms ║║Cancelling condition #1's schedules... +125ms ║║Condition group #1 evaluated false (state changed) (11ms) +128ms ║╚Execution stage complete. (18ms) +129ms ╚Event processed successfully (128ms) 1/9/2018, 9:57:43 PM +214ms +1ms ╔Received event [NFP].time = 1515553064139 with a delay of -926ms +90ms ║RunTime Analysis CS > 14ms > PS > 41ms > PE > 36ms > CE +93ms ║Runtime (39038 bytes) successfully initialized in 41ms (v0.2.101.20171227) (90ms) +95ms ║╔Execution stage started +102ms ║║Cancelling condition #4's schedules... +103ms ║║Condition #4 evaluated true (1ms) +104ms ║║Cancelling condition #1's schedules... +104ms ║║Condition group #1 evaluated true (state changed) (3ms) +107ms ║║Cancelling statement #8's schedules... +126ms ║║Executed virtual command [Kitchen table light].saveStateLocally (15ms) +133ms ║║%%%%%% Captured state +133ms ║║Executed virtual command [Kitchen table light].log (1ms) +136ms ║║Cancelling statement #10's schedules... +163ms ║║Executed physical command [Kitchen table light].off() (7ms) +169ms ║║Executed physical command [Kitchen table light].on([delay: 5000]) (4ms) +173ms ║║Executed physical command [Kitchen table light].on([delay: 10099]) (4ms) +175ms ║║Executed virtual command [Kitchen table light].flash (31ms) +176ms ║║Requesting a wake up for Tue, Jan 9 2018 @ 9:57:53 PM EST (in 10.1s) +180ms ║╚Execution stage complete. (87ms) +182ms ║Setting up scheduled job for Tue, Jan 9 2018 @ 9:57:53 PM EST (in 10.095s) +191ms ╚Event processed successfully (191ms) 1/9/2018, 9:57:34 PM +39ms +1ms ╔Received event [Back door open sensor 1].contact = open with a delay of 66ms +84ms ║RunTime Analysis CS > 12ms > PS > 36ms > PE > 36ms > CE +87ms ║Runtime (39052 bytes) successfully initialized in 36ms (v0.2.101.20171227) (84ms) +88ms ║╔Execution stage started +98ms ║║Comparison (enum) open stays (string) open = true (2ms) +100ms ║║Adding a timed trigger schedule for condition 4 +102ms ║║Condition #4 evaluated false (9ms) +103ms ║║Condition group #1 evaluated false (state did not change) (10ms) +105ms ║╚Execution stage complete. (18ms) +107ms ║Setting up scheduled job for Tue, Jan 9 2018 @ 9:57:44 PM EST (in 9.994s) +122ms ╚Event processed successfully (122ms)


#2

Oh, and I know that with this piston I could just have one with block, but what I’m really trying to do is wrap the middle with statement in a do loop until the contact is closed. I’ve removed it here for simplicity.


#3

@michicago So I got this working by putting the “Never cancel” setting in the location shown below… the problem is, I have no idea why this fixed it. I tried that setting on the if block, as well as on other blocks. Nothing fixed it until I put it right here. Can you help me understand why?


#4

I believe because the WITH statement actually sets the action. So setting it to “never cancel” tells the piston those specific tasks are not to be cancelled.

Conversely, when we make an IF statement, we only set conditions. There are a no actions generated by the piston, or nothing to protect from being cancelled.