In addition to the exciting data that a SmartHome generates, you should also pay a little attention to the status of the heart of the SmartHome. If you have installed your NodeRed installation on a RaspberryPi (or other Linux system), you can use the following example to display some of the most important information about the RaspberryPi on the dashboard.
What you need to do is explained in the following article.
Safety instructions
I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/
Affiliate links/advertising links
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂
Requirements
Helpful articles:
So that you can install new nodes, NodeRed should of course already be installed.
How to prepare a RaspberryPi and then install NodeRed on it is described in the following articles.
The following three articles describe what needs to be done to prepare the RaspberryPi:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH
NodeRed – Installing NodeRed on the RaspberryPi
NodeRed – Install new nodes
NodeRed - Create a user interface with dashboard nodes
Required material:
-no-
Required material:
In the following list you will find all the parts you need to implement this article.
Log into the NodeRed configuration interface
Before you can edit your NodeRed configuration, you must - if activated - first log into the NodeRed configuration interface.
Node code
In addition to the dashboard node, only standard nodes and corresponding Linux commands are used for this display. Simply add the following node code and don't forget to position the dashboard elements correctly on your dashboard afterwards.
You can also find information on this in the article NodeRed - Create a user interface with dashboard nodes.
Node code:
[{ "id": "fbbafb8d.8c3818", "type": "exec", "z": "ae220e4a.3c49d", "command": "vcgencmd measure_temp", "addpay": false, "append": "", "useSpawn": "", "timer": "", "oldrc": false, "name": "RPi temperature", "x": 440, "y": 200, "wires": [ ["17fa85a3.c0a5fa"], [], [] ] }, { "id": "610a759f.da34ec", "type": "inject", "z": "ae220e4a.3c49d", "name": "update 10sec", "topic": "", "payload": "", "payloadType": "date", "repeat": "10", "crontab": "", "once": false, "onceDelay": "", "x": 200, "y": 200, "wires": [ ["fbbafb8d.8c3818", "6b5302eb.fe0fbc", "f8494c08.39fe8"] ] }, { "id": "17fa85a3.c0a5fa", "type": "function", "z": "ae220e4a.3c49d", "name": "cutString", "func": "str = msg.payload\r\nmsg.payload = str.substring(5,9);\r\nreturn msg;", "outputs": 1, "noerr": 0, "x": 660, "y": 200, "wires": [ ["e8f154dc.299398", "71f38a1c.ca6f64"] ] }, { "id": "4070b9bd.5796b8", "type": "exec", "z": "ae220e4a.3c49d", "command": "sudo reboot", "addpay": false, "append": "", "useSpawn": "", "timer": "", "oldrc": false, "name": "Restart", "x": 430, "y": 540, "wires": [ [], [], [] ] }, { "id": "77a93271.11eabc", "type": "exec", "z": "ae220e4a.3c49d", "command": "sudo shutdown -h now", "addpay": false, "append": "", "useSpawn": "", "timer": "", "oldrc": false, "name": "shutdown", "x": 440, "y": 620, "wires": [ [], [], [] ] }, { "id": "6b5302eb.fe0fbc", "type": "exec", "z": "ae220e4a.3c49d", "command": "top -d 1 -b -n2 | grep ", "s": "|tail -n 1 | awk '{print $2 + $4}'", "addpay": false, "append": "", "useSpawn": "", "timer": "", "oldrc": false, "name": "CPU Last", "x": 420, "y": 280, "wires": [ ["97612f41.a7f6e"], [], [] ] }, { "id": "f8494c08.39fe8", "type": "exec", "z": "ae220e4a.3c49d", "command": "free | grep Mem | awk '{print 100*(($3+$5)/$2)}'", "addpay": false, "append": "", "useSpawn": "", "timer": "", "oldrc": false, "name": "RAM", "x": 410, "y": 360, "wires": [ ["6ce43c7.2c89bc4"], [], [] ] }, { "id": "7b744c14.050354", "type": "exec", "z": "ae220e4a.3c49d", "command": "df -h", "addpay": false, "append": "", "useSpawn": "", "timer": "", "oldrc": false, "name": "storage space", "x": 440, "y": 440, "wires": [ ["403e1890.2fbab8"], [], [] ] }, { "id": "403e1890.2fbab8", "type": "function", "z": "ae220e4a.3c49d", "name": "modifyString", "func": "var re = /([0-9]{2})%/\r\nvar idx = msg.payload.search(re);\r\nvar str = msg.payload;\r\nif (idx >=0) {\r\n str = msg.payload.substring(idx, idx + 2);\r\n}\r\nmsg.payload = str;\r\nreturn msg;", "outputs": 1, "noerr": 0, "x": 670, "y": 440, "wires": [ ["f574e160.da0f1"] ] }, { "id": "da61973.d30f268", "type": "inject", "z": "ae220e4a.3c49d", "name": "update 1min", "topic": "", "payload": "", "payloadType": "date", "repeat": "60", "crontab": "", "once": false, "onceDelay": "", "x": 200, "y": 440, "wires": [ ["7b744c14.050354"] ] }, { "id": "37bde909.05a676", "type": "ui_button", "z": "ae220e4a.3c49d", "name": "", "group": "5fe5a9b.a8a6158", "order": 3, "width": 0, "height": 0, "passthru": false, "label": "Restart", "color": "", "bgcolor": "", "icon": "", "payload": "", "payloadType": "str", "topic": "", "x": 230, "y": 540, "wires": [ ["4070b9bd.5796b8"] ] }, { "id": "12fa2be3.80e824", "type": "ui_button", "z": "ae220e4a.3c49d", "name": "", "group": "5fe5a9b.a8a6158", "order": 4, "width": 0, "height": 0, "passthru": false, "label": "shutdown", "color": "", "bgcolor": "red", "icon": "", "payload": "", "payloadType": "str", "topic": "", "x": 240, "y": 620, "wires": [ ["77a93271.11eabc"] ] }, { "id": "e8f154dc.299398", "type": "ui_gauge", "z": "ae220e4a.3c49d", "name": "", "group": "5fe5a9b.a8a6158", "order": 1, "width": 0, "height": 0, "gtype": "gage", "title": "CPU temperature", "label": "C", "format": "{{value}}", "min": 0, "max": "100", "colors": ["#00b500", "#e6e600", "#ca3838"], "seg1": "", "seg2": "", "x": 910, "y": 180, "wires": [] }, { "id": "638024a7.6ca05c", "type": "ui_gauge", "z": "ae220e4a.3c49d", "name": "", "group": "6b432a4a.06ad54", "order": 1, "width": 0, "height": 0, "gtype": "gage", "title": "CPU", "label": "CPU", "format": "{{value}}%", "min": 0, "max": "100", "colors": ["#00b500", "#e6e600", "#ca3838"], "seg1": "", "seg2": "", "x": 870, "y": 300, "wires": [] }, { "id": "d80d6326.88202", "type": "ui_gauge", "z": "ae220e4a.3c49d", "name": "", "group": "6b432a4a.06ad54", "order": 1, "width": 0, "height": 0, "gtype": "gage", "title": "Memory", "label": "RAM", "format": "{{value}}%", "min": 0, "max": "100", "colors": ["#00b500", "#e6e600", "#ca3838"], "seg1": "", "seg2": "", "x": 880, "y": 360, "wires": [] }, { "id": "f574e160.da0f1", "type": "ui_gauge", "z": "ae220e4a.3c49d", "name": "", "group": "6b432a4a.06ad54", "order": 1, "width": 0, "height": 0, "gtype": "gage", "title": "Disk", "label": "disk space", "format": "{{value}}%", "min": 0, "max": "100", "colors": ["#00b500", "#e6e600", "#ca3838"], "seg1": "", "seg2": "", "x": 870, "y": 440, "wires": [] }, { "id": "71f38a1c.ca6f64", "type": "ui_chart", "z": "ae220e4a.3c49d", "name": "", "group": "5fe5a9b.a8a6158", "order": 2, "width": 0, "height": 0, "label": "CPU temperature history", "chartType": "line", "legend": "false", "xformat": "HH:mm:ss", "interpolate": "linear", "nodata": "", "dot": false, "ymin": "", "ymax": "", "removeOlder": "24", "removeOlderPoints": "", "removeOlderUnit": "3600", "cutout": 0, "useOneColor": false, "colors": ["#1f77b4", "#aec7e8", "#ff7f0e", "#2ca02c", "#98df8a", "#d62728", "#ff9896", "#9467bd", "#c5b0d5"], "useOldStyle": true, "x": 930, "y": 240, "wires": [ [], [] ] }, { "id": "6ce43c7.2c89bc4", "type": "function", "z": "ae220e4a.3c49d", "name": "deleteWhitespace", "func": "var str = msg.payload\r\nstr = str.trim();\r\nvar nr=parseInt(str);\r\nmsg.payload = nr.toFixed(1);\r\nreturn msg;", "outputs": 1, "noerr": 0, "x": 690, "y": 360, "wires": [ ["d80d6326.88202"] ] }, { "id": "97612f41.a7f6e", "type": "function", "z": "ae220e4a.3c49d", "name": "deleteWhitespace", "func": "str = msg.payload\r\nmsg.payload = str.trim();\r\nreturn msg;", "outputs": 1, "noerr": 0, "x": 690, "y": 280, "wires": [ ["638024a7.6ca05c"] ] }, { "id": "75f679fd.1125a8", "type": "inject", "z": "ae220e4a.3c49d", "name": "shutdown", "", "topic": "", "payload": "", "payloadType": "date", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 260, "y": 680, "wires": [ ["77a93271.11eabc"] ] }, { "id": "5fe5a9b.a8a6158", "type": "ui_group", "z": "ae220e4a.3c49d", "name": "2", "tab": "7e8708a2.0fc408", "order": 2, "disp": false, "width": "6", "collapse": false }, { "id": "6b432a4a.06ad54", "type": "ui_group", "z": "ae220e4a.3c49d", "name": "1", "tab": "7e8708a2.0fc408", "order": 1, "disp": false, "width": "6", "collapse": false }, { "id": "7e8708a2.0fc408", "type": "ui_tab", "z": "ae220e4a.3c49d", "name": "Raspi data", "icon": "dashboard", "order": 1 }]
Have fun with the project
I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂
PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂
Hi, very nice flow. I'm a beginner with node-red and can learn a lot with it.
CPU temperature and history running. For the node RAM, I replaced "mem" with "RAM" (German Raspian :-), works too. But the commands for "memory space" and "CPU" do not work and unfortunately my knowledge is not sufficient for a change. Could you adapt that for a German version?
Thanks and regards, Hajo.
Hi hajo,
I just tested it all again. "Unfortunately" everything works for me. Can you give me some more info what isn't working for you? 🙂
Best regards
Fabian
2/13/2023, 9:04:19 am node: modifyString
function : (error)
"TypeError: msg.payload.search is not a function"
???
Hello Nerdy,
have downloaded and installed the flow (I am also a beginner).
It worked really well ...
Now that I have transferred the system from the SD card to an HD, the CPU, memory and disk no longer show any values ...
CPU temperature works.
Do you have any tips for me?
Best regards
Jurgen
Hi Jürgen,
Yes, this is most likely because the hard disk has a different mount point/path than the SD card.
Can you send me the output of "df -h" (just type it into the console)? Then I can tell you what the current mountpoint is and we can adjust the NodeRed code accordingly 🙂
Best regards
Fabian
Hello, unfortunately an error has crept into the CPU load node:
The correct command in the exec node must look like this:
top -d 1 -b -n2 | grep "%Cpu" | tail -n 1 | awk '{print $2 + $4}'
How the display worked