The “sun” integration presently has attributes for the next rising/setting, however sometimes it is desirable to know or compare with when today’s (calendar day) sunrise/sunset is or was whether or not it has passed yet.
It would be good if the current day’s sunrise/sunset times were available instead of just the next one.
This could be resolved by a template sensor, so not sure if I would vote for this, can you provide a use case?
EDIT: if use case is uncommon, then why add…
How can it be resolved by a template sensor? I’ve been unsuccessfully trying to find a way to off and on for a while. There was a thread I found but it didn’t seem like they ended up with a simple sensor that did that at the end.
I’ve been trying to eliminate some edge cases where I have automations that trigger based on sunrise/sunset with an offset and if I’m working on the system when the times fire then I have no way to correct the state when it finishes loading. This was compounded when from Dec-Feb there was a bug causing extremely slow startup of HA which made it more likely I’d miss an automation trigger and get out of sync so lights would be stuck on or off requiring manual interaction.
I’d like to be able to build a simple binary-sensor state template that is based on fixed state data rather than triggers like (psudocode) 6AM < now() < (sunrise + 1hr) but with only next_sunrise available this throws the time off by several minutes from what it ought to be.
Similarly, it would be nice to have a simple dashboard that tells me when the sunrise/sunset for the same day happened so I can look and go as a human “oh the sun set 15 minutes ago” when I want to know that information.
This doesn’t seem like it should be so uncommon of a usecase, its common enough most home-assistants like Google voice-assistant can correctly answer “when is sunset/sunrise today” and it will tell you “it is at X” or “it was at X”.
It seems like this would make more sense than the “next-sunrise” and “next-sunset” already implemented which I’m not sure I understand a usecase for since they may not even be the same day.
I was also looking for this as I wanted a bar graph showing how many hours of daylight left. I needed a total hours between sunrise to sunset today so I can show it as a percentage. In the end I just used the one that’s available as it’s only a couple of minutes different day to day.
It is a custom integration (in HA, “addons” are different than integrations). Sun2 is available through HACS or manual download at the link I posted above.
Oh oops, I totally missed the hyperlink. Sounds like it would add the sensors but I still think the basic sunrise-sunset for the same day ought to be a built-in one. This seems a good work-around potentially though.
Try this Trigger-based Template Sensor. At the start of every day (‘00:00:01’) it computes the length of the current day’s daylight hours and reports sunrise and sunset. It won’t work for sub-Arctic regions because it assumes sunrise/sunset always occur after `00:00:00’ every day.
Feel free to change the time format to whatever you prefer.
My usecase is that I have a card with simply todays sunrise time, todays daylight and todays sunset time.
For the moment I am using just the available figures(next rising, next setting), but I would like to have the correct number in there.