Testing my power failure RM using low delay times assuming each delay would execute once in parallel, but that's not what occurred, it was serial.
First delay was for 5 minutes, then received the "Warning power failure at home" messages, and second delay set for 5:30 for the shutdown. This is not what I expected. I wanted the shutdown 30 seconds after the first notificaion. (Note when live this will be about 180 minutes from initial power failure), and the Hub shutdown message about 15 seconds before shutdown.
My question: is there any way to create an "end delay" statement group or must I adjust the order and timing of the delays to compensate for the Delay statement behavior as shown in the Proposed RM below?
Current RM action
set outageTime to now() in seconds
Delay 0:05:00 (cancelable)
Notify moto x4, Twilio Arn: 'Warning power failure at home'
Delay 0:05:30 (cancelable)
Send POST to: http://127.0.0.1:8080/hub/shutdown
Delay 0:05:15 (cancelable)
Notify moto x4, Twilio Arn: 'Notice: power failure Hubitat hub shut down, when power returns restart system using WIFI plug'
Proposed RM action
set outageTime to now() in seconds
Delay 0:05:00 (cancelable)
Notify moto x4, Twilio Arn: 'Warning power failure at home'
Delay 0:00:15 (cancelable)
Notify moto x4, Twilio Arn: 'Notice: power failure Hubitat hub shut down, when power returns restart system using WIFI plug'
Delay 0:00:15 (cancelable)
Send POST to: http://127.0.0.1:8080/hub/shutdown
I'm not quite sure what you're asking for with an "end delay statement group," but I think what you want is achievable with the fact that a "Cancel Delayed Actions" action (something I don't see in any of your actions even though you marked the delays as cancelable; without this, that doesn't have any effect), any delayed actions that have not already run are cancelled. In the case of a standalone "Delay" action (which you have, as opposed to a "delay" on an action), this also cancels the execution of everything after them.
So the general trend is something like:
Actions:
Notify "Actions starting!"
Delay 0:00:30
Notify "It's been 30 seconds!"
Delay 0:01:00
Notify "It's been 1 minute and 30 seconds!"
Delay 0:02:00
Notify "It's been 3 minutes and 30 seconds!"
...as opposed to:
Notify "Actions starting!"
Notify "It's been 30 seconds!" --> delay 0:00:30
Notify "It's been 1 minute!" --> delay 0:01:00
Notify "It's been 2 minutes!" --> delay 0:02:00
Same delay times, different execution times.
A typical use of "Cancel delayed actions" would be something like:
Trigger: Power outage sensor changes (I'm assuming you have a way to detect this; pardon my pseudo-code)
Actions:
IF (Power is lost) THEN
Delay 0:05:00 (cancelable)
Notify "Power lost!"
Delay 0:00:15 (cancelable) // assuming you want it 15 seconds after the above notification
Send POST to hubip/hub/shutdown
Delay 0:00:15 (cancelable)
Notify "Hub shut down..."
ELSE
Cancel Delayed Actions
END-IF
That second thing is what you want to stop this if the power comes back before it all finishes (there is another way you could do this wait "Wait for event..." but I like this way better here ).
My apologies, I did not show the entire rule. It has a cancel delayed actions as shown below. Looks similar to your suggestion, however my current thought is to ignore short term power failures less than 5 minutes.
Also the notification that the hub is shutting down must occur prior to the hub actually shutting down or it will never be sent.
Additionally when this is live the second delay will be 2 hours 54 minutes and 45 seconds.
Current Rule
Trigger: Power source of Office Extender(mains) reports changed
IF (Power source of Office Extender(mains) is mains(T) [TRUE]) THEN
set restoreTime to now() in seconds
Cancel Delayed Actions
Set durationSeconds to (restoreTime - outageTime)
IF (Variable durationSeconds(444) > 299 TRUE) Notify moto x4, Twilio Arn: 'Power restored to home'
ELSE
set outageTime to now() in seconds
Delay 0:05:00 (cancelable)
Notify moto x4, Twilio Arn: 'Warning power failure at home'
Delay 0:00:15 (cancelable)
Notify moto x4, Twilio Arn: 'Notice power failure. Hubitat hub shutting down in 15 seconds. When power returns restart system using WIFI plug.'
Delay 0:00:15 (cancelable)
Send POST to: http://127.0.0.1:8080/hub/shutdown
END-IF
Ha, you're right, of course. Ignore that part. Your rule looks like it would work to me, assuming you want that first notification way before the shutdown. I'm thinking about doing something like this myself once I get a Ring Extender or something I can use for this purpose.
I prefer "standalone" delays like you had first, though either would work. I'm pretty sure any action in RM now has the "delay" option, but maybe I'm mistaken. In any case, it doesn't really matter which method you choose since you can get the same outcome from either action as long as you time things appropriately.