Convert Seconds to Hours, Minutes & Seconds

Node Red 0.19.5 on Raspberry Pi

For display purposes on the dashboard I want to display time remaining in Hours, Minutes & Seconds.

I assume this is a common task to complete, but I have found very little on the best way to do it. Yes there are examples on how to do this in a Function node, but I would have assumed there was a built in Function node for this common task. Am I missing something very obvious?

I did find the convert-seconds Node, but I thought it was strange that such a common task wasn't already available as a Node in the Palette manager. Am I missing something here?

I ended up trying to install the convert-seconds Node, but I can't see it in my Node-Red.

I am still very much learning Node-Red and just starting to understand some of the basic concepts, so any assistance would be greatly appreciated.

If you want to do this easily, the node-red-contrib-moment node lets you format date/time in lots of ways and also lets you deal with timezone differences.

Thanks for the suggestion, however I am dealing with just a period of time from a countdown timer that is not related to a particular time and date. I don't believe the suggested node can help with this situation.

Which node are you using that is generating remaining time in Secs ?

Maybe post your flow ?

I have some code here (below) that was provided to me by another member that allows me to display a countdown from the MyTimeout Node on the Dashboard - here it is if you like

[{"id":"6ea69ec4.cfb7c","type":"ui_button","z":"a78930fe.ed232","name":"Manual 8hr Turn on of Circulating Pump","group":"2b345d73.f4d042","order":3,"width":0,"height":0,"passthru":false,"label":"Manual CP 8 Hr Turn on","color":"","bgcolor":"","icon":"","payload":"{     \"payload\": \"on\",     \"timeout\": 28800,     \"warning\": 5 }","payloadType":"json","topic":"topic/circulatingpumpoverride","x":220,"y":780,"wires":[["a3177923.ca0018"]]},{"id":"868c3c0f.4264d","type":"mqtt out","z":"a78930fe.ed232","name":"","topic":"topic/circulatingpumpoverride","qos":"","retain":"","broker":"389dd264.7716de","x":940,"y":900,"wires":[]},{"id":"da81147e.1b8758","type":"inject","z":"a78930fe.ed232","name":"Turn off CP Override","topic":"topic/circulatingpumpoverride","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":170,"y":940,"wires":[["a3177923.ca0018"]]},{"id":"45112e1b.eb1e7","type":"ui_button","z":"a78930fe.ed232","name":"Manual 4hr Turn on of Circulating Pump","group":"2b345d73.f4d042","order":2,"width":0,"height":0,"passthru":false,"label":"Manual CP 4 Hr Turn on","color":"","bgcolor":"","icon":"","payload":"{     \"payload\": \"on\",     \"timeout\": 14400,     \"warning\": 5 }","payloadType":"json","topic":"topic/circulatingpumpoverride","x":220,"y":820,"wires":[["a3177923.ca0018"]]},{"id":"467580d3.350e2","type":"ui_button","z":"a78930fe.ed232","name":"Turn off Manual Override of CP","group":"2b345d73.f4d042","order":4,"width":0,"height":0,"passthru":false,"label":"Turn off Manual Override of CP","color":"","bgcolor":"","icon":"","payload":"0","payloadType":"str","topic":"topic/circulatingpumpoverride","x":190,"y":900,"wires":[["a3177923.ca0018"]]},{"id":"a3177923.ca0018","type":"mytimeout","z":"a78930fe.ed232","name":"Circulatiing Pump Manual Turn on","outtopic":"topic/circulatingpumpoverride","outsafe":"1","outwarning":"","outunsafe":"0","warning":"5","timer":"3600","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":640,"y":860,"wires":[["868c3c0f.4264d","7e21acd2.904284"],["8511d477.998b38","e516bdb2.36da9"]]},{"id":"b6dc0aa1.e05c68","type":"ui_button","z":"a78930fe.ed232","name":"Manual 2hr Turn on of Circulating Pump","group":"2b345d73.f4d042","order":1,"width":0,"height":0,"passthru":false,"label":"Manual CP 2 Hr Turn on","color":"","bgcolor":"","icon":"","payload":"{     \"payload\": \"on\",     \"timeout\": 7200,     \"warning\": 5 }","payloadType":"json","topic":"topic/circulatingpumpoverride","x":220,"y":860,"wires":[["a3177923.ca0018"]]},{"id":"7e21acd2.904284","type":"debug","z":"a78930fe.ed232","name":"CP Fire up - Node 1","active":false,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","x":920,"y":860,"wires":[]},{"id":"8511d477.998b38","type":"debug","z":"a78930fe.ed232","name":"CP Fire up - Node 2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":920,"y":960,"wires":[]},{"id":"e516bdb2.36da9","type":"change","z":"a78930fe.ed232","name":"Set Variable to get it onto Dashboard","rules":[{"t":"set","p":"CIrculatingPumpTimeToRun","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":1020,"wires":[["caf1a13f.d8d6"]]},{"id":"caf1a13f.d8d6","type":"change","z":"a78930fe.ed232","name":"Take Variable and Put into Payload","rules":[{"t":"move","p":"CIrculatingPumpTimeToRun","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":1080,"wires":[["d5602c1e.081f4"]]},{"id":"d5602c1e.081f4","type":"ui_text_input","z":"a78930fe.ed232","name":"","label":"Manual Pump - Time to run (Sec)","group":"2b345d73.f4d042","order":0,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"","x":960,"y":1080,"wires":[[]]},{"id":"2b345d73.f4d042","type":"ui_group","z":"","name":"Circulating Pump Control","tab":"c9d53e06.a95c8","order":4,"disp":true,"width":"5"},{"id":"389dd264.7716de","type":"mqtt-broker","z":"a78930fe.ed232","broker":"localhost","port":"1883","clientid":"Node-Red","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c9d53e06.a95c8","type":"ui_tab","z":"","name":"CURTIN house main page","icon":"dashboard","order":1}]

See how you go with that

Craig

Just noticed that you do not need the Switch node any longer (the author had a bug previously that this worked around)

You can drop both of them and just put the output of the MyTimeout Node direct to the Dashboard

Craig

You can use node-red-contrib-moment if you multiply the seconds by 1000 first (to turn it into msec), like this for example

image

[{"id":"e6b1f8b5.ac6328","type":"moment","z":"6dc690a3.1abc88","name":"","topic":"","input":"payload","inputType":"msg","inTz":"ETC/GMT","adjAmount":0,"adjType":"days","adjDir":"add","format":"hh:mm:ss","locale":"en_GB","output":"payload","outputType":"msg","outTz":"ETC/GMT","x":807.5,"y":165,"wires":[["7f6fc147.e0341"]]},{"id":"7cd877ab.ebee5","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"","payload":"3700","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":456.5,"y":165,"wires":[["ce39452a.02d7b8"]]},{"id":"ce39452a.02d7b8","type":"change","z":"6dc690a3.1abc88","name":"To millisecs","rules":[{"t":"set","p":"payload","pt":"msg","to":"msg.payload*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":606.5,"y":165,"wires":[["e6b1f8b5.ac6328"]]},{"id":"7f6fc147.e0341","type":"debug","z":"6dc690a3.1abc88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":863.5,"y":247,"wires":[]}]
3 Likes

Just wanted to say thank you Colin for your help with this one. It has taken me a year to come back to this task and your solution worked.

1 Like