Code Monkey home page Code Monkey logo

system_sensors's Introduction

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

It currently logs the following data:

  • CPU usage
  • CPU temperature
  • CPU Clock Speed
  • Disk usage
  • Memory usage
  • Power status of the RPI
  • Last boot
  • Last message received timestamp
  • Swap usage
  • Wifi signal strength
  • Wifi connected SSID
  • Amount of upgrades pending
  • Disk usage of external drives
  • Hostname
  • Host local IP
  • Host OS distro and version
  • CPU Load (1min, 5min and 15min)
  • Network Download & Upload throughput

System Requirements

You need to have at least python 3.6 installed to use System Sensors.

Installation:

  1. Clone this repo >> git clone https://github.com/Sennevds/system_sensors.git
  2. cd system_sensors
  3. sudo apt-get install python3-dev
  4. sudo apt-get install python3-apt
  5. pip3 install -r requirements.txt
  6. Edit settings_example.yaml in "~/system_sensors/src" to reflect your setup and save as 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. python3 src/system_sensors.py src/settings.yaml
  2. (optional) create a service to autostart the script at boot, copy the content of the example_system_sensors.service file into the editor:
    1. sudo systemctl edit --force --full system.sensors
    2. 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.
    3. sudo systemctl daemon-reload
    4. sudo systemctl enable --now system.sensors.service
    5. sudo systemctl status 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 sinds 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

system_sensors's People

Contributors

alexmerm avatar benmepham avatar codeclinic avatar codingcatgirl avatar dependabot[bot] avatar didiermetral avatar eddy805 avatar emkookmer avatar jounathaen avatar jsa1987 avatar kylehase avatar matthewr-property24 avatar maxvram avatar mcunkelman avatar mmattel avatar patriciocl avatar poeschl avatar schuby-doo avatar sennevds avatar svbz3r0 avatar tomlut avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.