[SOLVED] Strange behavior with automation front door

Hello !

I writed an automation to turn on two light during 10 minutes when I open my front door, only the night. It works well, but when I close and re-open my door, the light turn off immediatly, and I don’t know why. If you have an idea, I’ll take it !

- alias: Lamp
  trigger:
    platform: state
    entity_id: binary_sensor.front_door
    to: "on"
  condition:
    condition: state
    entity_id: sun.sun
    state: 'below_horizon'
  action:
    - service: switch.turn_on
      entity_id: 
        - switch.led
        - switch.lamp
    - delay:
        minutes: 10
    - service: switch.turn_off
      entity_id: 
        - switch.led
        - switch.lamp

Do tout want the light to turn off after 10 min regardless of the door state, or would it make more sense for the light to turn off if the door was closed for 10 min?
If so I would break this into 2 automations. Keep the ones you have to turn on, create another one to turn off, with trigger:

- alias: Lamp Off
  trigger:
    platform: state
    entity_id: binary_sensor.front_door
    to: "off"
    for:
      minutes: 10
1 Like

If the automation is re-triggered while waiting in the delay it will skip the remaining delay and continue with execution of the actions. The solution is provided by @lolouk44. Don’t use a delay. Use two automations.

2 Likes

OK, thank you for your quickly return. :slight_smile:

but still a strange behavior :wink:

It is the intended behaviour.

Why skip the delay in that way ? What is the utility ?

IDK, but it annoys a lot of people.