Adding a Delay when using automation and automation: !include_dir_list automation

Hi:

I have a question when using automation: !include_dir_list automation in configuration.yaml. I have a simple automation that when a door “sensor” is opened, I want a room light to come on for a period of time ( 7 minutes ), then turn off automatically. Using automation: !include_dir_list automation with the delay function as such:

####Turn on Garage Lights for 7 Minutes####
  • alias: ‘Garage_Light_On’
    trigger:
    • platform: state
      entity_id: binary_sensor.garage_door
      to: ‘on’
      from: ‘off’
      condition:
    • condition: state
      entity_id: sun.sun
      state: ‘below_horizon’
      action:
    • service: light.turn_on
      entity_id: light.garage_light
      data:
      brightness: 160
    • delay: ‘00:07:00’
    • service: light.turn_off
      entity_id: light.garage_light

produces an error stating that the entity_id is a duplicate:

Sep 19 22:17:32 homeassistant hass[2966]: 16-09-19 22:17:32 ERROR (MainThread) [homeassistant.util.yaml] duplicate key: “service”
Sep 19 22:17:32 homeassistant hass[2966]: in “/home/hass/.homeassistant/automation/garage_light_trigger.yaml”, line 14, column 0
Sep 19 22:17:32 homeassistant hass[2966]: in “/home/hass/.homeassistant/automation/garage_light_trigger.yaml”, line 19, column 0

Runing the following automation produces no errors, and it works fine, but I’m not sure how to introduce the 7 minute delay:

alias: 'Garage_Light_On'
trigger:
  - platform: state
    entity_id: binary_sensor.garage_door
    to: 'on'
    from: 'off'
condition:
  - condition: state
    entity_id: sun.sun
    state: 'below_horizon'
action:
  - service: light.turn_on
    entity_id: light.garage_light
    data:
      brightness: 160

almost like a motion sensor delay, minus the motion sensor component if that makes sense to turn off a light after a certain period of inactivity.

Any help would be greatly appreciated thank you

See if this helps

automation:
  alias: Turn on kitchen lights when there is movement
  trigger:
    - platform: state
      entity_id: sensor.motion_sensor
      to: 'on'
  action:
    service: homeassistant.turn_on
    entity_id: script.timed_lamp

script:
  timed_lamp:
    alias: "Turn on lamp and set timer"
    sequence:
      # Cancel ev. old timers
      - service: script.turn_off
        data:
           entity_id: script.timer_off
      - service: light.turn_on
        data:
          entity_id: light.kitchen
      # Set new timer
      - service: script.turn_on
        data:
          entity_id: script.timer_off

  timer_off:
    alias: "Turn off lamp after 10 minutes"
    sequence:
      - delay:
          minutes: 10
      - service: light.turn_off
        data:
          entity_id: light.kitchen
3 Likes

According to the documentation https://home-assistant.io/getting-started/automation-action/

You can use multiple services for actions. The first automation should work. I would change the trigger to to: 'on' and leave it at that. Can you repost it with the same syntax you are actually using?

So I take it that the example on the website is incorrect or did I misread something?

I deleted my comment, as I didn’t actually open the link you shared (I did just now). I didn’t know a delay could be defined directly in an automation. I only use delays in scripts.

Looking at it a little closer, you are right: we need to see the automation with proper formatting as it’s likely to be a syntax issue.

I too have only used the delays in scripts. I am going to try to put together a test automation real quick.

Were you able to add a delay without a script?

I can’t see your indentation and not sure if that would cause any issues, but here is an example automation rule that I use that has a delay:

- alias: "Security System - Away Alarming"
  trigger:
    platform: state
    entity_id: group.exterior_doors
    to: 'on'
  condition:
    condition: state
    entity_id: alarm_control_panel.alarm_panel
    state: 'armed_away'
  action:
    - service: switch.turn_on
      entity_id:
        - switch.main_floor_siren
        - switch.basement_siren
    - service: notify.sns
      data:
        message: 'Away - Alarm is sounding.'
        target: 'redacted'
    - delay: '00:00:30'
    - service: switch.turn_on
      entity_id:
        - switch.main_floor_siren
        - switch.basement_siren
6 Likes