Would like to show the next Sunrise and Sunset on my Dashboard

I have not found a way to show the next Sunrise or Sunset on my Dashboard. I do have Home Assistant that I have linked to SharpTools if that helps.

I am still new to all this and just don’t know where to start looking for this info to get this working.

Any help that you all can provide to get this accomplished is greatly appreciated.

Can you share some more details about how you want to use the sunrise and sunset?

Custom Tile

I put together a quick Custom Tile that loads the sunrise and sunset from Open Meteo. You can import the Custom Tile using this link:

:arrow_down_small: Import Sunset/Sunrise Custom Tile

After importing the tile, scroll down and press save, then add it to your dashboard from the Other → Custom Tile section. You’ll need to edit the tile on your dashboard and configure it with your latitude and longitude (which you can find on something like LatLong.net)

Rule Expression

You could create a rule that runs every morning and calls the new sunset() and sunrise() expression methods that I just put together for this.

The benefit of this approach is you can use the sunrise and/or sunset time on your dashboard and in your rules.

image

Here’s a few different snippets showing how you might use this

Today’s Sunrise

formatDate(sunrise(), "LT")

Today’s Sunset

formatDate(sunset(), "LT")

Tomorrow’s Sunrise

tomorrow = addDays(now(), 1)
formatDate(sunrise(tomorrow), "LT")

The Next Sunrise

tomorrow = addDays(now(), 1)
time = now() > sunrise() ? 
  sunrise(tomorrow) : 
  sunrise()
formatDate(time, "LT")

The last one reads as: "if it’s currently after today’s sunrise, then use tomorrow’s sunrise, otherwise use today’s.

Home Assistant

Since you mentioned that you’re using Home Assistant, you could use the native Sun integration which is enabled on most installations by default. To use it, you would need to make sure the relevant attributes that you are interested in are authorized in the SharpTools Home Assistant Add-on:

image

I would note that these values are UTC time formatted by default, so you would probably end up wanting to format them with an expression to get them into the format you want for display, so using the expressions above might be just as easy.

Hey Josh, I’ve notice the sunrise and sunset is a minute or two off between the expression vs the custom tile. The custom tile is accurate as I’ve checked it against other sources.

Does anyone else see the same?

I’ve found that various sunset and sunrise sources will have different values all generally within a range of a few minutes of each other.

Source Sunrise Sunset
Expression 6:56:11 AM 8:07:19 PM
Open-Meteo.com 6:55:56 AM 8:05:47 PM
SunCalc.org 6:55:28 AM 8:05:49 PM
SunCalc.net 6:57 AM 8:07 PM
Sunrise-Sunset.org 6:55:19 AM 8:05:56 PM
SunriseSunset.io 6:57:47 AM 8:06:36 PM

In writing this up, I just noticed that the default timestamp that Open-Meteo reports truncates the seconds rather than rounding the minutes, so that also accounts for some precision loss.

Edit: For all practical purposes, 1-2 minutes difference is generally inconsequential.

You can really start getting into some deep questions when you really start digging into exactly how you’d define sunrise or sunset and how you would actually confirm it. There’s different schools of thoughts for astronomical purposes versus meteorological purposes versus practical purposes. You start getting into things where you need to take into account pressure, temperature, and humidity and the implications it has on curvature of light and things of that nature when you start really getting into certain perspectives. But when you’re within one to two minutes, for all practical purposes, it’s within a sufficient margin.

You always have the option of using an external API in a rule if you have a strong preference though.

1 Like

Makes perfect sense and thank you! There used to be a member in webcore that was really into this type of stuff - mathematical equations to calculate length of day during solstices etc. your explanation reminded me of him :slight_smile:

1 Like