diff --git a/ISP-RPi-mqtt-daemon.py b/ISP-RPi-mqtt-daemon.py index 73d9d79..bd3b15e 100755 --- a/ISP-RPi-mqtt-daemon.py +++ b/ISP-RPi-mqtt-daemon.py @@ -1633,6 +1633,9 @@ def isPeriodTimerRunning(): K_RPI_DRV_NFS = "device-nfs" K_RPI_DVC_IP = "ip" K_RPI_DVC_PATH = "dvc" +# new block devices dictionary +K_RPI_BLK_DEVICES = "block_devices" +K_RPI_BLK_DEV_TEMP = "temperature_c" # new memory dictionary K_RPI_MEMORY = "memory" K_RPI_MEM_TOTAL = "size_mb" @@ -1689,6 +1692,10 @@ def send_status(timestamp, nothing): rpiData[K_RPI_NETWORK] = getNetworkDictionary() + rpiBlockDevices = getBlockDevicesDictionary() + if len(rpiBlockDevices) > 0: + rpiData[K_RPI_BLK_DEVICES] = rpiBlockDevices + rpiDrives = getDrivesDictionary() if len(rpiDrives) > 0: rpiData[K_RPI_DRIVES] = rpiDrives @@ -1727,6 +1734,21 @@ def forceSingleDigit(temperature): tempInterp = '{:.1f}'.format(temperature) return float(tempInterp) +def getBlockDevicesDictionary(): + rpiDevices = OrderedDict() + + smartctlHelper = os.path.join(os.path.dirname(__file__), 'smartctl-helper') + stdout, stderr, returncode = invoke_shell_cmd("sudo " + smartctlHelper) + if returncode != 0: + print_line('Could not query SMART data: {}'.format(stderr), warning=True) + return rpiDevices + + for device in stdout.decode('utf-8').splitlines(): + [ name, temp ] = device.split(':') + if len(temp) > 0: + rpiDevices[name] = { K_RPI_BLK_DEV_TEMP: float(temp) } + return rpiDevices + def getDrivesDictionary(): global rpi_filesystem diff --git a/README.md b/README.md index bcc4d28..e031866 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Additional pages: - Tested on Raspberry Pi's zero, 2, 3, and 4 with Jessie, Stretch, Buster, and Bullseye - Tested with Home Assistant v0.111.0 -> 2023.4.6 -- Tested with Mosquitto broker +- Tested with Mosquitto broker - Data is published via MQTT - MQTT discovery messages are sent so RPi's are automatically registered with Home Assistant (if MQTT discovery is enabled in your HA installation) - MQTT authentication support @@ -129,7 +129,7 @@ First install extra packages the script needs (select one of the two following c ### Packages for Ubuntu, Raspberry pi OS, and the like ```shell -sudo apt-get install git python3 python3-pip python3-tzlocal python3-sdnotify python3-colorama python3-unidecode python3-apt python3-paho-mqtt python3-requests +sudo apt-get install git python3 python3-pip python3-tzlocal python3-sdnotify python3-colorama python3-unidecode python3-apt python3-paho-mqtt python3-requests smartmontools ``` ### Additional Packages for pure Ubuntu @@ -143,7 +143,7 @@ sudo apt-get install libraspberrypi-bin net-tools ### Packages for Arch Linux ```shell -sudo pacman -S python python-pip python-tzlocal python-notify2 python-colorama python-unidecode python-paho-mqtt python-requests inetutils +sudo pacman -S python python-pip python-tzlocal python-notify2 python-colorama python-unidecode python-paho-mqtt python-requests inetutils smartmontools ``` **NOTE**: _for users of Arch Linux the number of updates available will NOT be reported (will always show as '-1'.) This is due to Arch Linux not using the apt package manager._ @@ -214,6 +214,15 @@ sudo pip3 install -r requirements.txt ... need to have any mention of `/opt/RPi-Reporter-MQTT2HA-Daemon` changed to your install location **before you can run this script as a service.** +If you want to report SMART data of your block devices, such as the temperature, and you are running as a non-root user you have to add a sudo-rule for the _smartctl-helper_ as follows: + +```shell +sudo echo "daemon ALL=NOPASSWD: /opt/RPi-Reporter-MQTT2HA-Daemon/smartctl-helper" > /etc/sudoers.d/90-smartctl-helper +sudo chmod 440 /etc/sudoers.d/90-smartctl-helper +``` + +Replace `daemon` with the user name under which you will run. + #### Why are we checking-out the latest release? When I'm developing new features I'll work on a different branch thereby not affecting master. When they are tested I'll merge the development brach into master. However it is much easier to merge pull requests directly into master. This action will, for a short period of time, make the **master branch have possibly non-working code**! You don't want this version until I've completed my testing of the new version and marked it as a new release. The clone gets you all versions while the checkout command moves your installation to the released version so you are running the latest fully tested code. You can always check the [releases page](https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon/releases) to find out which is the latest. This also tells you what changes appeared in each release. @@ -247,7 +256,7 @@ password = {your mqtt password if your setup requires one} Now that your config.ini is setup let's test! -**NOTE:** *If you wish to support remote commanding of your RPi then you can find additional configuration steps in [Setting up RPi Control from Home Assistant](./RMTECTRL.md) However, to simplifly your effort, please complete the following steps to ensure all is running as desired before you attempt to set up remote control.* +**NOTE:** _If you wish to support remote commanding of your RPi then you can find additional configuration steps in [Setting up RPi Control from Home Assistant](./RMTECTRL.md) However, to simplifly your effort, please complete the following steps to ensure all is running as desired before you attempt to set up remote control._ ## Execution @@ -293,7 +302,7 @@ $ daemon : daemon video # ^^^^^ now it is present ``` -*NOTE: Yes, `video` is correct. This appears to be due to our accessing the GPU temperatures.* +_NOTE: Yes, `video` is correct. This appears to be due to our accessing the GPU temperatures._ ### Choose Run Style @@ -375,7 +384,7 @@ systemctl status isp-rpi-reporter.service ``` -**NOTE**: *Wondering about the "checkout" command? See [Why are we checking-out the latest release?](#why-are-we-checking-out-the-latest-release) above.* +**NOTE**: _Wondering about the "checkout" command? See [Why are we checking-out the latest release?](#why-are-we-checking-out-the-latest-release) above._ #### SysV init script commands to perform update @@ -402,7 +411,7 @@ sudo /etc/init.d/rpi-reporter status ``` -**NOTE**: *Wondering about the "checkout" command? See [Why are we checking-out the latest release?](#why-are-we-checking-out-the-latest-release) above.* +**NOTE**: _Wondering about the "checkout" command? See [Why are we checking-out the latest release?](#why-are-we-checking-out-the-latest-release) above._ ## Integration @@ -493,7 +502,6 @@ See Closed Issues: [#94](https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemo We occasionaly have reports of users who updated their RPi afterwhich the RPI reporter Daemon script fails to start. The issue is that one of the packages updated appears to have reset the `daemon` group perminsions. For instructions on resetting the permissions to what is needed see: [Set up daemon account to allow access to temperature values](https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon#set-up-daemon-account-to-allow-access-to-temperature-values) - ### Issue: Some of my RPi's don't show up in HA Most often fix: _install the missing package._ diff --git a/smartctl-helper b/smartctl-helper new file mode 100755 index 0000000..4c11a9d --- /dev/null +++ b/smartctl-helper @@ -0,0 +1,6 @@ +#!/bin/bash + +smartctl --scan | awk '{ print $1 }' | while read dev; do + temp="$(smartctl -a $dev | grep "Temperature:" | awk '{ print $2 }')" + echo "$dev:$temp" +done