Morning all.
I have a rule that has essentially 2 variables. 1 “Hh” for hours and “Mm” for minutes. They are both number variables.
They are derived from another number variable that has an elapsed minutes since event occurred “elapsed”
So what I do is
Set Hh to (elapsed / 60)
Set Hh to round (Hh)
If elapsed < 60
Then
Set Mm to elapsed
Else
Set Mm to (elapsed / 60)
End if
That gives me the elapsed minutes as Hours and Minutes
I then set a String variable HHMM to %Hh%:%Mm% which works fine to display the hours and min seperated with a colon.
But for anyone who’s looking at this from a programming background you likely see my issue…if either Hh or Mm is a single digit number it displays as such. So I wind up with things like 0:7 if it’s only been 7 minutes or 2:5 if it’s been 2 hours and 5 min.
Now I did all this because I couldn’t for the life of me figure out an easier way to
(1) determine the elapsed time since a door closed. So “elapsed” is set in a rule by setting a variable when a contact sensor reports closed and then periodically repeating variable math time difference of that time to current time. Which gives me elapsed time in min
(2) do that in a way that reports out a standard HH:MM time format
So can someone either tell me why I’m a dolt in the initial rule in calculating the time difference in an easier way that reports out HH:MM
Or
Tell me in a string if there’s a way to set the %Mm% to have 2 places with a leading 0 if the minutes is less than 10
Thanks in advance!