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
This fork is heavily modified, in a very poor way as I'm by no means a developer. I have added additional sensors for my needs. I do not run Home Assistant so I've not given that much thought
It currently logs the following data:
- Hostname
- Host Local IP Address
- Host OS distro and Version
- Host Kernel Version - ADDED
- Host Platform - ADDED
- Host Arch
- Number of Updates Pending
- Uptime in Days, Hours and Minutes - ADDED
- Last Boot Timestamp
- Host Power Status
- Last Message Received Timestamp
- CPU Temperature
- CPU Clock Speed
- CPU Usage - ADDED
- CPU Load (1min, 5min and 15min)
- Memory Available & Used - ADDED
- Memory Available & Used Percentage - ADDED
- Disk Available & Used - ADDED
- Disk Available & Used Percentage - ADDED
- Swap Used Percentage
- Network Download & Upload Throughput
- Network Bytes Sent and Received - ADDED
- Network Packets Sent and Received - ADDED
- Wifi Signal Strength
- Wifi SSID
- Disk Usage of External Drives
- You need to have Git and Pip to install System Sensors.
sudo apt install git
sudo apt-get install python3-pip
- Clone the following repo
git clone https://github.com/leelooauto/system_sensors.git
- Install Python3 if not already
sudo apt-get install python3-apt
- To install and run system_sensors
cd system_sensors
pip3 install -r requirements.txt
3a. If 'Externally Managed Environment'
pip3 install -r requirements.txt --break-system-packages
- Edit settings.yaml to reflect your system settings
sudo nano src/settings.yaml
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 |
deviceName | true | \ | device name is sent with topic |
client_id | true | \ | client id to connect to the MQTT broker |
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. |
- Run to confirm working as expected
python3 src/system_sensors.py src/settings.yaml
- (optional, but not really) create service to autostart the script at boot
- Edit the path to your script path and settings.yaml. Also make sure you replace pi in "User=pi" with the account from which this script will be run. This is typically 'pi' on default raspbian system.
sudo cp system_sensors.service /etc/systemd/system/system_sensors.service
sudo systemctl enable system_sensors.service
sudo systemctl start system_sensors.service
Before running this application in a docker container you'll need to add the following to the crontab
@reboot <git clone location>/src/bin/ip_pipe.sh
This 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 /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 -d
The only config you need in Home Assistant is the following:
mqtt:
discovery: true
discovery_prefix: homeassistant
I have used following custom plugins for lovelace:
- vertical-stack-in-card
- mini-graph-card
- bar-card
Config:
type: custom:vertical-stack-in-card
title: Deconz System Monitor
cards:
- type: horizontal-stack
cards:
- type: custom:mini-graph-card
entities:
- sensor.deconz_cpu_usage
name: CPU
line_color: '#2980b9'
line_width: 2
hours_to_show: 24
- type: custom:mini-graph-card
entities:
- sensor.deconz_temperature
name: Temp
line_color: '#2980b9'
line_width: 2
hours_to_show: 24
- type: custom:bar-card
entity: sensor.deconz_disk_use
name: HDD
positions:
icon: outside
name: inside
color: '#00ba6a'
- type: custom:bar-card
entity: sensor.deconz_memory_use
name: RAM
positions:
icon: outside
name: inside
- type: entities
entities:
- sensor.deconz_last_boot
- binary_sensor.deconz_under_voltage
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: