You have 2 automations with the exact same name. Not sure what happens…but I’d guess the 2nd one wont get added due to ‘duplicate entity_id’ error.
Note: The alias is the entity id. It will generate an id of automation.alias (spaces and other characters will be converted to underscores)
But fixing that will cause another issue. If you push the button again, the 2nd automation will skip the delay and turn off the light. Then the first automation will call toggle which will turn it back on.
I’d make this a single automation.
- alias: Załącz/ Wyłącz Wentylator w Łazience
trigger:
platform: event
event_type: xiaomi_aqara.click
event_data:
entity_id: binary_sensor.switch_158d000373c264
click_type: single
action:
- service: switch.toggle
entity_id: switch.przelacznik_lazienka_wentylator
# Waits for the switch to turn off, or until timeout. Note, if this event happens again,
# this timeout will be cancelled and it will continue through the rest of the actions.
# Note, if the toggle turned the switch off, this will skip the delay right away.
- wait_template: "{{ is_state('switch.przelacznik_lazienka_wentylator', 'off') }}"
timeout: "00:05:00"
# If the switch state changed within the last 5 minutes, skip everything else.
# This will happen if the toggle turned the light off, OR if another event fires
# before the timeout is complete.
- condition: template
value_template: "{{ as_timestamp(now()) - as_timestamp(states.switch.outdoor_lights.last_changed) > 5*60 }}"
# Switch hasn't changed state. Must have been left off. Turn it off.
- service: switch.turn_off
entity_id: switch.przelacznik_lazienka_wentylator
A timer would work well. Make sure to reset the timer every time the other automation is called. Well, I guess timer.start would do that! So yeah…timer makes more sense here.