Next Sun Rise or Sun Set

I want to be able to display how long until the next sun-rise or sun-set will be.

I’m using astro:sun:Sun:rise#start and astro:sun:Sun:set#start to give me the times of these events and then regularly calculate the time remaining to each. The problem is that astro:sun only updates these values at midnight for the next day. So, after sun-set each day I can only calculate the time to the next sun-rise after it is updated at midnight.

Is there any way I can trigger an updated calculation to get the next sun-rise, or get both today’s and tomorrow’s sun-rise times?

Previous discussion -

So I’ve read through the previous discussion which essentially boiled down to “OH is event driven so events are supposed to be surprises and we can’t think of a possible use case where you would want to know when the next predictable event is going to occur (even though you have given us one). Besides, the astro binding is already too big as it is.”

Except that nobody seems that have actually looked at the astro binding code and noticed the lines:

Sun sunYesterday = getSunInfo(addDays(calendar, -1), latitude, longitude, altitude, true, useMeteorologicalSeason);
Sun sunTomorrow = getSunInfo(addDays(calendar, 1), latitude, longitude, altitude, true, useMeteorologicalSeason);

So, the astro binding already calculates the sun information for the previous and following days. In fact, it even publishes that information in the many available (undocumented) channels.

My gripe is that this question/request was fobbed off with a ‘too hard/can’t do it’ response four years ago by people who didn’t really look for the solution. Anyone asking the question just gets referred back to the original discussion. Anybody doing due diligence research on the question would have seen this and taken it as the accepted answer when in fact the data is already calculated and published.

So, for anyone looking for the answer to can you get tomorrow’s sunrise or yesterday’s sunset, they are available as:

astro:sun:Sun:morningNight#start - sun set yesterday
astro:sun:Sun:night#end - sun rise tomorrow

Note that these times are calculated using Astronomical twilight, so you may need to offset by up to +/- 1.5hr depending on your latitude to get the actual sunrise/sunset.


Well done for volunteering effort. Much better than gripes. Further, documentation is editable by all.

1 Like