I am trying to make a lighting rule for sunset when I am not home. I live in Canada so sunset varies between 4:30 pm and 9:30 pm depending on the time of year, so I made allowances for this in the rule. Everything seems to work other than when I arrive back home and the rule is still executing its lighting sequence. I am hoping to make the rule so that when I arrive back home the lighting sequence (that is turning lights on/off based on a delay, and then possibly repeating them based on time of year) stops. Currently, when I come back home the rule keeps running through its sequence. My rule logs show the rule triggered when I arrived home and my mode changed from "away" to "day". *Note I haven't programmed the lighting sequence for winter yet, still have some time. LOL.
Most of what you have looks good--I think just one small change would help. Try adding a "Cancel Delayed Actions" action after your "Stop Repeating Actions" action. The "Stop Repeating Actions" action only stops the list of actions between the "Repeat" and "END-REP" from executing another time, but it doesn't do anything about delays/schedules you've created inside the repeat with other actions. The "Cancel Delayed Actions" action should keep your lights as they are at the moment when that actions runs by un-scheduling all of your scheduled on()
and off()
events for your lights--any delayed action where you've set the "cancel" (now called "cancelable" in newer versions) flag.
This is assuming your problem is that your lights keep turning on and off unexpectedly after you get back, which is what I'd guess is happening based on the rule actions. If it's something else, feel free to explain the problem a bit more!
Thank-you that was exactly the problem and it sounds like the perfect solution. I always assumed that when cancel was selected when programming the delay, that it would execute the cancel whenever the rule truth changed. In RM4, when you make a delay "cancelable" do you have to add the "Cancel Delayed Actions" to initiate the cancel? I think when you select "stopable" for a repetition you have to add "Stop Repeating Actions" for the stop to come into effect. So then both "cancel" and "stopable" would work the same way?
Yep! Sounds like you're familiar with old versions of Rule Machine. In 4.0, as you can see, there isn't even a "rule" anymore and thus no concept of "rule truth," so to make "cancel(able)" do anything now, you have to manually add a "Cancel Delayed Actions" action. Often these are in separate halves of an IF/ELSE, emulating what "Cancel on truth change" did back when truth change was a RM concept.