User Tools

Site Tools


dictionary:more:formatelapsedtime

Format Elapsed Time

This verb takes an integer of Seconds and returns a string in one of 2 formats to show the elapsed time. I added it to better display the Length of the last HVAC cycle so as to better track issues with that. In that case I set it to the xtOnLabel of the Pseudo Unit from it’s On script. Examples below.


Short Format:

Default setting returns a string with minutes and seconds with each padded to 2 characters and separated by a colon. Additionally hours and days may be included if they are more than 0.

Format Elapsed Time 45 

will return “00:45”

Format Elapsed Time 90

will return “01:30”

Format Elapsed Time 5546

will return “01:32:26” adding the hours section and

Format Elapsed Time 432000

will return “05:00:00:00”


Long Format:

Adding the optional switch “with long format” will output instead a string with the days, hours minutes and seconds labeled with those words in English. It can be setup to work with other languages with slightly more work and if anyone desires that please drop me a note.

Format Elapsed Time 45 with long format

will return “45 Seconds”

Format Elapsed Time 90 with long format

will return “1 Minutes and 0 Seconds”

Format Elapsed Time 5546 with long format

will return “1 Hours, 32 Minutes and 26 Seconds”

Format Elapsed Time 432000 with long format

will return “5 Days”


Example For HVAC Cycle Time Display:

To create a Unit that displays the length of time of the last HVAC cycle you might do something like this. Create a dimmable Pseudo Unit called something like “HVAC Last Cycle Time” In the On script of this Unit we are going to take the new value and use the Format Elapsed Time verb to set it’s On Label.

Remember that since the current value of the Unit is not updated until after the scripts are run you must use the Future Value verb to get the new value.

set xtOnLabel of (thisUnit) to Format Elapsed Time (future value)

Now we need to tap into the shutting off of the HVAC to update the display, Prior to ZWave and Zigbee this used to be fairly simple as “Idle” was always a value of 0 and so this trap could be placed in the Off script of the State Unit. Now that enumerated values are sent it seems to be universal that the first value that causes the Unit to run it’s Off script is never used as the Idle value. So we need to check the enumerated value against a list of what is considered idle or not.

You’ll find the list of enumerations sent by your thermostat in it’s State unit under the Display tab and Finally the Enumerated Values field. For my thermostat the list looks like:

heating,pending cool,pending heat,vent economizer,idle,cooling,fan only

So in my case heating would be a value of 0, and cooling is a value of 5. We can’t just look for the Idle value as it goes through a “pending heat” or “pending cool” state after the heat or cool cycle and we dont want to include that in the time measurement. So instead of looking for “idle” we want to see if the current state is “heating” or “cooling” and that the new state is not. That way it also wont change when you just turn the fan on or something.

First we need a list of the Enumerations that count as being On. In my case those are “heating” and “cooling”

set OnStates to {“heating”, “cooling”}

Next we need the current state. Remember that the Scripts run before the database values are updated so we can use the value of verb to get the value that it was before it is being changed to the new value. And then use the “for” parameter to the enumerated value of to get the name of the current state.

set currentState to (enumerated value of (thisUnit) for (value of (thisUnit))

If the current state is not one of the OnStates then we dont want to do anything and we can just exit

if currenState is not in OnStates then Return

Now we get the new State value and make sure it also is not in that list. Which means that we now know we WERE in an On state, but we are now in an Idle state, of whatever name, and we can do the time elapsed display. Remember the value is not updated yet, so to get the new value we use the Future Value verb.

set newState to enumerated value of (thisUnit) for (future value)
if newState is in OnStates then return

If we get past this point we know that it was on, and it is now not on, so we set the elapsed time value. Since the Last Time Stamp and Time Delta of the Unit are not updated until after the Scripts are run we can use the Time Delta verb to get the number of seconds the cycle lasted up until this moment. Since we already setup a Pseudo Unit to hold this information we can just set the value of that Unit to this value.

set value of "HVAC Last Cycle Time” to time delta of (thisUnit)

and then it’s ON script will update it’s label. That value will display in any list or view or web interface display that you place it into.

dictionary/more/formatelapsedtime.txt · Last modified: 2024/05/16 13:40 by James Sentman