Delay not working in automation

I cannot figure out why my delay is not working. The light turns on and then turns off immediately.

I originally had this in a single automation, using an or condition, but broke it out into two separate automations hoping that would solve my problem. I still experience the same problem.

My configuration passes the validation check…

- id: back_dooor_triggers_hallway_outside_light_after_sunset
  alias: "Back door triggers hallway ouside lightm after sunset"
  trigger:
    platform: state
    entity_id: switch.back_door
  condition:
    condition: sun
    after: sunset
  action:
    - service: switch.turn_on
      entity_id: switch.hallway_outside_light
    - delay:
       minutes: 10
    - service: switch.turn_off
      entity_id: switch.hallway_outside_light

- id: back_dooor_triggers_hallway_outside_light_before_sunrise
  alias: "Back door triggers hallway ouside light before sunrise"
  trigger:
    platform: state
    entity_id: switch.back_door
  condition:
    condition: sun
    before: sunrise
  action:
    - service: switch.turn_on
      entity_id: switch.hallway_outside_light
    - delay:
       minutes: 10
    - service: switch.turn_off
      entity_id: switch.hallway_outside_light

Delays in automations will be skipped if the automation is triggered again during the delay time.

The workaround is to move the action section to a script and fire the script from the automation.

4 Likes

Thanks @anon43302295! I’ll try it tonight after sunset.

1 Like

Awesome, works :smile:

Automation…

- id: back_dooor_triggers_hallway_outside_light
  alias: "Back door triggers hallway ouside light"
  trigger:
    platform: state
    entity_id: switch.back_door
    to: 'on'
  condition:
    condition: or
    conditions:
      - condition: sun
        after: sunset
      - condition: sun
        before: sunrise
  action:
    - service: script.hallway_outside_light_action

Script…

hallway_outside_light_action:
  alias: "Hallway outside light action"
  sequence:
  - service: switch.turn_on
    entity_id: switch.hallway_outside_light
  - delay:
     minutes: 5
  - service: switch.turn_off
    entity_id: switch.hallway_outside_light
1 Like