Multiple triggers combined with “or” not working


#1

1) Give a description of the problem
I have a gentle wake up command that fires every weekday under specified conditions, and in the same if trigger, I have a manually activated virtual switch that fires the same sequence. For some reason, the manually activated switch isn’t working correctly. It is supposed to turn on the lights and fade them in over an 8 min period, instead it turns them on, but never fades. This works perfectly when triggered on a schedule, just not when the manual switch is thrown.

2) What is the expected behavior?
I give alexa the command “gentle good morning”. She then flips a virtual switch that does the following:

Two hue bulbs turn on at 1%, color is changed to 6500K, then over 8 minutes they fade in to 100%. Halfway through the fade (4 min), another z-wave switch is turned on activating another light. Also the downstairs lights are turned on at this time as well.

3) What is happening/not happening?
The hue lights turn on at 1%. None of the rest of the sequence is firing. However the entire sequence fires on weekdays when activated by a scheduled trigger connect to the manual switch with an “or” operand.

**4) Post a Green Snapshot of the piston

**5) Attach any logs
2/3/2018, 6:22:51 AM +572ms
+1ms ╔Received event [V gentle wake up].switch = on with a delay of 112ms
+177ms ║RunTime Analysis CS > 22ms > PS > 39ms > PE > 115ms > CE
+179ms ║Runtime (45289 bytes) successfully initialized in 39ms (v0.2.102.20180116) (177ms)
+180ms ║╔Execution stage started
+191ms ║║Comparison (time) 22971761 happens_daily_at (time) 18000000 = false (0ms)
+193ms ║║Condition #27 evaluated false (5ms)
+194ms ║║Cancelling statement #27’s schedules…
+197ms ║║Requesting time schedule wake up at Sun, Feb 4 2018 @ 5:00:00 AM EST
+200ms ║║Condition group #38 evaluated false (state did not change) (12ms)
+204ms ║║Comparison (enum) on changes = true (0ms)
+205ms ║║Cancelling condition #40’s schedules…
+206ms ║║Condition #40 evaluated true (5ms)
+207ms ║║Cancelling condition #39’s schedules…
+208ms ║║Condition group #39 evaluated true (state changed) (21ms)
+209ms ║║Cancelling condition #26’s schedules…
+210ms ║║Condition group #26 evaluated true (state changed) (23ms)
+212ms ║║Cancelling statement #3’s schedules…
+228ms ║║Executed physical command [Bedroom].setLevel([1]) (9ms)
+229ms ║║Executed [Bedroom].setLevel (11ms)
+240ms ║║Executed physical command [Bedroom 2].setLevel([1]) (9ms)
+241ms ║║Executed [Bedroom 2].setLevel (10ms)
+250ms ║║Executed physical command [Bedroom].setColorTemperature([6500]) (5ms)
+251ms ║║Executed [Bedroom].setColorTemperature (7ms)
+257ms ║║Executed physical command [Bedroom 2].setColorTemperature([6500]) (5ms)
+258ms ║║Executed [Bedroom 2].setColorTemperature (6ms)
+274ms ║║Executed physical command [Bedroom].setLevel([1]) (7ms)
+337ms ║║Executed virtual command [Bedroom].fadeLevel (72ms)
+347ms ║║Executed physical command [Bedroom 2].setLevel([1]) (7ms)
+404ms ║║Executed virtual command [Bedroom 2].fadeLevel (66ms)
+405ms ║║Requesting a wake up for Sat, Feb 3 2018 @ 6:30:52 AM EST (in 480.1s)
+411ms ║║Cancelling statement #19’s schedules…
+419ms ║║Executed virtual command [Backyard Floods, Happy Light, Kitchen Peninsula, Kitchen Sink, Kitchen Window, Living Room Lamp, Table].wait (1ms)
+420ms ║║Requesting a wake up for Sat, Feb 3 2018 @ 6:26:51 AM EST (in 240.0s)
+432ms ║║Condition #6 evaluated false (5ms)
+433ms ║║Condition group #1 evaluated false (state did not change) (7ms)
+723ms ║╚Execution stage complete. (542ms)
+784ms ║Setting up scheduled job for Sun, Feb 4 2018 @ 5:00:00 AM EST (in 81427.645s)
+794ms ╚Event processed successfully (794ms)


#2

I’m getting better at spotting this but the problem is you have coupled an “IF item X changes” with a “wait X minutes” command. After waiting 4 minutes, the switch has no longer “changed”, unless you remember to toggle the switch at exactly 4 minutes.

I would fix this by introducing a flag variable “Switch_14_Flag” as boolean. When switch 14 has changed, set this variable to True and use it as the basis for program execution. Once the program is complete, your last action will be to return it to false.

Give that a try and see if it helps

Option 2 would be instead of “switch X canes”, could you change it to “switch X changes to On”? In this case, the program will run as long as the switch remains on. I personally like this better because if you have a sleep in day (holiday, sick, lazy, etc) and forgot to cancel the sequence, you could also capture a “switch X changes to off” option to cancel the alarm or snooze the alarm sequence.

Would take a little more work but a feature like that would be needed in my house for wife approval.


#3

Click on each of your WITH statements that have WAIT instructions in them. Then click on the gear cog to expand settings, and change your Task Cancellation Policy to Never Cancel Tasks:

Why this works: As you can see in the dropdown list, the default behavior is to cancel tasks initiated by your piston if a condition state changes. That means when your piston wakes up after one of its wait periods it will re-evaluate your IF condition. Since “time happens daily” and "switch 14 changes will evaluate False, your piston cancels all pending tasks (your wait periods and continued increase in lighting levels).

Hope this helps.


#4

I started typing up my response here and I realized it was going to get rather lengthy so I just created an Example post instead… :slight_smile:

But the short version is…I do the same thing you do, but I use a piston with 2 triggers in it to call the piston I want to do the work. That way I can reuse the code in the called piston and I even change things up a bit if I want to get up earlier.

Anyway, here’s the full write-up.


#5

Thanks for the input everyone!

changing the task cancellation policy seems to have worked.

I guess what I still don’t understand is why it would work, just like it was supposed to, when it was a scheduled event, but not when it was manually switched on.


#6

Tough to explain for me as Im still new at this, but your piston will only run as long as the condition remains true. Now, if you piston ran because the time is now past 6:30, you then tell it to wait 4 minutes…4 minutes later it is still past 6:30. This could only be no longer true if you told it to wait 18 hours or so.

Now, as an option B you told it to execute when your switch Changes. The switch has only changed momentarily. If the switch is off and you change it to on, it can only be claimed as “changed” for a short period of time. Four minutes later, the switch is still on, that is no longer changed. If it were changed, you could then argue is it still “changed” an hour later? 4 hours later? At what point is it no longer changed? That is why I suggested you set it to “changes to…” or assign a variable flag, which is what I do in my pistons.

Think of the “switch changes” trigger as behaving like a button…momentary.

Like I said, tough to describe, but it comes down to the definition of how long is an item considered “changed”


#7

But isn’t the “happens daily at “x” time” the same thing? It initiates the action, but is only true for a finite period of time. I guess webcore treats this differently from a momentary switch.

The virtual switch i’m using is a momentary button tile so that I don’t have to worry about turning it back off. I’m using different modes to change state and limit when the scheduled action occurs - just seems neater to me to have a mode change to indicate vacation.


#8

Yea I know right LOL. Seems the “Happens Daily at X” operates as a latch. I am not sure when that truly resets. I assume at midnight, but I have no idea. I have learned that switch actions and buttons do not carry through time though. My personal work around was to establish variable for action…which is then used in debugging statements and the piston dashboard status statement, so works well for me.