I have an automation that turns the patio light on/off at sunset and sunrise. I originally used the Sun’s “sunrise” and “sunset” as triggered, and use “sun.sun” state with “above_horizon” and “below_horizon” as conditions to determine if I should turn on or off the light. It did not work. I found out that when the automation was triggered by “sunset”, the state of the “sun.sun” was still “above_horizon” and therefore, it will not turn the light on (and vice versa with the sunrise trigger).
Because of that, I changed to use of the state of the sun (“sun.sun”) as both the trigger and the condition to turn the light on/off. It works perfectly. However, something unexpected happened at around 3 am last night. I turned the light off before I went to bed. But the automation was triggered again by the sun’s state and the light was turned back on (because the state of the sun was “below_horizon”). Why did the sun’s state got changed/triggered in the middle of the night? If the value of the sun’s state hasn’t changed, why it triggered the automation? Please help me to understand what’s going on. I have attached the relevant log book entries at the end of this post. Thank you!
Here is my trigger snipplet:
- platform: state
entity_id: sun.sun
Here are my action conditions:
action:
- choose:
- conditions:
- condition: state
entity_id: sun.sun
state: above_horizon
sequence:
- service: light.turn_off
data: {}
target:
device_id: 9b00a82f17d6b015292982f8a52bc54c
- conditions:
- condition: state
entity_id: sun.sun
state: below_horizon
sequence:
- service: light.turn_on
data:
brightness_pct: 10
target:
device_id: 9b00a82f17d6b015292982f8a52bc54c