So I’ve just started playing around with Home Assistant. I tried creating a simple automation from the UI that generated this YAML
alias: On at sunset
description: ""
trigger:
- platform: sun
event: sunset
offset: 0
condition: []
action:
- type: turn_on
device_id: b6f2c8e8d3d8eae5e33b3da769295eef
entity_id: switch.tp_link_smart_plug_1331
domain: switch
mode: single
Nothing happens at sunset
If I replace the sunset trigger with a time instead, it works
alias: On at 6pm
description: ""
trigger:
- platform: time
at: "18:00:00"
condition: []
action:
- type: turn_on
device_id: b6f2c8e8d3d8eae5e33b3da769295eef
entity_id: switch.tp_link_smart_plug_1331
domain: switch
mode: single
Monitoring the Sun entity shows it’s correctly figuring out sunrise/set times. HA’s time is set correctly.
The YAML was created entirely by the UI so I assume it’s correct. Having said that I can’t find any documentation for the Sun entity events and I’m not sure how to verify that the “sunset” event happens.
I always had problem with sunrise/sunset triggers and honestly I don’t know why. This is what I done in one bedroom to turn on light when it’s dark till I buy motion sensor with lux capabilities.
The way YAML is structured always seems too flexible. For whatever reason, when I set up an “after sunset” automation I used a different order for the lines under trigger:
- id: away_guest_lamp_on
alias: Away - Guest BR Lamp On After Sunset
initial_state: 'false'
mode: single
trigger:
- event: sunset
offset: 0:14:00
platform: sun
action:
- service: switch.turn_on
target:
entity_id: my_entity_id
With so many “right” ways, I never know which to choose, and it’s harder to know when something is wrong, or just different. At any rate, I know the above works for me.