Homey Community Forum

Calculating time diffence between 2 events in homey script

Hey guys,

I am trying to calculate the daily time difference to determine the rate of light dimming between sunset and dusk.

I have tried a couple of option but all of them seems to have a limitation.

Here are the options I tried and why they failed.

-To calculate the time difference I tried to save the store the time in a variable in better logic app. The problem here is that the time stored in the variable are only the two digits of de 24 hour format.

  • I Tried using mathjs in betterlogic by subtracting “dusk-sunset” but I get weird value as output.

So to sum up I calculate time difference because I cant store the data in flow nor script. And I cant mathematically calculate the difference .

Any tips?

my tip is search this forum for (time) calculation

you could make a Homescript and send two parameters, time1 & time2
convert them to timestamps, substract them, and than you could convert that back to time. or… use my script i posted recently, in Dutch:

var dateParts = '17-09-2013 10:08'.match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/);

console.log(dateParts); // ["17-09-2013 10:08", "17", "09", "2013", "10", "08"]

source: jquery - Converting a datetime string to timestamp in Javascript - Stack Overflow