Skip to content

Commit

Permalink
Added drive temperatures via SMART
Browse files Browse the repository at this point in the history
This fixes ironsheep#28.
  • Loading branch information
thorsten-meinl-knime committed May 3, 2024
1 parent 259e42c commit 3f87dbf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
21 changes: 21 additions & 0 deletions ISP-RPi-mqtt-daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1727,6 +1734,20 @@ 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(':')
rpiDevices[name] = { K_RPI_BLK_DEV_TEMP: temp }
return rpiDevices


def getDrivesDictionary():
global rpi_filesystem
Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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._
Expand Down Expand Up @@ -247,7 +247,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
Expand Down Expand Up @@ -293,7 +293,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
Expand Down Expand Up @@ -375,7 +375,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
Expand All @@ -402,7 +402,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
Expand Down Expand Up @@ -493,7 +493,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._
Expand Down
6 changes: 6 additions & 0 deletions smartctl-helper
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3f87dbf

Please sign in to comment.