Correct use of Condition Group?


#1

1) Give a description of the problem
The condition highlighted in the below trace as red is evaluating as false, even though the intent is for it to evaluate as true. Have i used the Group condition incorrectly or something to where this does not evaluate in the way intended?

2) What is the expected behavior?
The intent is for the condition to evaluate to true IF: activeAlertSound is true AND (either activeAlertAwake is true OR switch 13 is off). That is, if activeAlertSound is true, the condition should evaluate to true if either activeAlertAwake is true or switch 13 is off.

3) What is happening/not happening?
The condition however is evaluating to FALSE, as shown by the red trace. In this screenshot, the global variable activeAlertSound is true in the variables section of webcore. The global variable activeAlertAwake is false. And switch 13 is indeed off.

**4) Post a Green Snapshot of the piston![image|45x37]

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

+1ms ╔Received event [Home].mode = Alert with a delay of 154ms
+317ms ║RunTime Analysis CS > 22ms > PS > 201ms > PE > 93ms > CE
+320ms ║Runtime (46125 bytes) successfully initialized in 201ms (v0.3.10a.20190223) (318ms)
+321ms ║╔Execution stage started
+331ms ║║Comparison (string) :c7630a3b5502e2a9c13dbc553e985507: changes_to (string) :c7630a3b5502e2a9c13dbc553e985507: = true (1ms)
+333ms ║║Cancelling condition #8’s schedules…
+334ms ║║Condition #8 evaluated true (7ms)
+336ms ║║Cancelling condition #1’s schedules…
+337ms ║║Condition group #1 evaluated true (state changed) (10ms)
+343ms ║║Cancelling statement #4’s schedules…
+442ms ║║Executed virtual command [Kitchen Pendant].saveStateGlobally (90ms)
+446ms ║║Cancelling statement #6’s schedules…
+468ms ║║Executed virtual command [Living Room Lamp Right].saveStateGlobally (15ms)
+473ms ║║Cancelling statement #42’s schedules…
+496ms ║║Executed virtual command [Sarah’s Lamp].saveStateGlobally (14ms)
+506ms ║║Comparison (boolean) false is (boolean) true = false (2ms)
+509ms ║║Condition #52 evaluated false (7ms)
+510ms ║║Condition group #33 evaluated false (state did not change) (10ms)
+514ms ║║Cancelling statement #44’s schedules…
+528ms ║║Executed virtual command executePiston (9ms)
+532ms ║╚Execution stage complete. (211ms)
+534ms ╚Event processed successfully (533ms)

#2

Your lines 38-45 looks alright to me. To properly test this, I would not rely on the Trace. I would change your location mode to ‘Alert’ instead.


#3

This was a trace from when the Location Mode indeed changed to Alert. And the condition evaluated to false, and the “then” statement never executed as expected. Now, in the piston that changes the Mode to Alert, I do set activeAlertSound to true in the line right before i change the mode to Alert. Could there be some sort of race condition going on?


#4

If the piston that changes the mode is also the piston that changed the global variable, then that is likely the issue. Global variables are not changed until the very last line of the piston has been executed.


#5

Depending on your other piston, you might be successful with a 1 second wait added to this piston after line 36. (before the IF)


#6

Ah, that must be it then. Strange that the setting of global variables is delayed like that. I’m sure there must be a technical reason for it, but that behavior certainly fooled me :slight_smile: Now i just have to figure out how to modify it… If i wait until the last line of the calling piston to change the Location Mode to Alert, would that do it?


#7

That would definitely help, but you may also have to add a tiny delay in this piston as mentioned in my last post.


#8

For reference:
Local variables update nearly instantly (about 5ms)
Global variables update after the last line of the piston has completed


#9

Thanks for your help. I figured out a way to condense the pistons into one single piston, so that i can use only local variables. Working now as expected.