Did I understand you question correctly? Atleast one of these three:
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.
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.
And finally the Flow Utilities app can do similar things like calculate the elapsed time from a known start time.
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).
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;
}else{
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
}else{
console.log("Target time is tomorrow!");
return (target_minutes+60-now_minutes)+(target_hours+23-now_hours)*60
}
}