This works great most of the time, but sometimes it seems like the switch.turn_on fails for some reason. It’s a z-wave switch and sometimes the signal gets lost, or other times somebody will trigger it when the switch is already on and it will fail.
When this happens it seems to skip the delay step and go straight into switch.turn_off and then the notify step.
Does anybody have any idea why the delay would be skipped? Is there some sort of error handling I should be performing? I couldn’t find any docs that talked about failure scenarios for actions.
If you re-trigger the automation while it is waiting in the delay it will skip the delay and proceed with the rest of the actions. It’s designed to operate that way.
A better way to approach this would be to simply turn the switch on manually. Then have an automation that turns the switch off after it has been on for 510 seconds.
- alias: 'Hot Water Off'
initial_state: true
trigger:
platform: state
entity_id: switch.garage_hotwater
to: 'on'
for:
seconds: 510
action:
- service: switch.turn_off
entity_id: switch.garage_hotwater
- service: notify.ios_all
data:
message: "Hot Water Ready"
title: "Hot Water Ready"
I thought there were other cases where it skipped straight to the notify when something would fail, but maybe I’m wrong about that. I’ll keep an eye out to see if I see that or if it’s always when it’s retriggered.
Doesn’t quite work for me since I actually have two different automations for different delay lengths depending on where in the house I need the water.
But it does work nicely for me as an “auto off” since sometimes the switch.turn_off gets lost in the z-wave network and this ensure it doesn’t run forever.
Since its not using any automated trigger, why not use a script instead? Delays would not be skipped then. You can also have the first step of the script be something like:
script:
hot_water:
alias: Hot Water Control
sequence:
- service: script.turn_off
entity_id: script.some_trigger script
- service: switch.turn_on
entity_id: switch.garage_hotwater
- delay:
seconds: 510
- service: switch.turn_off
entity_id: switch.garage_hotwater
- service: notify.ios_all
data:
message: "Hot Water Ready"
title: "Hot Water Ready"
EDIT: i made a mistake there with cancelling itself but you get the idea
I agree that a script is a better option, but stopping itself as the first action is going to mean it never gets any further.
There’s a few solutions to a lost signal, like put a delay of a few seconds and then call the service again, or use a wait_template with a short timeout to let you know if something didn’t work properly.