Can't get this simple automation to work

I am simply trying to turn on the garage light when the garage door opens from sunset to sunrise. Just won’t work.

alias: Garage door opens turns light on
description: ‘’
trigger:

  • platform: state
    entity_id: cover.garage_door
    from: closed
    to: open
  • platform: state
    entity_id: cover.garage_door
    from: closed
    to: opening
    condition:
  • condition: sun
    after: sunset
    before: sunrise
    action:
  • type: turn_on
    device_id: 5ce8d59ca69b7fa79df78da7a06c837a
    entity_id: switch.switchlinc_relay_dual_band_3c_2a_b7
    domain: switch
  • delay:
    hours: 0
    minutes: 10
    seconds: 0
    milliseconds: 0
  • type: turn_off
    device_id: 5ce8d59ca69b7fa79df78da7a06c837a
    entity_id: switch.switchlinc_relay_dual_band_3c_2a_b7
    domain: switch
    mode: single
1 Like

Can you please use the editor’s code formatting (</> icon) and post again?

Also: Does the action part work when you trigger the automation manually?

alias: Garage door opens turns light on
description: ''
trigger:
  - platform: state
    entity_id: cover.garage_door
    from: closed
    to: open
  - platform: state
    entity_id: cover.garage_door
    from: closed
    to: opening
condition:
  - condition: sun
    after: sunset
    before: sunrise
action:
  - type: turn_on
    device_id: 5ce8d59ca69b7fa79df78da7a06c837a
    entity_id: switch.switchlinc_relay_dual_band_3c_2a_b7
    domain: switch
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 5ce8d59ca69b7fa79df78da7a06c837a
    entity_id: switch.switchlinc_relay_dual_band_3c_2a_b7
    domain: switch
mode: single



When I select run actions yes light does turn on for 10 minutes then off.

Your condition is wrong. Has to be an or

condition:
  condition: or
  conditions:
    - condition: sun
      after: sunset
    - condition: sun
      before: sunrise
1 Like

Thank you. It’s nice to have friends.