I wanted to keep track of my Node-RED uptime on my home Windows PC and so put together this little flow.
It uses a new to me node - the hourglass node. Its a little different than other nodes to control, this sample flow should save you some time to get it up and running.
The top inject node is set to fire once when the flow is first run, in my case, when Node-RED boots up.
The middle inject node fires every 15 seconds so I can get a readout of the current uptime.
The bottom inject node could be manually pressed to stop the timer. I included it purely as an example on how to control the hourglass node.
I could see this node being pressed into use for something like a pump run time totalizator, or refrigeration compressor duty cycle control.
Here is what the node outputs.
For my use case, I simply used the msg.elapsed.human
so I could broadly see the program uptime at a glance. I don’t need minutes and seconds resolution on my dashboard. But the full time object is there if you want to drill into that.
Lastly, here is my flow to get you started.
[{"id":"f4c0fc7b.0d8ba","type":"hourglass","z":"d9148e1f.60835","name":"","humanizeLocale":"","x":740,"y":240,"wires":[["cc439402.40cd98"]]},{"id":"9dbff6e2.f4fa78","type":"inject","z":"d9148e1f.60835","name":"Auto Start","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":230,"y":192,"wires":[["913ec325.43e08"]]},{"id":"913ec325.43e08","type":"change","z":"d9148e1f.60835","name":"Start","rules":[{"t":"set","p":"command","pt":"msg","to":"start","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":192,"wires":[["f4c0fc7b.0d8ba"]]},{"id":"3bc76c68.e85f64","type":"change","z":"d9148e1f.60835","name":"Status","rules":[{"t":"set","p":"command","pt":"msg","to":"status","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":240,"wires":[["f4c0fc7b.0d8ba"]]},{"id":"c857c4c5.942628","type":"change","z":"d9148e1f.60835","name":"Stop","rules":[{"t":"set","p":"command","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":288,"wires":[["f4c0fc7b.0d8ba"]]},{"id":"3fa35199.275e3e","type":"inject","z":"d9148e1f.60835","name":"Read every 15 seconds","topic":"","payload":"","payloadType":"date","repeat":"15","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":240,"wires":[["3bc76c68.e85f64"]]},{"id":"b4de9086.a01dc","type":"inject","z":"d9148e1f.60835","name":"Manual Stop","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":289,"wires":[["c857c4c5.942628"]]},{"id":"cc439402.40cd98","type":"debug","z":"d9148e1f.60835","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":910,"y":240,"wires":[]}]