Automation to turn on a light if garage door is opened

I have an outside light (controlled within HA via a Shelly1) that I want to turn on for 10 minutes when I open the garage door (controlled within HA via OpenGarage).

I have created an automation to do this, but for some reason it doesn’t work, ie the light doesn’t come on when I open the garage. But the lights & garage door do work when I control them individually.

Where might I have gone wrong?

TIA

- id: '1635702500035'
  alias: Outside Lights On (10 mins) - Garage Door
  description: ''
  trigger:
  - platform: device
    device_id: e9f5d4e5fxxxx0c6c6b32328f36e1c9
    domain: cover
    entity_id: cover.garage_door
    type: opening
  condition:
  - condition: sun
    before: sunrise
    after: sunset
  action:
  - type: turn_on
    device_id: 665aba3e7037f289yyyyyy23d4b63248
    entity_id: switch.barn_lights
    domain: switch
  - wait_template: ''
    timeout: 00:10:00
    continue_on_timeout: true
  - type: turn_off
    device_id: 665aba3e7037f289yyyyyy23d4b63248
    entity_id: switch.barn_lights
    domain: switch

  mode: single

before sunrise and after sunset together at the same time does not exist, i guess?

try:

condition:
  condition: state
  entity_id: sun.sun
  state: "below_horizon"
1 Like

Also, try using the state platform for your trigger.

trigger:
  - platform: state
    entity_id: cover.garage_door
    from: 'closed'
    to: 'open'
1 Like

Many thanks, with @BebeMischa & @Paradox8 - you were very helpful. With a bit of tweaking it now works. For the help of others in the future, this is what I now have & it works perfectly.

Very happy :grinning:

- id: '1555733330035'
  alias: Outside Lights On (10 mins) - Garage Door
  description: ''
  trigger:
  - platform: state
    entity_id: cover.garage_door
    from: closed
    to: opening
  condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
  - service: switch.turn_on
    target:
      entity_id:
      - switch.barn_lights
      - switch.drive_lights
  - wait_template: ''
    timeout: 00:10:00
    continue_on_timeout: true
  - service: switch.turn_off
    target:
      entity_id:
      - switch.barn_lights
      - switch.drive_lights
  mode: single
1 Like

That’s a peculiar usage of wait_template. Normally you use wait_template with a template.

Without a template, it doesn’t wait for anything to happen. It simply times out after 10 minutes (and then proceeds to turn off the lights).

Based on how you’re using it, all three lines of the wait_template can be replaced by this:

    - delay: '00:10:00'

Example:

- id: '1555733330035'
  alias: Outside Lights On (10 mins) - Garage Door
  description: ''
  trigger:
  - platform: state
    entity_id: cover.garage_door
    from: closed
    to: opening
  condition:
  - condition: state
    entity_id: sun.sun
    state: below_horizon
  action:
  - variables:
      lights:
      - switch.barn_lights
      - switch.drive_lights
  - service: switch.turn_on
    target:
      entity_id: '{{ lights }}'
  - delay: '00:10:00'
  - service: switch.turn_off
    target:
      entity_id: '{{ lights }}'
  mode: single