I have a rule that runs 14-steps, each separated by ~4 minute wait.
The rule is triggered by a vSwitch, and I want it to exit when the switch turns Off (or when it completes, whichever comes first.)
While a Required Expression can shut-down a rule mid-stream, (Switch is Off)l it never allows the rule to run as it's evaluated at/before the rule trigger.
So....how can I Exit the rule when the switch turns-off?
(I know I can interrupt waits, but I see no way to stop the rule mid-stream, EXCEPT inserting IF/THEN Exit Rule at every step, which is an extra 14 lines in the rule.
Solved this another way...
I removed the trigger for the main rule and setup triggers for this switch via vButtons, which when pressed, turns the switch on, waits for 2-seconds, THEN runs the actions of my main rule. The 2-second wait allows time for the vSwitch to settle ON before running the main rule. NOW I can use a Required Expression of the vSwitch=ON to terminate/exit the main rule. And it works!
I could also imagine structuring this as a REPEAT WHILE Switch is On, but that depends heavily on whether your 14 steps can be reduced to a single block of code with incrementing variables.
Yes. You could have just kept your original rule, and added second rule to watch for Switch = Off as the trigger. Would only need one single action, under Run/Cancel/Pause rules in the actions drop down > Cancel Rule Timers.
By canceling any timers and pending actions you are basically stopping the rule.
I am lazy to test this but any trigger should cancel all rule waits.
Am I right?
So, if you trigger rule on switch change and wrap all actions in:
If switch is on
actions with waits
end if
when switch will turn off rule will trigger, waits will be canceled
but no action will be running.
This way rule is simply stopped.
Am I missing something?
IIUC, this is the difference between "Wait, Execute action" and "Execute action with delay". A delayed action is already placed on the schedule, and remains there even if the rule gets retriggered (unless the new instance explicitly used Cancel Delayed Actions, of course). Whereas a retrigger will cause the first version never to complete the wait, and therefore the action never gets executed.