Elapsed Time for on state

I have a client that would like to see elapsed time in hours for the life of a switch for when that switch is in the ON state.
example: A pump motor. How many hours has the pump been on for it’s lifetime.

Digital input is switched ON start counter. Off Pause counter. ON resume… etc.

Any idea’s how to accomplish this? I assume something with timestamp manipulation, but it would be cool if I can have the graph updating regularly while the switch is in the on state, instead of updating after a device state toggle.

Thanks.

Hi @Jonathan_Betke,

It seems this functionality would be very beneficial as a built-in platform tool and has been a popular request. I will give the Feature Request a +1 and update you in the near future on its status.

In the meantime, there is a similar post here detailing how you could store the number of hours it has been active, but in your case the “threshold” would be “on” and “off”. This example would only update after the state has changed, however.

Currently, the way I would determine the total time active could only occur in an Experience Page. On render, you could use a Device: Get Node to get the last state. If the device is “on,” you could take the timestamp of that state and compare it to now, getting the total time since the last state report of “on.” If you add this “since last on” value to the “total running” time, you would have the total historical uptime of the pump.

Let me know if I can answer any further questions!
Julia