Logging of system sensor specific for the RPI and sending them to a MQTT broker
Logging of system sensor specific for the RPI and sending them to a MQTT broker
I’ve created a simple python script that runs every 60 seconds and sends several system data over MQTT. It uses the MQTT Discovery for Home Assistant so you don’t need to configure anything in Home Assistant if you have discovery enabled for MQTT
It currently logs the following data:
You need to have at least python 3.6 installed to use System Sensors.
cd system_sensorssudo apt-get install python3-devsudo apt-get install python3-aptpip3 install -r requirements.txt| Value | Required | Default | Description |
|---|---|---|---|
| mqtt | true | \ | Details of the MQTT broker |
| mqtt:hostname | true | \ | Hostname of the MQTT broker |
| mqtt:port | false | 1883 | Port of the MQTT broker |
| mqtt:user | false | \ | The userlogin( if defined) for the MQTT broker |
| mqtt:password | false | \ | the password ( if defined) for the MQTT broker |
| tls | false | \ | Details of TLS settings broker |
| tls:ca_certs | false | \ | TLS settings ( if defined) for the MQTT broker |
| tls:certfile | false | \ | TLS settings ( if defined) for the MQTT broker |
| tls:keyfile | false | \ | TLS settings ( if defined) for the MQTT broker |
| client_id | true | \ | client id to connect to the MQTT broker |
| ha_status | false | hass | Status topic for homeassistant, defaults to hass if not set |
| timezone | true | \ | Your local timezone (you can find the list of timezones here: time zones) |
| power_integer_state(Deprecated) | false | false | Deprecated |
| update_interval | false | 60 | The update interval to send new values to the MQTT broker |
| sensors | false | \ | Enable/disable individual sensors (see example settings.yaml for how-to). Default is true for all sensors. |
python3 src/system_sensors.py src/settings.yamlexample_system_sensors.service file into the editor:sudo systemctl edit --force --full system_sensorssudo systemctl daemon-reloadsudo systemctl enable --now system_sensors.servicesudo systemctl status system_sensors.serviceBefore running this application in a docker container you'll need to add the following to the crontab
@reboot /src/bin/ip_pipe.shThis little script will create a pipe and fetch the Host OS IP address and put it in the pipe.
The container will have the pipe mounted in/tmp/system_sensor_pipe:/app/host/system_sensor_pipe:ro
so it can read the ip. This is required since docker container can't and shouldn't access the host OS.
Running in docker container is very symplistic:
docker-compose up -dThe only config you need in Home Assistant is the following:
mqtt:
discovery: true
discovery_prefix: homeassistantUse the following custom plugins for lovelace:
Note that due to the fact that the bar-card has finally been removed from HACS with HA 2025.6.3 due to it was long time unmaintained, the config has been updated with a replacement based on the idea of replacing former bar card config.
Config:
…Note: you need to change the friendly name for entities like last boot in the entity settings, the card prints the default entity string if no friendly name was defined.
Example:
No open issues yet, or sync has not completed.