NodeRed Flow gesucht für Uptime

  • Hallo Forengemeinde,

    ich suche mir gerade einen Wolf in Foren und Internet.

    Das Thema dürfte eigentlich gar nicht so schwer sein:

    Mit einem NodeRed-Flow soll ein Uptime-Wert (s) ins Format dd:hh:mm.ss gewandelt und in einen eigenen Datenpunkt geschrieben werden. Diesen will ich dann in Vis anzeigen.

    Habt Ihr da was für mich?

    Tausend Dank. :thumbup:

  • Moin,

    ich habe mich hier bedient:

    Uptime in DD:HH:MM:SS (flow) - Node-RED

    Hiermit müsstet Du arbeiten können:

    pasted-from-clipboard.png

    pasted-from-clipboard.png

    Code
    [{"id":"831e06c8a9469f57","type":"debug","z":"16380ce8.f9555b","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":4900,"wires":[]},{"id":"4f73520cb1149dc4","type":"http request","z":"16380ce8.f9555b","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"10.153.10.100/status","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":290,"y":4900,"wires":[["8d4b5bd4fbdab0f8"]]},{"id":"1c50478c0f30877e","type":"inject","z":"16380ce8.f9555b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":150,"y":4900,"wires":[["4f73520cb1149dc4"]]},{"id":"8d4b5bd4fbdab0f8","type":"change","z":"16380ce8.f9555b","name":"uptime","rules":[{"t":"move","p":"payload.uptime","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":4900,"wires":[["50f9790b.49c718"]]},{"id":"50f9790b.49c718","type":"function","z":"16380ce8.f9555b","name":"Seconds to DD:HH:MM:SS","func":" var totalNumberOfSeconds = msg.count;\n var days = parseInt( totalNumberOfSeconds / 86400 );\n var hours = parseInt (( totalNumberOfSeconds - ( days * 86400 )) / 3600  );\n var minutes = parseInt ((totalNumberOfSeconds - ((hours * 3600)+( days * 86400 ))) / 60 );\n var seconds = parseInt(totalNumberOfSeconds - ((hours * 3600) + (minutes * 60)+( days * 86400 )));\n var result = (days < 10 ? \"0\" + days : days) + \":\" + (hours < 10 ? \"0\" + hours : hours) + \":\" + (minutes < 10 ? \"0\" + minutes : minutes) + \":\" + (seconds  < 10 ? \"0\" + seconds : seconds);\n msg.payload=result;\n return msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":4900,"wires":[["831e06c8a9469f57"]]}]
  • Danke, Andreas. :thumbup:

    Werde ich gleich testen.

  • Deinen Link hatte ich übrigens auch gefunden , konnte den aber nicht für mich anpassen. :D

    Mit Deiner schon angepassten Version konnte ich das für meinen "Bedarf" anpassen. Und nun funktioniert es. :thumbup:

    Uptime als String.JPG

    Auch das kennst Du ja. ;)

    Nochmals Danke und schönes Rest-WE. :beer:

  • Moin Stefan,

    den Function-Node habe ich gar nicht angepasst, ich habe lediglich die Nodes davor für die Shellies angepasst, damit man dort die Uptime auslesen kann.

    Du kannst die Doppelpunkte auch durch Wörter ersetzen, allerdings wird die Zeile dann etwas lang. Im Function-Node unten solltest Du aber schnell finden, wo Du " Tage " durch " T " ersetzen könntest:

    Code
    [{"id":"7b419d8001373380","type":"debug","z":"2c583695f13b3b98","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":200,"wires":[]},{"id":"c21509154d42a7e2","type":"http request","z":"2c583695f13b3b98","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"10.153.10.100/status","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":270,"y":200,"wires":[["6ed593e242bd3794"]]},{"id":"08a5e1b1094f9570","type":"inject","z":"2c583695f13b3b98","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":130,"y":200,"wires":[["c21509154d42a7e2"]]},{"id":"6ed593e242bd3794","type":"change","z":"2c583695f13b3b98","name":"uptime","rules":[{"t":"move","p":"payload.uptime","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":200,"wires":[["7d0aa4674a7566c5"]]},{"id":"7d0aa4674a7566c5","type":"function","z":"2c583695f13b3b98","name":"Seconds to DD:HH:MM:SS","func":" var totalNumberOfSeconds = msg.count;\n var days = parseInt( totalNumberOfSeconds / 86400 );\n var hours = parseInt (( totalNumberOfSeconds - ( days * 86400 )) / 3600  );\n var minutes = parseInt ((totalNumberOfSeconds - ((hours * 3600)+( days * 86400 ))) / 60 );\n var seconds = parseInt(totalNumberOfSeconds - ((hours * 3600) + (minutes * 60)+( days * 86400 )));\n var result = (days < 10 ? \"0\" + days : days) + \" Tage \" + (hours < 10 ? \"0\" + hours : hours) + \" Stunden \" + (minutes < 10 ? \"0\" + minutes : minutes) + \" Minuten \" + (seconds  < 10 ? \"0\" + seconds : seconds) + \" Sekunden\";\n msg.payload=result;\n return msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":200,"wires":[["7b419d8001373380"]]}]
  • Dieses Thema enthält 3 weitere Beiträge, die nur für registrierte Benutzer sichtbar sind, bitte registrieren Sie sich oder melden Sie sich an um diese lesen zu können.