Piston never fires - conditions inside for each loop


#1

1) Give a description of the problem
I can’t get the piston to fire based on the conditions.

2) What is the expected behavior?
I’m inputting two conditions in the if block. I realize this is inefficient, but I want the piston to fire if either a watched switch comes on or the watched switch’s level is different from the variable integer (which changes based on time of day…separate piston handles that variable).

3) What is happening/not happening?
When the piston is running, nothing happens. So if the reference integer is 10, and I have the light set to 100, I know that condition is met. Then, if I turn off, then on the switch, I know that condition is met. But the piston doesn’t fire, and so it doesn’t change the dimmer level. However, If I manually test it by pressing the test button, the piston does exactly what I want. It seems like maybe the “for each” is dorking up the piston’s ability to subscribe to the conditions I want it to subscribe to. Is this possible?

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)

+1ms ╔Starting piston… (v0.3.107.20180806)
+398ms ║╔Subscribing to devices…
+409ms ║║Subscribing to Home.:8183ef827920214044f7df93ae2053aa:.@dimlevel
+424ms ║║Subscribing to Home.:8183ef827920214044f7df93ae2053aa:.@SendSMS
+561ms ║║Subscribing to Master Bedroom Lamp…
+562ms ║║Subscribing to Master Bedroom Overhead Light…
+563ms ║║Subscribing to Upstairs Hallway Light…
+564ms ║╚Finished subscribing (172ms)
+616ms ║Comparison (boolean) true is (boolean) true = true (1ms)
+626ms ╚Piston successfully started (625ms)

#3

I think you just need to structure it differently:

IF level is different
AND switch is on
THEN
For each device
DO
Set Device to @dimlevel


#4

I think I’ve found how to structure the piston so that it fires:

In some of the threads I found, there was talk of “parallelism.” I could never really discern what this does, or if I need it.

Now I’ve got another follow-on question. Every time my piston runs and sets the level, that makes the piston fire a second time. The second fire checks conditions and finds that now the level matches the target level, so it doesn’t do the actions…but is there a way I can optimize it to remove the second run? If this was excel VBA, I’d disable events in the macro, then re-enable at the end after all the actions are done. Any hints?

Here’s a log:
8/14/2018, 11:21:10 PM +40ms
+1ms ╔Received event [Upstairs Hallway Light].level = 15 with a delay of 292ms
+70ms ║RunTime Analysis CS > 14ms > PS > 35ms > PE > 22ms > CE
+72ms ║Runtime (40361 bytes) successfully initialized in 35ms (v0.3.107.20180806) (70ms)
+73ms ║╔Execution stage started
+83ms ║║Comparison (integer) 15 is_different_than (integer) 15 = false (1ms)
+84ms ║║Cancelling condition #4’s schedules…
+85ms ║║Condition #4 evaluated false (7ms)
+86ms ║║Cancelling condition #1’s schedules…
+87ms ║║Condition group #1 evaluated false (state changed) (9ms)
+89ms ║╚Execution stage complete. (16ms)
+90ms ╚Event processed successfully (90ms)
8/14/2018, 11:21:06 PM +891ms
+1ms ╔Received event [Upstairs Hallway Light].level = 42 with a delay of 295ms
+71ms ║RunTime Analysis CS > 16ms > PS > 35ms > PE > 19ms > CE
+73ms ║Runtime (40366 bytes) successfully initialized in 35ms (v0.3.107.20180806) (71ms)
+74ms ║╔Execution stage started
+83ms ║║Comparison (integer) 42 is_different_than (integer) 15 = true (2ms)
+84ms ║║Cancelling condition #4’s schedules…
+85ms ║║Condition #4 evaluated true (7ms)
+93ms ║║Comparison (enum) on is (string) on = true (1ms)
+94ms ║║Condition #5 evaluated true (9ms)
+95ms ║║Cancelling condition #1’s schedules…
+96ms ║║Condition group #1 evaluated true (state changed) (18ms)
+98ms ║║Cancelling statement #2’s schedules…
+123ms ║║Executed physical command [Upstairs Hallway Light].setLevel([15]) (22ms)
+124ms ║║Executed [Upstairs Hallway Light].setLevel (24ms)
+130ms ║║Comparison (boolean) true is (boolean) true = true (1ms)
+131ms ║║Condition #9 evaluated true (5ms)
+132ms ║║Condition group #6 evaluated true (state did not change) (5ms)
+133ms ║║Cancelling statement #7’s schedules…
+140ms ║║Calculating (string) Adjusted the + (string) Upstairs Hallway Light >> (string) Adjusted the Upstairs Hallway Light
+142ms ║║Calculating (string) Adjusted the Upstairs Hallway Light + (string) to >> (string) Adjusted the Upstairs Hallway Light to
+145ms ║║Calculating (string) Adjusted the Upstairs Hallway Light to + (string) 15 >> (string) Adjusted the Upstairs Hallway Light to 15
+161ms ║║Executed virtual command sendSMSNotification (12ms)
+164ms ║╚Execution stage complete. (91ms)
+165ms ╚Event processed successfully (165ms)


#5

Try to put your triggers outside the loops. I’m not sure it works if done that way as you found out.