Need help troubleshooting an automation

Hello friends,

I can not understand the behaviour of the following automation:

- id: garage_stairs_on_if_entered_after_dark
  alias: "Turn on Garage stairs if front door opens after dark"
  trigger:
    - platform: state
      entity_id: binary_sensor.front_door
      to: 'on'
  condition:
    - condition: state
      entity_id: sun.sun
      state: "below_horizon"
  action:
    - service: homeassistant.turn_on
      entity_id: switch.garage_stairs
    - delay: 00:05:00
    - service: homeassistant.turn_off
      entity_id: switch.garage_stairs

It behaves properly the first time: once the door opens, the lights would turn on.
BUT- if the same door opens once more within the delay of 5 minutes as specified - the light turns off and stay off…

What is happening and how to make sure it stays on and the timer will just restart… what am I missing?

Any ideas are much appreciated.

I have a similar automation. I added an additional condition to check if the light is off. THat way the automation only runs if the door is opened and the light is off.

THere might be a better way but it works for me. I’m still new to HA.

I usually use 2 automations for this.

https://github.com/Data-Monkey/Home-Assistant-Config/blob/master/config/includes/automations/bathroom.yaml

The off automation triggers x minutes after the last motion.

1 Like

Thank you both very much

I ended up adding another condition like this:

#------------------------------------------------------------------
- id: garage_stairs_on_if_entered_after_dark
  alias: "Turn on Garage stairs if front door opens after dark"
  trigger:
    - platform: state
      entity_id: binary_sensor.front_door
      to: 'on'
  condition:
    condition: and
    conditions: 
      - condition: state
        entity_id: sun.sun
        state: 'below_horizon'
      - condition: state
        entity_id: switch.garage_stairs
        state: 'off'
  action:
    - service: homeassistant.turn_on
      entity_id: switch.garage_stairs
    - delay: 00:05:00
    - service: homeassistant.turn_off

For what it’s worth, you do not need the lines

condition: and
conditions:

when listing multiple and conditions.

Your automation could be simplified a bit as follows:

- id: garage_stairs_on_if_entered_after_dark
  alias: "Turn on Garage stairs if front door opens after dark"
  trigger:
    - platform: state
      entity_id: binary_sensor.front_door
      to: 'on'
  condition:
    - condition: state
      entity_id: sun.sun
      state: 'below_horizon'
    - condition: state
      entity_id: switch.garage_stairs
      state: 'off'
  action:
    - service: homeassistant.turn_on
      entity_id: switch.garage_stairs
    - delay: 00:05:00
    - service: homeassistant.turn_off