# Conversion of time variable "hh:mm" into 2 numeric variables hour and minutes, and vice versa

Hello everyone,

Does anyone know how to convert an Homey hour (for example the “hh:mm” current time given by Homey) to two numbers corresponding to the hour and the minute, and conversely, how to obtain an hour variable “hh:mm” with two numbers corresponding to the hour and the minutes?

For information, I’m looking for this to calculate the ideal time to start the filtration of my swimming pool according to the water temperature on the one hand, and the period of the day when my solar panels produce the most electricity on the other. Example: The maximum electricity production of the panels is at 11.30 am at my place. If ever the calculated time for filtration is 3 hours, then I start filtration at 11:30 - 3h/2 = 10:00, and I stop it at 11:30 + 3h/2 = 13:00

NB : I’ve read in some topics that Better Logic Library and / or Homeyscript could probably do this, but I really did not understand how to do this at all

Hi

I’m doing something similar here, but to heat up the outdoor spa:

Setting a dynamic start time

If you have a constant of 3 hours for the filtration then you. An use the Scheduler device’s action card for ” Schedule ahead of time” similar to the flow sample:

Schedule 90 minutes before 11:30 and repeat on …

Now if you have formula to get the number of minutes for your filter cycle, you can put that in a BLL expression (as a tag) Math.round((your formula for filter cycle in minutes)/2)

1 Like

Hi Tapio,

I had a look at you post and the app, and yes, I think it could be the solution

So I’ll try to do the flows and let you know.

Thanks a lot !

1 Like

For those who are interested, here are my flows using the Action Scheduler app :

I could have done this using BLL but I’ve choosen Action Scheduler as I find it much easier to use for people like me who do not know anything about IT coding ^^

Once again, thanks @OH2TH

2 Likes

I use two separate variables: HourOfTheDay. I set it every hour to stay accurate if Homey has rebooted, and every 3 minutes I add 0.05 to the value.
The second variable is CumulativeHours. I add the same 0.05 every 3 minutes, but I can use this value for less time sensitive stuff for which I don’t want to run timers (and prevent the loss of timers when Homey reboots). This variable also doesn’t have any complications with the next day when using logic. If I want to know if an event happened 20 hours ago, the logic is always simple.

1 Like

Thanks, this is really a very simple solution without any App to use and no timer too