A different / shorter / efficient way of making a trigger for when 2 switches AND'ed together come out true

branding
execution
piston

#1

1) Give a description of the problem
I know via the AND truth table two switches AND (&&) together should produce true only when the both are true (or ON) and false the rest of the time. However i can’t get this trigger to work for me

2) What is the expected behavior?
When both switches are ON then the overall logic should be true so therefore my piston should trigger as long as my other conditions are true. The piston is basically suppose to trigger my Good night flow when i have flipped my Asleep trigger to ON (meaning i am going to bed), and my gf has switched hers to ON as well.

3) What is happening/not happening?
I don’t see the Night mode coming on. The logs below show that this piston never triggered to anything. My only guess is that AND switches together can’t be used as a trigger they have to be used as a condition. The reason for my hunch is because i have another logical operation in another piston that XOR’s the same switches but in that piston they are used as conditions not triggers.

4) Post a Green Snapshot of the pistonimage

5) Attach any logs (From ST IDE and by turning logging level to Full)
5/29/2018, 11:20:18 PM +507ms
+1ms ╔Received event [Home].routineExecuted = 83160a5b-39b3-45fc-900d-fcdf32b01f59 with a delay of 64ms
+156ms ║RunTime Analysis CS > 19ms > PS > 52ms > PE > 85ms > CE
+159ms ║Runtime (40704 bytes) successfully initialized in 52ms (v0.3.104.20180323) (157ms)
+160ms ║╔Execution stage started
+179ms ║║Comparison (enum) present is (string) present = true (2ms)
+181ms ║║Condition #13 evaluated true (15ms)
+186ms ║║Comparison (string) :425cbfce23c780743c01ab5a5ee6e3c0: executes (string) :425cbfce23c780743c01ab5a5ee6e3c0: = true (2ms)
+188ms ║║Cancelling condition #15’s schedules…
+189ms ║║Condition #15 evaluated true (7ms)
+190ms ║║Cancelling condition #14’s schedules…
+191ms ║║Condition group #14 evaluated true (state changed) (9ms)
+192ms ║║Cancelling condition #1’s schedules…
+193ms ║║Condition group #1 evaluated true (state changed) (27ms)
+195ms ║║Cancelling statement #18’s schedules…
+207ms ║║Executed virtual command executePiston (7ms)
+210ms ║╚Execution stage complete. (51ms)
+212ms ╚Event processed successfully (212ms)
5/28/2018, 1:27:27 AM +236ms
+5ms ╔Starting piston… (v0.3.104.20180323)
+316ms ║╔Subscribing to devices…
+445ms ║║Subscribing to Home.routineExecuted.83160a5b-39b3-45fc-900d-fcdf32b01f59…
+577ms ║║Subscribing to Amanda V…
+578ms ║║Subscribing to Miguel’s iPhone…
+579ms ║╚Finished subscribing (279ms)
+659ms ║Comparison (enum) present is (string) present = true (4ms)
+668ms ║Comparison (string) null executes (string) :425cbfce23c780743c01ab5a5ee6e3c0: = false (3ms)
+683ms ║Calculating (boolean) true && (boolean) true >> (boolean) true
+690ms ║Comparison (boolean) true changes_to (boolean) true = false (5ms)
+693ms ║Cancelling condition #17’s schedules…
+694ms ║Cancelling condition #14’s schedules…
+695ms ║Cancelling condition #1’s schedules…
+729ms ╚Piston successfully started (725ms)


#2

Just a guess here, but maybe promote your triggers to the IF and then condition based upon the presence.


#3

What @Bry said… demote the presence conditions.


#4

I think the switch statement evaluates to On or Off. On && On doesn’t equal true, that’s why it isn’t triggering.

I’d try a different way, and avoid that expression entirely.

if
{{
ANY of asleep switch 1 or aspleep switch 2 CHANGES TO On
and
ALL of asleep switch 1 and asleep switch 2 are On
}
or
Routine executes Good Night
}
then
Execute piston nigh mode actions


#5

Hi @eibyer && @Bry (see what i did there :slight_smile:)

I don’t quite follow as my presence is indeed a condition not a trigger as i am using the ‘are’ and it is under the condition umbrella.


#6

Thanks! I think this is a much better approach. I know that i could do it with 2 groups that each made sure the other switch was ON already but i did not want to do it this long way. I think your suggest is much better. I’m curious as to why the switch statement doesn’t work however it works in another flow i have where i am doing the exact thing but with an XOR instead. The only difference being, as i explained above, is that in that other piston i am using this logical operation as a condition not a trigger…


#7

I agree. The following statement would never be true

temp

Since both switches cannot change to true at the same time


#8

Thanks! @WCmore & @milhouse

I have made the changes to include this:

ANY of asleep switch 1 or aspleep switch 2 CHANGES TO On --> as the trigger

AND

kept my && line as a condition. We shall see how it is reflected tonight when i try it! I will click the solution when i get it working!


#9

If you are using your && line as a condition make sure it is EQUALS true, not CHANGES TO true…

Good luck - let us know how it works (and repost the piston if it doesn’t).

milhouse


#10

Actually it doens’t seem to work consistently…

I have been debugging it for a while now. I think it doesn’t always work. The surprising thing is that the condition of && works, but not the switches! I don’t get it!

I notice that the Condition #21 is the one that is not working!

6/5/2018, 4:45:00 AM +115ms
+2ms	╔Received event [Miguel Asleep].switch = off with a delay of 486ms
+10396ms	║RunTime Analysis CS > 25ms > PS > 10263ms > PE > 108ms > CE
+10397ms	║Piston waited at a semaphore for 10194ms
+10399ms	║Runtime (41201 bytes) successfully initialized in 10263ms (v0.3.104.20180323) (10396ms)
+10400ms	║╔Execution stage started
+10410ms	║║Comparison (string) :b4ba316d4538932c3c6310b325c706fa: is_not (string) :1923c8c08aa61e0f078115829072ecdb: = true (2ms)
+10412ms	║║Condition #13 evaluated true (5ms)
+10417ms	║║Comparison (string) null executes (string) :425cbfce23c780743c01ab5a5ee6e3c0: = false (1ms)
+10418ms	║║Condition #15 evaluated false (5ms)
+10428ms	║║Calculating (boolean) false && (boolean) false >> (boolean) false
+10433ms	║║Comparison (boolean) false is (boolean) true = false (1ms)
+10434ms	║║Condition #17 evaluated false (14ms)
+10435ms	║║Condition group #20 evaluated false (state did not change) (16ms)
+10436ms	║║Condition group #14 evaluated false (state did not change) (23ms)
+10437ms	║║Condition group #1 evaluated false (state did not change) (32ms)
+10439ms	║╚Execution stage complete. (39ms)
+10440ms	╚Event processed successfully (10440ms)
6/5/2018, 4:45:00 AM +62ms
+1ms	╔Received event [Amanda Asleep].switch = off with a delay of 481ms
+143ms	║RunTime Analysis CS > 18ms > PS > 53ms > PE > 71ms > CE
+145ms	║Runtime (41151 bytes) successfully initialized in 53ms (v0.3.104.20180323) (143ms)
+146ms	║╔Execution stage started
+156ms	║║Comparison (string) :8221a0903035860d4d5eae2a7a112dba: is_not (string) :1923c8c08aa61e0f078115829072ecdb: = true (2ms)
+157ms	║║Condition #13 evaluated true (5ms)
+162ms	║║Comparison (string) null executes (string) :425cbfce23c780743c01ab5a5ee6e3c0: = false (1ms)
+164ms	║║Cancelling condition #15's schedules...
+165ms	║║Condition #15 evaluated false (5ms)
+174ms	║║Calculating (boolean) false && (boolean) false >> (boolean) false
+178ms	║║Comparison (boolean) false is (boolean) true = false (1ms)
+180ms	║║Cancelling condition #17's schedules...
+181ms	║║Condition #17 evaluated false (15ms)
+182ms	║║Condition group #20 evaluated false (state did not change) (15ms)
+183ms	║║Cancelling condition #14's schedules...
+183ms	║║Condition group #14 evaluated false (state changed) (25ms)
+184ms	║║Cancelling condition #1's schedules...
+185ms	║║Condition group #1 evaluated false (state changed) (34ms)
+188ms	║╚Execution stage complete. (41ms)
+189ms	╚Event processed successfully (189ms)
6/5/2018, 12:20:47 AM +430ms
+0ms	╔Received event [Home].routineExecuted = 83160a5b-39b3-45fc-900d-fcdf32b01f59 with a delay of 100ms
+234ms	║RunTime Analysis CS > 21ms > PS > 136ms > PE > 78ms > CE
+237ms	║Runtime (41162 bytes) successfully initialized in 136ms (v0.3.104.20180323) (236ms)
+238ms	║╔Execution stage started
+249ms	║║Comparison (string) :59dc4ac3feef2f9a26c3daebad7897e1: is_not (string) :1923c8c08aa61e0f078115829072ecdb: = true (2ms)
+251ms	║║Condition #13 evaluated true (6ms)
+256ms	║║Comparison (string) :425cbfce23c780743c01ab5a5ee6e3c0: executes (string) :425cbfce23c780743c01ab5a5ee6e3c0: = true (2ms)
+258ms	║║Cancelling condition #15's schedules...
+259ms	║║Condition #15 evaluated true (6ms)
+260ms	║║Cancelling condition #14's schedules...
+260ms	║║Condition group #14 evaluated true (state changed) (8ms)
+262ms	║║Cancelling condition #1's schedules...
+262ms	║║Condition group #1 evaluated true (state changed) (18ms)
+265ms	║║Cancelling statement #18's schedules...
+279ms	║║Executed virtual command executePiston (8ms)
+282ms	║╚Execution stage complete. (43ms)
+283ms	╚Event processed successfully (283ms)
6/5/2018, 12:20:33 AM +863ms
+1ms	╔Received event [Miguel Asleep].switch = on with a delay of 625ms
+152ms	║RunTime Analysis CS > 21ms > PS > 51ms > PE > 81ms > CE
+155ms	║Runtime (41126 bytes) successfully initialized in 51ms (v0.3.104.20180323) (153ms)
+156ms	║╔Execution stage started
+166ms	║║Comparison (string) :59dc4ac3feef2f9a26c3daebad7897e1: is_not (string) :1923c8c08aa61e0f078115829072ecdb: = true (2ms)
+168ms	║║Condition #13 evaluated true (6ms)
+173ms	║║Comparison (string) null executes (string) :425cbfce23c780743c01ab5a5ee6e3c0: = false (2ms)
+175ms	║║Condition #15 evaluated false (5ms)
+184ms	║║Calculating (boolean) true && (boolean) true >> (boolean) true
+189ms	║║Comparison (boolean) true is (boolean) true = true (2ms)
+190ms	║║Condition #17 evaluated true (14ms)
+198ms	║║Comparison (enum) on changes_to (string) on = false (1ms)
+200ms	║║Condition #21 evaluated false (8ms)
+201ms	║║Condition group #20 evaluated false (state did not change) (24ms)
+202ms	║║Condition group #14 evaluated false (state did not change) (32ms)
+203ms	║║Condition group #1 evaluated false (state did not change) (40ms)
+205ms	║╚Execution stage complete. (49ms)
+206ms	╚Event processed successfully (206ms)
6/5/2018, 12:20:20 AM +356ms
+1ms	╔Received event [Amanda Asleep].switch = on with a delay of 624ms
+140ms	║RunTime Analysis CS > 18ms > PS > 51ms > PE > 71ms > CE
+143ms	║Runtime (41128 bytes) successfully initialized in 51ms (v0.3.104.20180323) (140ms)
+144ms	║╔Execution stage started
+154ms	║║Comparison (string) :59dc4ac3feef2f9a26c3daebad7897e1: is_not (string) :1923c8c08aa61e0f078115829072ecdb: = true (2ms)
+155ms	║║Condition #13 evaluated true (5ms)
+160ms	║║Comparison (string) null executes (string) :425cbfce23c780743c01ab5a5ee6e3c0: = false (2ms)
+162ms	║║Condition #15 evaluated false (4ms)
+171ms	║║Calculating (boolean) true && (boolean) true >> (boolean) true
+175ms	║║Comparison (boolean) true is (boolean) true = true (2ms)
+177ms	║║Cancelling condition #17's schedules...
+177ms	║║Condition #17 evaluated true (14ms)
+184ms	║║Comparison (enum) on changes_to (string) on = false (0ms)
+186ms	║║Condition #21 evaluated false (8ms)
+187ms	║║Condition group #20 evaluated false (state did not change) (24ms)
+188ms	║║Condition group #14 evaluated false (state did not change) (31ms)
+189ms	║║Condition group #1 evaluated false (state did not change) (39ms)
+191ms	║╚Execution stage complete. (48ms)
+192ms	╚Event processed successfully (192ms)
6/5/2018, 12:20:11 AM +350ms
+1ms	╔Received event [Miguel Asleep].switch = on with a delay of 645ms
+151ms	║RunTime Analysis CS > 20ms > PS > 57ms > PE > 74ms > CE
+154ms	║Runtime (41128 bytes) successfully initialized in 57ms (v0.3.104.20180323) (151ms)
+155ms	║╔Execution stage started
+166ms	║║Comparison (string) :59dc4ac3feef2f9a26c3daebad7897e1: is_not (string) :1923c8c08aa61e0f078115829072ecdb: = true (3ms)
+168ms	║║Condition #13 evaluated true (6ms)
+173ms	║║Comparison (string) null executes (string) :425cbfce23c780743c01ab5a5ee6e3c0: = false (2ms)
+175ms	║║Condition #15 evaluated false (5ms)
+186ms	║║Calculating (boolean) false && (boolean) true >> (boolean) false
+190ms	║║Comparison (boolean) false is (boolean) true = false (2ms)
+192ms	║║Condition #17 evaluated false (16ms)
+193ms	║║Condition group #20 evaluated false (state did not change) (17ms)
+194ms	║║Condition group #14 evaluated false (state did not change) (25ms)
+195ms	║║Condition group #1 evaluated false (state did not change) (34ms)
+197ms	║╚Execution stage complete. (43ms)
+199ms	╚Event processed successfully (198ms)
6/5/2018, 12:20:07 AM +68ms
+1ms	╔Received event [Miguel Asleep].switch = off with a delay of 605ms
+187ms	║RunTime Analysis CS > 21ms > PS > 57ms > PE > 108ms > CE
+189ms	║Runtime (41130 bytes) successfully initialized in 57ms (v0.3.104.20180323) (187ms)
+190ms	║╔Execution stage started
+200ms	║║Comparison (string) :59dc4ac3feef2f9a26c3daebad7897e1: is_not (string) :1923c8c08aa61e0f078115829072ecdb: = true (2ms)
+202ms	║║Condition #13 evaluated true (6ms)
+207ms	║║Comparison (string) null executes (string) :425cbfce23c780743c01ab5a5ee6e3c0: = false (2ms)
+209ms	║║Condition #15 evaluated false (6ms)
+219ms	║║Calculating (boolean) false && (boolean) false >> (boolean) false
+224ms	║║Comparison (boolean) false is (boolean) true = false (2ms)
+225ms	║║Condition #17 evaluated false (15ms)
+226ms	║║Condition group #20 evaluated false (state did not change) (16ms)
+227ms	║║Condition group #14 evaluated false (state did not change) (24ms)
+228ms	║║Condition group #1 evaluated false (state did not change) (32ms)
+230ms	║╚Execution stage complete. (40ms)
+231ms	╚Event processed successfully (231ms)

#11

Huh. Logic sure looks right, but yeah, condition 21 “any of these switches changes to on” is coming out false even though the triggering event is clearly [Miguel Asleep].switch = on.

I wonder if you can try it the other way
{your expression} changes to true
and
all of swith 1 and switch 2 are on.


#12

Are the “Amanda Asleep” and “Miguel Asleep” switches the same as Switch 1 and Switch 4 ?

If so, then you’ll never have the state where both are on AND then one changes to on.

I think what you really want is

IF

Asleep Switch 1 is on & Asleep Switch 4 changes to on

OR

Asleep Switch 4 is on & Asleep Switch 1 changes to on

THEN


#13

I’ve seen that before, when there is a condition with a nested trigger. Try changing it to:

((Switch changes to ON
AND
Amanda && Miguel…)
OR
Routine executes Good Night)
AND
Location Mode is not Away