Homey Community Forum

Calculate Sunrise and Sunset time to decimal value


I think I can only do this by using homeyscript.
I want to set the sunrise and sunset times in decimal value.

I have found this script online, which should calculate a time into a decimal value.
From my very little scripting knowledge, I can read what it does.
Basically it rips apart the time and puts the hours into an hours variable and minutes into a minutes variable then combines them again, but divides the minutes variable by 60.
Great, this looks like something I need.
So if the sunrise is 6:45 the returned value is 6.75.

Now to get the sunrise tag and my own logic tag in there?

Or should I use a completely different script?

function timeStringToFloat(time) {
var hoursMinutes = time.split(/[.:]/);
var hours = parseInt(hoursMinutes[0], 10);
var minutes = hoursMinutes[1] ? parseInt(hoursMinutes[1], 10) : 0;
return hours + minutes / 60;

Curious what you plan to do with this decimal value (representing the time)

Hi @FKey .

The Splines app can not yet use tags for a variable number. But the developer already told me that he wants to make that an option. If I then set the sunrise and sunset times as tags in the X-axis, the flows using that Spline will able to work troughout the year. And not need adjustment based on how much light comes in at that time of the day, as opposed to the amount of light that comes in 4 months later.

1 Like