Skip to content

Logging of system sensor specific for the RPI and sending them to a MQTT broker

License

Notifications You must be signed in to change notification settings

leelooauto/system_sensors

 
 

Repository files navigation

RPI System Sensors

GitHub Release License

Project Maintenance GitHub Activity

Community Forum

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

Dependancies:

  • You need to have Git and Pip to install System Sensors.
sudo apt install git
sudo apt-get install python3-pip

Installation:

  1. Clone the following repo
git clone https://github.com/leelooauto/system_sensors.git
  1. Install Python3 if not already
sudo apt-get install python3-apt
  1. 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
  1. 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.
  1. Run to confirm working as expected
python3 src/system_sensors.py src/settings.yaml
  1. (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

Docker

Preparations

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

Start Container

Running in docker container is very symplistic:

docker-compose up -d

Home Assistant configuration:

Configuration:

The only config you need in Home Assistant is the following:

mqtt:
  discovery: true
  discovery_prefix: homeassistant

Lovelace UI example:

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:

alt text

About

Logging of system sensor specific for the RPI and sending them to a MQTT broker

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 91.2%
  • Shell 8.0%
  • Dockerfile 0.8%