Light on at sunset and off at sunrise (in a single automation)

Very cool. I’ll check this out.

@neliss, how do I choose sunset and sunrise tiggers?

I wrote it in a manual here: GitHub - nielsfaber/scheduler-card: HA Lovelace card for control of scheduler entities

In programming like this we always do things in reverse.
So the first condition should be after SUNSET - because that’s only true once. Then you do after SUNRISE - that way after sunset will match first (after sunset) and be executed, whereas as other people have pointed out - the way you have it once sunrise has happened, it will always match that first - even at sunset.

EDIT: But using the sun elevation is a better way of doing it - because sunset can be already be quite dark in the winter but quite light in the summer.

I have the sun integration but I don’t see the sun moon button.

You can achieve this easily in Standard HA Automations. Change the device and entity id as also domain if that’s light instead of switch in my case. After writing the code you can also see this in visual editor

description: Turn On/Off Garden Light
trigger:

  • platform: sun
    event: sunrise
    offset: 0
  • platform: sun
    event: sunset
    offset: 0
    condition:
    action:
  • choose:
    • conditions:
      • condition: sun
        after: sunrise
        sequence:
      • type: turn_off
        device_id: xxxx
        entity_id: xxxx
        domain: switch
    • conditions:
      • condition: sun
        after: sunset
        sequence:
      • type: turn_on
        device_id: xxxx
        entity_id: xxxx
        domain: switch
        mode: single

At least if you’re going to resurrect a 3 year old dead thread the least you could do is properly format your suggested code correctly.

:wink: