Very cool. I’ll check this out.
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.
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
- condition: sun
- conditions:
- condition: sun
after: sunset
sequence: - type: turn_on
device_id: xxxx
entity_id: xxxx
domain: switch
mode: single
- condition: sun
- conditions:
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.