Clock on Node Red Dashboard

In my Node Red Dashboard I display a Clock and the date. I live in the Netherlands so I had to convert UTC time to CET. This is done by the use of the moment node.

I have created a timer, that runs my function every 5 seconds. So the time is updated every 5 seconds. I then read the date (and time) with a funtion. The output is thrown to the moment node to convert it to CET timezone. After this the output is split, so I can display time and date in a friendly way.

[{"id":"4a1493e.f638d6c","type":"inject","z":"783c70d8.6ab84","name":"timer","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":false,"onceDelay":0.1,"x":134,"y":620,"wires":[["6ce53c71.0f4b84"]]},{"id":"6ce53c71.0f4b84","type":"function","z":"783c70d8.6ab84","name":"splitter date","func":"var date = new Date();\ndate = (date.getFullYear() + '-' + ('00' + (date.getMonth()+1)).slice(-2) + '-' + ('00' + date.getDate()).slice(-2) + ' ' + ('00' + date.getHours()).slice(-2) + ':' + ('00' + date.getMinutes()).slice(-2) + ':' + ('00' + date.getSeconds()).slice(-2));\nreturn[{payload:date}]","outputs":1,"noerr":0,"x":320.5,"y":625,"wires":[["215ba70a.4c0dd8"]]},{"id":"215ba70a.4c0dd8","type":"moment","z":"783c70d8.6ab84","name":"","topic":"","input":"payload","inputType":"msg","inTz":"ETC/GMT","adjAmount":"2","adjType":"hours","adjDir":"add","format":"","locale":"NL","output":"payload","outputType":"msg","outTz":"Europe/Amsterdam","x":334.5,"y":669,"wires":[["18b7580f.d8a258"]]},{"id":"18b7580f.d8a258","type":"function","z":"783c70d8.6ab84","name":"splitter date","func":"var date = msg.payload;\nvar datefull = date.split(\"T\");\nvar datesplit = datefull[0].split(\"-\");\nif (datesplit[1] === \"01\") { datesplit[1] = \"januari\";}\nif (datesplit[1] === \"02\") { datesplit[1] = \"februari\";}\nif (datesplit[1] === \"03\") { datesplit[1] = \"maart\";}\nif (datesplit[1] === \"04\") { datesplit[1] = \"april\";}\nif (datesplit[1] === \"05\") { datesplit[1] = \"mei\";}\nif (datesplit[1] === \"06\") { datesplit[1] = \"juni\";}\nif (datesplit[1] === \"07\") { datesplit[1] = \"juli\";}\nif (datesplit[1] === \"08\") { datesplit[1] = \"augustus\";}\nif (datesplit[1] === \"09\") { datesplit[1] = \"september\";}\nif (datesplit[1] === \"10\") { datesplit[1] = \"oktober\";}\nif (datesplit[1] === \"11\") { datesplit[1] = \"novmber\";}\nif (datesplit[1] === \"12\") { datesplit[1] = \"december\";}\n\nvar mydate = datesplit[2] + \" \" + datesplit[1] + \" \" + datesplit[0];\n\n\nvar timesplit = datefull[1].split(\":\");\nvar mytime = timesplit[0] + \":\" + timesplit[1];\nreturn[{payload:mydate},{payload:mytime}]","outputs":2,"noerr":0,"x":581,"y":674,"wires":[["fe198c52.de161"],["dd49ff65.d8295"]]},{"id":"fe198c52.de161","type":"ui_text","z":"783c70d8.6ab84","group":"877eec72.9fa84","order":2,"width":"6","height":"1","name":"datum","label":"","format":"<font size=4>{{msg.payload}}</font>","layout":"row-center","x":736,"y":659,"wires":[]},{"id":"dd49ff65.d8295","type":"ui_text","z":"783c70d8.6ab84","group":"877eec72.9fa84","order":1,"width":"6","height":"1","name":"tijd","label":"","format":"<font size=8>{{msg.payload}}</font>","layout":"row-center","x":740.5,"y":703,"wires":[]},{"id":"877eec72.9fa84","type":"ui_group","z":"","name":"Buienradar","tab":"4edf3a72.7283e4","order":1,"disp":false,"width":"6","collapse":false},{"id":"4edf3a72.7283e4","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.