Year progress
Node-RED

Year progress

Shows the current progress of the year in %
A flow by Blueforcer

Download flow Download assets

Flow Details

Shows the current progress of the year in %. You dont need any addtional settings. Just change your mqtt prefix or replace it with a http node .

[ { "id": "cb8adff659c25a9b", "type": "group", "z": "54b42d8d.cda474", "style": { "stroke": "#999999", "stroke-opacity": "1", "fill": "none", "fill-opacity": "1", "label": true, "label-position": "nw", "color": "#a4a4a4" }, "nodes": [ "cff2934586245f16", "b3c104ae61987f63", "e0e75b8673550866" ], "x": 34, "y": 919, "w": 652, "h": 82 }, { "id": "cff2934586245f16", "type": "inject", "z": "54b42d8d.cda474", "g": "cb8adff659c25a9b", "name": "", "props": [], "repeat": "3600", "crontab": "", "once": true, "onceDelay": "5", "topic": "", "x": 130, "y": 960, "wires": [ [ "b3c104ae61987f63" ] ] }, { "id": "b3c104ae61987f63", "type": "function", "z": "54b42d8d.cda474", "g": "cb8adff659c25a9b", "name": "Calculation", "func": "// Create current timestamp\nconst now = new Date();\n\n// Determine first day of current year\nconst startOfYear = new Date(now.getFullYear(), 0, 1);\n\n// Calculate difference in milliseconds between current timestamp and first day of year\nconst diffInMillis = now.getTime() - startOfYear.getTime();\n\n// Calculate total number of milliseconds in the year (including leap year)\nconst totalMillis = (now.getFullYear() % 4 === 0) ? 31622400000 : 31536000000;\n\n// Calculate percentage progress\nconst progress = Math.floor((diffInMillis / totalMillis) * 100);\n\nmsg.payload = {\"text\": progress + \"%\", \"icon\": \"y2023\"};\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 310, "y": 960, "wires": [ [ "e0e75b8673550866" ] ] }, { "id": "e0e75b8673550866", "type": "mqtt out", "z": "54b42d8d.cda474", "g": "cb8adff659c25a9b", "name": "", "topic": "awtrix/custom/yearprogress", "qos": "", "retain": "", "respTopic": "", "contentType": "", "userProps": "", "correl": "", "expiry": "", "broker": "346df2a95aac5785", "x": 540, "y": 960, "wires": [] }, { "id": "346df2a95aac5785", "type": "mqtt-broker", "name": "", "broker": "localhost", "port": "1883", "clientid": "", "autoConnect": true, "usetls": false, "protocolVersion": "4", "keepalive": "60", "cleansession": true, "birthTopic": "", "birthQos": "0", "birthPayload": "", "birthMsg": {}, "closeTopic": "", "closeQos": "0", "closePayload": "", "closeMsg": {}, "willTopic": "", "willQos": "0", "willPayload": "", "willMsg": {}, "userProps": "", "sessionExpiry": "" } ]
/flows/MYjJZA67oyrL/y2023.jpg
-- Flow first published on May 11, 2023, last updated on May 11, 2023 at 14:43.