I have an automation that turns my attic fan ON/OFF based on the temp in the attic. The fan is on a zigbee switch. Sometimes the ON/OFF signal doesn’t make it to the switch. Is there an easy way to have the automation confirm the switch responded and if it didn’t retry every X min? Someone mentioned using a wait_template but I couldn’t find any good examples or documentation to pull from.
The following example turns on the fan switch then checks if it is on. It waits up to 15 seconds for the switch to report it’s on. If after 15 seconds the switch is still off, it turns on the switch again. It repeats this process until the switch is on or a maximum of four times (whichever comes first).
alias: example
trigger:
- platform: numeric_state
entity_id: sensor.attic_temperature
above: 50
condition: []
action:
- repeat:
sequence:
- service: switch.turn_on
target:
entity_id: switch.your_fan
- wait_for_trigger:
- platform: state
entity_id: switch.your_fan
from: 'off'
to: 'on'
timeout: '00:00:15'
until:
- condition: template
value_template: >-
{{ is_state('switch.your_fan', 'on')
or repeat.index >= 4 }}
Thank you so much! This is outstanding.
1 Like