Calculate number of hours/minutes between "now" and a future point in time

I would like to calculate dynamically the # hours or minutes between the moment a given flow is started and a known future time.

For example target time is 20.00 and the flow is started at 13.40, number of hours is 6 or 7 depending on the rounding etc.

I cant find any means of doing so. Any app that could help? Or am I missong something? Thx

Check out BLL from fellow developer @Arie_J_Godschalk

Or check out Flow Utilities App for Homey | Homey

Also interesting maybe:

1 Like

Hello @Jux2k2,

Did I understand you question correctly? Atleast one of these three:

  1. You want to know how much time is on between known start and end times? The the answer could be Better Logic Library to do math between the too times.

  2. Or you only know the end time / target time for something to be ready and want to start a flow X minutes before that target time, then the answer is Alarm Utilities as @Peter_Kawa pointed out. However only the test version currently has the flow card to do the math for you.I expect to get that version published early next week.

  3. And finally the Flow Utilities app can do similar things like calculate the elapsed time from a known start time.

1 Like


Thanks for the help so far.

To your question:
-I do NOT know the start time, it has to be “now”, when the flow is started

-Flow is started by an automatic trigger, so I do not manually control it

-I DO know the end time, an hour (integer).

-My objective is to calculate the period (in hours, integer variable, it will require rounding up or down) so I can use it in other flows.

-Given that the end time is just an hour without date, the duration is below 24hrs :slight_smile:

I guess what I cant find is a card that allows me to identify what “now” is and extract the hour from it…

Better Logic Library can extract the current hour for you.

I’m trying to understand what is you end goal? What do you want to achieve as a result?

here’s a BLL example

Thanks guys, will look into this!

Im setting up a smart EV charging plan with this flow.
From the moment I plug the car I dont care when it charges as long as its charged by 9 am.
I can calculate how many hours of charge are required but still need to find that # of cheapest hours within the period from “now” and 9 am.

Also, I am running a peak shaving program so the charging speed may be drastically reduced to allow for heating to run. Each time the charging current is changed I need to update the charging plan (hence update the period duration).

I hope it makes sense :slight_smile:

Here’s another way, a HomeyScript which returns the number of minutes to a target time:

let now = new Date();

let now_local = now.toLocaleTimeString("nl-NL",
  hour12: false,
  timeZone: "Europe/Amsterdam",
  hour: "2-digit",
  minute: "2-digit",

let now_hours = Number(now_local.slice(0,2));
let now_minutes = Number(now_local.slice(3,5));

let target = args[0]; //For example "20:45";
let target_hours = Number(target.slice(0,2));
let target_minutes = Number(target.slice(3,5));

if (target_hours==now_hours && target_minutes==now_minutes){
  //Target time is equal to now, so return 0
  console.log("Target time is now!");
  return 0;
  if ((target_hours>now_hours) || (target_hours==now_hours && target_minutes>=now_minutes)){
    console.log("Target time is today!");
    return (target_minutes+60-now_minutes)+(target_hours-1-now_hours)*60
    console.log("Target time is tomorrow!");
    return (target_minutes+60-now_minutes)+(target_hours+23-now_hours)*60

@Jux2k2, did you find a solution?

Between work and toddlers I havent had time yet. Will keep the group updated!


calculated the time between two variable moments. you can replace one of the with “now”

Did you check out PBTH?