diff --git a/README.md b/README.md index 7866309..5aad8db 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ It currently logs the following data: | timezone | true | \ | Your local timezone (you can find the list of timezones here: [time zones](https://gist.github.com/heyalexej/8bf688fd67d7199be4a1682b3eec7568)) | power_integer_state | false | false | Return the power state in text or integer form | update_interval | false | 60 | The update interval to send new values to the MQTT broker +| check_available_updates | false | false | Check the # of avaiblable updates | check_wifi_strength | false | false | Check the wifi strength | external_drives | false | \ | Declare external drives you want to check disk usage of (see example settings.yaml) diff --git a/src/settings_example.yaml b/src/settings_example.yaml index ff93673..a0c49cb 100644 --- a/src/settings_example.yaml +++ b/src/settings_example.yaml @@ -9,5 +9,6 @@ timezone: Europe/Brussels power_integer_state: false #defaults to false update_interval: 60 #Defaults to 60 check_wifi_strength: true +check_available_updates: true external_drives: Drive1: /boot/ \ No newline at end of file diff --git a/src/system_sensors.py b/src/system_sensors.py index 99191d3..56cc2fc 100644 --- a/src/system_sensors.py +++ b/src/system_sensors.py @@ -10,7 +10,6 @@ import paho.mqtt.client as mqtt import pytz import yaml -import apt from pytz import timezone import argparse @@ -82,10 +81,10 @@ def updateSensors(): + get_rpi_power_status() + '", "last_boot": "' + get_last_boot() - + '", "updates": ' - + get_updates() + ', "last_message": "' + time.ctime()+'"') + if "check_available_updates" in settings and settings["check_available_updates"]: + payload_str = payload_str + ', "updates": ' + get_updates() if "check_wifi_strength" in settings and settings["check_wifi_strength"]: payload_str = payload_str + ', "wifi_strength": ' + get_wifi_strength() if "external_drives" in settings: @@ -351,29 +350,6 @@ def _parser(): qos=1, retain=True, ) - - mqttClient.publish( - topic="homeassistant/sensor/" - + deviceName - + "/" - + deviceName - + "Updates/config", - payload='{"name":"' - + deviceName - + 'Updates","state_topic":"system-sensors/sensor/' - + deviceName - + '/state","value_template":"{{ value_json.updates}}","unique_id":"' - + deviceName.lower() - + '_sensor_updates","device":{"identifiers":["' - + deviceName.lower() - + '_sensor"],"name":"' - + deviceName - + 'Sensors","model":"RPI ' - + deviceName - + '","manufacturer":"RPI"}, "icon":"mdi:cellphone-arrow-down"}', - qos=1, - retain=True, - ) mqttClient.publish( topic="homeassistant/sensor/" @@ -398,6 +374,31 @@ def _parser(): retain=True, ) + if "check_available_updates" in settings and settings["check_available_updates"]: + import apt + mqttClient.publish( + topic="homeassistant/sensor/" + + deviceName + + "/" + + deviceName + + "Updates/config", + payload='{"name":"' + + deviceName + + 'Updates","state_topic":"system-sensors/sensor/' + + deviceName + + '/state","value_template":"{{ value_json.updates}}","unique_id":"' + + deviceName.lower() + + '_sensor_updates","device":{"identifiers":["' + + deviceName.lower() + + '_sensor"],"name":"' + + deviceName + + 'Sensors","model":"RPI ' + + deviceName + + '","manufacturer":"RPI"}, "icon":"mdi:cellphone-arrow-down"}', + qos=1, + retain=True, + ) + if "check_wifi_strength" in settings and settings["check_wifi_strength"]: mqttClient.publish( topic="homeassistant/sensor/"