Hi,
Just joined the community.
I have been searching community for simple detecting sunset and Sunrise (Not Dusk or Dawn).
I have seen lots of codes provided from using below and above horizon to Sunset and Sunrise event of sun and elevation and azimuth. And they did not work for me. I wanted to get exact sunset and sunrise bases on its time. I see SUN entity has such attribute and I am trying to use that for my automation.
I have a toggle Helper where I like to set it to on when it is Sunset and off when it is Sunrise. This Helper will be used by several automations in my home assistant…
So far I have created the following template value by using the next_setting attribute of sun entity.
{{ (as_timestamp(states.sun.sun.attributes.next_setting) - 120*60) |float| timestamp_custom('%I:%M %p')}}
However, the result is not local time. I tired to use timepstamp_local filter before float and it did not work. I tried to use as_local() in replace of as_timestamp and that did not work. If I use the following code I get the correct time
{{ (states.sun.sun.attributes.next_setting |float| timestamp_custom('%I:%M %p')}}
But then I cannot use the time to calculate the offset.
So here is what I am trying to do in a nutshell:
- If current local time is equal to Sun next_setting attribute + offset then
call service to turn the Helper on - if the current local time is equal to Sun Next_rising + offiset then
call service to turn the Helper off
I also like to know what entity can I use for trigger.
I really appreciate your help in advance…