Help with a switch automation?

Hi there. Can someone tell me what’s wrong with this automation YAML? The purpose is to turn on two light switches when it’s dark outside. It does nothing. The part where I’m kinda stumped is that it totally works if I reverse the condition. If I set it as “after: sunrise” and “before: sunset” … it works.

And this is my first post. Not quote understanding code blocks, but I’ll give it a try. Thanks all.

- id: 'Lights when Garage Opens'
  alias: Welcome Lights
  trigger:
    platform: state
    entity_id: cover.double_door
    from: opening
    to: open
  condition:
    condition: and
    conditions:
    - condition: sun
      `after : sunset`
    - condition: sun
      `before: sunrise`
  action:
    - service: homeassistant.turn_on
      entity_id: switch.ge_14291_in_wall_smart_switch_switch
    - service: homeassistant.turn_on
      entity_id: light.leviton_dz6hd_1bz_decora_600w_smart_dimmer_level

Cool. Code blocks :).

Based on the second example here, it looks like you probably want an or condition.

My guess is that it only considers sunrise and sunset of the current day, so it’s impossible to have a time that is after sunset and also before sunrise on the same day.

Also, welcome!

As @tboyce1 said, you need to use or. Time goes from 0 to 24 hours and does not overlap midnight.
So if you want it to overlap midnight, you need to treat the end of the day and the start of the day as separate items.

- id: 'Lights when Garage Opens'
  alias: Welcome Lights
  trigger:
    platform: state
    entity_id: cover.double_door
    from: opening
    to: open
  condition:
    condition: or
    conditions:
    - condition: sun
      after : sunset
    - condition: sun
      before: sunrise
  action:
    - service: homeassistant.turn_on
      entity_id: switch.ge_14291_in_wall_smart_switch_switch
    - service: homeassistant.turn_on
      entity_id: light.leviton_dz6hd_1bz_decora_600w_smart_dimmer_level

Awesome. Thank you both! Figured it was something simple.

Darn. You see that unneeded space after the “after” condition? Ya. Syntax is important. Plus changing the “and” to an “or” should do the trick.