Time with dynamic offset?

If you haven’t read this post, I’d highly suggest doing so – tons of good stuff there.

The sunset/sunrise are returned as an epoch (learn more here)

So, you can easily store it as an epoch or convert it to serve it on a dashboard, etc., your choice.

Here’s how I store both the sunset as an epoch and as a ‘display’ time for a dashboard – put this after your open weather API call:

Calculating the offsets would be based on your logic, for mine I use these based on the weatherID at the time and the less sunny the weather, the greater the sunset offset (you can get the weatherIDs here):

You can convert your offset epoch by doing this:

In order to trigger it, I use an ‘Every One Minute’ rule – which has its pros and cons – and check to see if the current time is equal to the sunset offset time. If it is, I turn another variable true, which triggers my rule which adjusts various things (lights, thermostats, etc.) around the house:

Hope this helps!

1 Like