A simple Python script allowing you to monitor all the Raspberry Pis you might have running in your smart home has been shared by GitHub user Sennevds. This can be useful if you have multiple Raspberry Pis doing different things, for example, if you have one as an ad-blocker and another one as a Zigbee hub.
Using this simple script you will be able to monitor vital system information, such as CPU usage and temperature. For all the nerds who like stats, you will of course also be able to display the system information using bars and graphs in the Home Assistant dashboard.
How the Raspberry Pi monitoring script works
The script, which is written in Python, runs every 60 seconds and sends system information data to an MQTT broker. If your Home Assistant has access to the same MQTT broker it will automatically pull that data using MQTT auto-discovery. You can then display the system information from the Raspberry Pi in your Home Assistant dashboard and, of course, use it in automations and scripts.
The script gathers data on the CPU (usage and temperate), memory (usage) storage (usage, swap usage and external drive usage), networking (Wi-Fi signal strength), and the Raspberry Pi itself (power status, last boot, last message received timestamp, and amount of upgrades pending).
For the script to work you will have to edit a file, which is written in YAML. There are a few required parameters such as information on the MQTT broker, a client ID and name, and the timezone you are in. Other parameters are optional, such as the update interval and whether the Wi-Fi signal strength should be measured or not.
How to use the system information data
Thanks to the MQTT auto-discover you won’t have to make any adjustments in Home Assistant, other than adding the following lines to your configuration.yaml:
mqtt: discovery: true discovery_prefix: homeassistant
Having the system information of your Raspberry Pis available in Home Assistant can be very useful. For starters, you won’t have to log in to the Raspberry Pis every time you want to check on how they are doing. You can also have a notification sent to your smartphone every time the CPU of a Raspberry Pi exceeds a limit you have set or if the storage is nearing its full capacity.
The creator of this script has also shared their own personal Lovelace configuration. They use a combination of the vertical-stack-in-card, the mini-graph-card, and the bar-card. I do have to admit, having the system information of Raspberry Pis displayed in Home Assistant does look nice.