Expression for Seconds Left in Day
-
Hello all, I am trying to create a timer in home assistant that will run for the amount of seconds left in the day. To do so, my plan is to create an expression in MSR where I subtract the seconds elapsed in the day from 86400. From there I will run a service command to start the timer for the seconds I calculated in the expression. I have tried using the
time ()
function in MSR but cannot figure out a way to just get the time elapsed today and in seconds. -
The
time()
function gives you milliseconds since midnight January 1, 1970 in UTC. You can approach a solution with it, but it's probably more complex than something like this:d=dateparts(), 86400-(d.hour*3600+d.minute*60+d.second)
This is a compound expression that uses the
dateparts()
function to get the current local time as components. From there, a little simple math converts hours, minutes, and seconds into seconds elapsed for the day, which is subtracted from 86400 to get seconds remaining in the day. -
P Pabla marked this topic as a question on
-
P Pabla has marked this topic as solved on
-
T toggledbits locked this topic on