I know there are already several topics about this but thought someone maybe find my approach interesting.
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
Here’s the repo system_sensors
Currently you need to manualy install the following python3 libraries:
I wanted to make something simple and something I had control over.
It’s quiet easy to add extra sensors the only thing you have to add is an extra publish for the config and add the variable to the publish of the sensor values.
The only thing I hoped was that I could publish only one config per device instead of create a config per sensor
I’m monitoring 3 additional boards to HassOS Pi: one running OpenMediaVault, one MotionEyeOS and one Raspbian and I tried several monitoring options
Some OS like MotionEyeOS is limited so it’s impossible to install something there
Universal monitoring way I used for a while is similar to this but with .sh scripts and HomeAssistant API, this way does not require installing additional packages on devices but it requires setting up the monitoring .sh scripts.
Now I’m using SSH Generic Sensor from HACS and it does all the work from HassOS without doing anything on devices just configuring this component, for exaple here is temp monitor on OMV:
That’s a really nice way to do the logging!
For me the way I did it was also to understand and learn mqtt discovery.
I have a Matrix Creator and want to send the sensor data to Hass. So first I thougt lets start with something easy like this!
Maybe I will upload the script to a repository instead so you can make a pull request!
Then I also can add a requirements file to easy install the deps
UTC = pytz.utc
DEFAULT_TIME_ZONE = timezone('Australia/Hobart')#Local Time zone
broker_url = "10.1.1.100"#MQTT server IP
broker_port = 1883 #MQTT server port
client = mqtt.Client()
client.username_pw_set("mqtt_user", "redacted") #Username and pass if configured otherwise you should comment out this
deviceName = "gpio_bridge_1" #Name off your PI
SYSFILE = '/sys/devices/platform/soc/soc:firmware/get_throttled'
WAIT_TIME_SECONDS = 60
EDIT: actually I think it’s step 3 that failed:
pi@gpio_mqtt_bridge_1:~/system_sensors $ pip install -r requirements.txt
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: paho-mqtt==1.4.0 in /usr/local/lib/python2.7/dist-packages (from -r requirements.txt (line 1)) (1.4.0)
Collecting psutil==5.6.3 (from -r requirements.txt (line 2))
Downloading https://files.pythonhosted.org/packages/1c/ca/5b8c1fe032a458c2c4bcbe509d1401dca9dda35c7fc46b36bb81c2834740/psutil-5.6.3.tar.gz (435kB)
|████████████████████████████████| 440kB 2.3MB/s
Collecting pytz==2019.2 (from -r requirements.txt (line 3))
Downloading https://files.pythonhosted.org/packages/87/76/46d697698a143e05f77bec5a526bf4e56a0be61d63425b68f4ba553b51f2/pytz-2019.2-py2.py3-none-any.whl (508kB)
|████████████████████████████████| 512kB 5.2MB/s
Building wheels for collected packages: psutil
Building wheel for psutil (setup.py) ... done
Stored in directory: /home/pi/.cache/pip/wheels/90/7e/74/bb640d77775e6b6a78bcc3120f9fea4d2a28b2706de1cff37d
Successfully built psutil
ERROR: influxdb 5.2.2 has requirement requests>=2.17.0, but you'll have requests 2.12.4 which is incompatible.
Installing collected packages: psutil, pytz
Found existing installation: psutil 5.6.1
Uninstalling psutil-5.6.1:
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/psutil-5.6.1.dist-info/DESCRIPTION.rst'
Consider using the `--user` option or check the permissions.
Will do. First I’m going to further implement the mqtt discovery so all the metrics will be seen as one device!
You always can make a pull request to update the readme.md