So, the topics of timers vs delay has been long discussed, and with timers able to now survive an HA restart i wanted to clarify something.
I have this automation:
alias: Ensuite Bathroom - Fan On/Off with Humidity Derivative
description: ""
trigger:
- platform: state
entity_id:
- sensor.ensuite_bathroom_humidity_derivative
condition:
- condition: numeric_state
entity_id: sensor.ensuite_bathroom_humidity_derivative
above: input_number.ensuite_humidity_threshold
action:
- type: turn_on
device_id: 7d74b7c8e812e444474b8c4f46021cde
entity_id: switch.aqara_switch_module_ensuite_switch
domain: switch
- service: timer.start
data:
duration: "300"
target:
entity_id: timer.ensuite_bathroom_fan_timer
- if:
- condition: state
entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_opening_6
state: "off"
then:
- wait_for_trigger:
- platform: state
entity_id:
- binary_sensor.lumi_lumi_sensor_magnet_aq2_opening_6
to: "on"
- wait_template: "{{states('timer.ensuite_bathroom_fan_timer')=='idle'}}"
continue_on_timeout: true
- type: turn_off
device_id: 7d74b7c8e812e444474b8c4f46021cde
entity_id: switch.aqara_switch_module_ensuite_switch
domain: switch
- service: timer.start
data:
duration: "1500"
target:
entity_id: timer.ensuite_bathroom_fan_timer
- wait_template: "{{states('timer.ensuite_bathroom_fan_timer')=='idle'}}"
continue_on_timeout: true
mode: single
Basically if the humidity change in a room is above a certain threshold, a fan comes on, a timer then starts for 5 minutes, then when the timer stops, there is a wait for trigger further down that then turns the fan off. The Timer helper has restore enabled.
I’m assuming, despite the fact that the timer has the restore option enabled, if HA restarts during the automations wait for trigger, the automation in its current state won’t turn off the fan.
My presumption is that in order to make this robust against an HA restart, that I need to refactor this automation to add another trigger at the start, to listen for the idle state of the timer. Then use some condition further down to turn off the fan.