Top 5 This Week

Related Posts

I used Home Assistant to monitor Raspberry Pi health and I love it

Cockpit offers an excellent web GUI to manage a Raspberry Pi. But figuring out the graphs it populates for the system metrics is a struggle. At times, it’s difficult to discern any trends in how Pi uses its resources. So, I roped in the Home Assistant to visualize all the system health data for better clarity. Home Assistant doesn’t support that by default, and I utilized a third-party script, RPi-MQTT2HA-Daemon, to source the Pi’s system health data.

It works with a Raspberry Pi that runs Pi OS (64-bit). I’ve configured the MQTT broker in Home Assistant as the system health information carrier. For the script to work, I downloaded HACS in Home Assistant. Next, the script installation on my Raspberry Pi 4B and configuring the data into cards in Home Assistant took less than 30 minutes.

Related


6 Home Assistant integrations I use to make my smart home smarter

If you have a smart home and want to make it even smarter, these Home Assistant integrations will do the trick.

Why use Home Assistant to monitor the Raspberry Pi’s system health?

Better visualized convenience

Photo of an iPad running Cockpit in browser to manage Raspberry Pi

Currently, I have one Pi 4B running as a home server, and I plan to add more Pi units to my home lab. Monitoring Raspberry Pi’s system health data through the top commands or Cockpit reveals a busy view of what’s happening with the system resources. Home Assistant makes it convenient to view individual metrics for resources like CPU, memory, network, and temperature separately on a single dashboard.

I stumbled upon RPi-MQTT2HA-Daemon on IronSheep’s GitHub page. That script collects data from a Raspberry Pi and transmits it using the MQTT (Message Queuing Telemetry Transport) protocol to Home Assistant. Thanks to the MQTT protocol, only a fraction of the network bandwidth is utilized.

Raspberry Pi 4 computer

Storage

MicroSD card slot

CPU

Arm Cortex-a72 (quad-core, 1.8GHz)


A render of the Raspberry Pi 5

CPU

Arm Cortex-A76 (quad-core, 2.4GHz)

Memory

Up to 8GB LPDDR4X SDRAM


Deploying the packages on the Raspberry Pi

Getting things ready

Install python dependencies for MQTT2HA daemon in Terminal

The RPi-MQTT2HA-Daemon is a lightweight, Python-based script. But you’ll need to ensure your Pi has several Python-related dependencies installed. I installed all of them on Pi OS with the following command:

sudo apt install git python3 python3-pip python3-tzlocal python3-sdnotify python3-colorama python3-unidecode python3-apt python3-paho-mqtt python3-requests

Next, I cloned Ironsheep’s GitHub repository to a specific folder:

sudo git clone https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon.git /opt/RPi-Reporter-MQTT2HA-Daemon

After that, you’ll need to configure and set up the script to run the daemon automatically.

Configure the script to work with the MQTT broker

Putting it all together

Setting up the script is quick if you have already set up the MQTT broker in Home Assistant. First, create the configuration files in the RPi-MQTT2HA-Daemon folder:

sudo cp /opt/RPi-Reporter-MQTT2HA-Daemon/config.{ini.dist,ini}

Edit the configuration file using the nano or vim editor:

sudo nano /opt/RPi-Reporter-MQTT2HA-Daemon/config.ini

Since the Home Assistant runs on the same Pi, I removed # from a few attributes and modified their values in {} brackets:

username = {MQTT broker username}
password = {MQTT broker password}

If Home Assistant runs on a different Pi, then you’ll need to define a couple of other values, especially the MQTT broker’s Hostname.

To let the MQTT2HA daemon access the Pi’s temperature value, add it as a user to the video group:

sudo usermod daemon -a -G video

Only after that can you use the script to record the system temperature.

Ensuring that the script runs as a service

Starts when the Pi boots

After deploying the script, I had to ensure that it ran automatically on every boot. I made it run as a system service on a Raspberry Pi.

First, I created a symbolic link to the service in the systemd folder:

sudo ln -s /opt/RPi-Reporter-MQTT2HA-Daemon/isp-rpi-reporter.service /etc/systemd/system/isp-rpi-reporter.service

To apply that change, I made the system take the updated version of the systemd configuration and regenerate all the dependency trees:

sudo systemctl daemon-reload

After that, I ensured that the service runs automatically every time the Raspberry Pi boots:

sudo systemctl enable isp-rpi-reporter.service

I summoned the service to make it work in the background:

sudo systemctl start isp-rpi-reporter.service

Finally, I checked if the service worked without any issues or exit codes:

sudo systemctl status isp-rpi-reporter.service

When everything runs as expected, the final step is to configure cards in Home Assistant to display all possible details.

Viewing Raspberry Pi’s system health details in Home Assistant

Figure out what details you want to see

Home Assistant spoils me with the variety of cards available to display information. I chose to use the System Monitor integration to curate a collection of cards with particular details on a dedicated dashboard. But first, I had to enable all the entities I wanted to use and then pull in their relevant data in the cards. That took nearly half an hour since I wanted separate cards for CPU usage, memory usage, storage usage, and so on.

If you don’t want to use System Monitor integration, you can install the RPi Monitor Card directly from HACS to get started. It displays a glance or full view of the Raspberry Pi’s system health details. Of course, you’ll need to configure the script on each Pi and set relevant entities inside Home Assistant.

Related


How to monitor your home network traffic with a Raspberry Pi

You don’t need expensive equipment to monitor your home network. All you need is a Raspberry Pi and a little time to set it up.

Better visualization that’s easy to follow

That’s how I monitor the Raspberry Pi’s system health in a visualized form that’s easy on the eyes using Home Assistant. Deploying the packages and configuring scripts on the Raspberry Pi takes just a couple of minutes. Configuring the data extrapolated from Pi to transform into dynamic charts or complex graphs for data visualization is indeed a rabbit hole. The possibilities are endless. I host a mix of different cards to monitor system health, especially while using the Pi to boost productivity or as a media center.

#Home #Assistant #monitor #Raspberry #health #love

source: https://www.xda-developers.com/home-assistant-monitor-raspberry-pi-health/

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Popular Articles