OK I did some testing with your piston. It is as you created, except the only difference is that I kept it calling the LIFX toggle command instead of switching a single light. I paused my existing piston and then turned debugging on for your test one.
I pressed button 7 once. The light turned off, then 10 seconds later turned on. This is exactly the original behavior I had, and as predicted yesterday, Running flag does not work because of the semaphore.
Here’s the debug log after pressing button 7 just one:
10/8/2018, 12:51:47 PM +76ms
+1ms ╔Received event [Home].time = 1539017505134 with a delay of 1942ms
+101ms ║RunTime Analysis CS > 21ms > PS > 61ms > PE > 18ms > CE
+104ms ║Runtime (40225 bytes) successfully initialized in 61ms (v0.3.108.20180906) (101ms)
+105ms ║╔Execution stage started
+136ms ║║Executed virtual command setVariable (4ms)
+140ms ║╚Execution stage complete. (36ms)
+143ms ╚Event processed successfully (142ms)
10/8/2018, 12:51:31 PM +295ms
+1ms ╔Received event [ZWN-SC7 Enerwave 7 Button Scene Controller].button = pushed with a delay of 727ms
+10100ms ║RunTime Analysis CS > 18ms > PS > 10072ms > PE > 11ms > CE
+10101ms ║Piston waited at a semaphore for 10038ms
+10104ms ║Runtime (40338 bytes) successfully initialized in 10072ms (v0.3.108.20180906) (10101ms)
+10105ms ║╔Execution stage started
+10118ms ║║Comparison (enum) pushed gets (string) pushed = true (2ms)
+10120ms ║║Condition #2 evaluated true (8ms)
+10125ms ║║Comparison (boolean) false is_not (boolean) true = true (2ms)
+10127ms ║║Condition #3 evaluated true (6ms)
+10128ms ║║Condition group #1 evaluated true (state did not change) (18ms)
+10131ms ║║Cancelling statement #9’s schedules…
+10138ms ║║Executed virtual command setVariable (3ms)
+12828ms ║║Executed virtual command lifxToggle (2687ms)
+12832ms ║║Cancelling statement #10’s schedules…
+12837ms ║║Executed virtual command wait (0ms)
+12838ms ║║Requesting a wake up for Mon, Oct 8 2018 @ 12:51:45 PM EDT (in 1.0s)
+12843ms ║╚Execution stage complete. (2739ms)
+12845ms ║Setting up scheduled job for Mon, Oct 8 2018 @ 12:51:45 PM EDT (in 1s)
+12872ms ╚Event processed successfully (12872ms)
10/8/2018, 12:51:31 PM +175ms
+1ms ╔Received event [ZWN-SC7 Enerwave 7 Button Scene Controller].button = pushed with a delay of 609ms
+10178ms ║RunTime Analysis CS > 17ms > PS > 10148ms > PE > 14ms > CE
+10179ms ║Piston waited at a semaphore for 10097ms
+10182ms ║Runtime (40338 bytes) successfully initialized in 10148ms (v0.3.108.20180906) (10179ms)
+10183ms ║╔Execution stage started
+10196ms ║║Comparison (enum) pushed gets (string) pushed = true (4ms)
+10198ms ║║Condition #2 evaluated true (8ms)
+10204ms ║║Comparison (boolean) false is_not (boolean) true = true (2ms)
+10206ms ║║Condition #3 evaluated true (6ms)
+10207ms ║║Condition group #1 evaluated true (state did not change) (19ms)
+10210ms ║║Cancelling statement #9’s schedules…
+10221ms ║║Executed virtual command setVariable (5ms)
+12141ms ║║Executed virtual command lifxToggle (1915ms)
+12145ms ║║Cancelling statement #10’s schedules…
+12152ms ║║Executed virtual command wait (1ms)
+12154ms ║║Requesting a wake up for Mon, Oct 8 2018 @ 12:51:44 PM EDT (in 1.0s)
+12159ms ║╚Execution stage complete. (1977ms)
+12161ms ║Setting up scheduled job for Mon, Oct 8 2018 @ 12:51:44 PM EDT (in 1s)
+12170ms ╚Event processed successfully (12170ms)
10/8/2018, 12:51:31 PM +144ms
+1ms ╔Received event [ZWN-SC7 Enerwave 7 Button Scene Controller].button = pushed with a delay of 565ms
+233ms ║RunTime Analysis CS > 17ms > PS > 205ms > PE > 12ms > CE
+236ms ║Runtime (40265 bytes) successfully initialized in 205ms (v0.3.108.20180906) (233ms)
+237ms ║╔Execution stage started
+250ms ║║Comparison (enum) pushed gets (string) pushed = true (3ms)
+252ms ║║Cancelling condition #2’s schedules…
+253ms ║║Condition #2 evaluated true (9ms)
+258ms ║║Comparison (boolean) false is_not (boolean) true = true (2ms)
+260ms ║║Condition #3 evaluated true (6ms)
+261ms ║║Cancelling condition #1’s schedules…
+262ms ║║Condition group #1 evaluated true (state changed) (20ms)
+265ms ║║Cancelling statement #9’s schedules…
+273ms ║║Executed virtual command setVariable (4ms)
+1909ms ║║Executed virtual command lifxToggle (1632ms)
+1913ms ║║Cancelling statement #10’s schedules…
+1917ms ║║Executed virtual command wait (1ms)
+1918ms ║║Waiting for 1000ms
+2926ms ║║Executed virtual command setVariable (4ms)
+2929ms ║╚Execution stage complete. (2693ms)
+2931ms ╚Event processed successfully (2931ms)
I then changed it to run Parallel instead of Serial. This improves things, but also as predicted last night, the Running logic does not help (just like my 1750 ms logic doesn’t either), for the same reason - because one thread sets Running to true but the 2nd thread doesn’t see it yet. I cleared the log and then press the button. The light turned off and stayed off. But as you’ll see, it attempted to toggle the light in the 2nd piston, but it doesn’t work (fortunately) because apparently LIFX can’t process both toggles fast enough which is a good thing in this case.
So the bottom line is that your approach and mine are similar in design, and the issue that keeps mine from working is identical to the issue that keeps yours from working. But in the end, the fact that LIFX can’t process the duplicate Toggle command fast enough so the 2nd one is a no-op actually benefits us and provides a working system for me. I’m not crazy about it though, because technically it shouldn’t work, which means in the future if something changes it may cause this to break again. Here’s the log from parallel mode:
10/8/2018, 12:55:43 PM +635ms
+2ms ╔Received event [ZWN-SC7 Enerwave 7 Button Scene Controller].button = pushed with a delay of 58ms
+65ms ║RunTime Analysis CS > 13ms > PS > 37ms > PE > 15ms > CE
+68ms ║Runtime (40244 bytes) successfully initialized in 37ms (v0.3.108.20180906) (65ms)
+69ms ║╔Execution stage started
+82ms ║║Comparison (enum) pushed gets (string) pushed = true (4ms)
+84ms ║║Cancelling condition #2’s schedules…
+85ms ║║Condition #2 evaluated true (10ms)
+91ms ║║Comparison (boolean) false is_not (boolean) true = true (2ms)
+93ms ║║Condition #3 evaluated true (7ms)
+94ms ║║Cancelling condition #1’s schedules…
+95ms ║║Condition group #1 evaluated true (state changed) (20ms)
+98ms ║║Cancelling statement #9’s schedules…
+104ms ║║Executed virtual command setVariable (3ms)
+2702ms ║║Executed virtual command lifxToggle (2594ms)
+2706ms ║║Cancelling statement #10’s schedules…
+2710ms ║║Executed virtual command wait (1ms)
+2711ms ║║Waiting for 1000ms
+3718ms ║║Executed virtual command setVariable (3ms)
+3731ms ║╚Execution stage complete. (3662ms)
+3736ms ╚Event processed successfully (3736ms)
10/8/2018, 12:55:43 PM +654ms
+2ms ╔Received event [ZWN-SC7 Enerwave 7 Button Scene Controller].button = pushed with a delay of 90ms
+75ms ║RunTime Analysis CS > 16ms > PS > 41ms > PE > 17ms > CE
+77ms ║Runtime (40244 bytes) successfully initialized in 41ms (v0.3.108.20180906) (75ms)
+79ms ║╔Execution stage started
+90ms ║║Comparison (enum) pushed gets (string) pushed = true (2ms)
+92ms ║║Cancelling condition #2’s schedules…
+93ms ║║Condition #2 evaluated true (8ms)
+99ms ║║Comparison (boolean) false is_not (boolean) true = true (2ms)
+101ms ║║Condition #3 evaluated true (6ms)
+102ms ║║Cancelling condition #1’s schedules…
+103ms ║║Condition group #1 evaluated true (state changed) (18ms)
+106ms ║║Cancelling statement #9’s schedules…
+114ms ║║Executed virtual command setVariable (4ms)
+2170ms ║║Executed virtual command lifxToggle (2052ms)
+2174ms ║║Cancelling statement #10’s schedules…
+2179ms ║║Executed virtual command wait (1ms)
+2180ms ║║Waiting for 1000ms
+3188ms ║║Executed virtual command setVariable (4ms)
+3202ms ║╚Execution stage complete. (3124ms)
+3208ms ╚Event processed successfully (3207ms)
Finally, here’s the test piston generating those debug logs: