added translations for MQTT and partially display command (#180)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from random import randrange
|
from random import randrange
|
||||||
|
|
||||||
# Script version
|
# Script version
|
||||||
version = "0.6.2"
|
version = "0.6.3"
|
||||||
|
|
||||||
# MQTT server configuration
|
# MQTT server configuration
|
||||||
mqtt_host = "ip address or host"
|
mqtt_host = "ip address or host"
|
||||||
@@ -22,6 +22,7 @@ hass_token = "your_hass_token"
|
|||||||
hass_host = "your_hass_host"
|
hass_host = "your_hass_host"
|
||||||
|
|
||||||
# Messages configuration
|
# Messages configuration
|
||||||
|
language = "en"
|
||||||
|
|
||||||
# Interval in seconds between probes when running the script as a service (--service option)
|
# Interval in seconds between probes when running the script as a service (--service option)
|
||||||
service_sleep_time = 120
|
service_sleep_time = 120
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import html
|
|||||||
import uuid
|
import uuid
|
||||||
import glob
|
import glob
|
||||||
import requests
|
import requests
|
||||||
|
import configparser
|
||||||
#import external sensor lib only if one uses external sensors
|
#import external sensor lib only if one uses external sensors
|
||||||
if config.ext_sensors:
|
if config.ext_sensors:
|
||||||
# append folder ext_sensor_lib
|
# append folder ext_sensor_lib
|
||||||
@@ -27,6 +28,15 @@ if config.ext_sensors:
|
|||||||
import ds18b20
|
import ds18b20
|
||||||
from sht21 import SHT21
|
from sht21 import SHT21
|
||||||
|
|
||||||
|
|
||||||
|
configlanguage = configparser.ConfigParser()
|
||||||
|
configlanguage.read(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'translations.ini'))
|
||||||
|
|
||||||
|
def get_translation(key):
|
||||||
|
""" get the correct translation"""
|
||||||
|
return configlanguage.get(config.language, key, fallback=key)
|
||||||
|
|
||||||
|
|
||||||
def check_wifi_signal(format):
|
def check_wifi_signal(format):
|
||||||
try:
|
try:
|
||||||
full_cmd = "ls /sys/class/ieee80211/*/device/net/"
|
full_cmd = "ls /sys/class/ieee80211/*/device/net/"
|
||||||
@@ -149,7 +159,7 @@ def read_ext_sensors():
|
|||||||
# in case we have any problems to read the sensor, we continue and keep default values
|
# in case we have any problems to read the sensor, we continue and keep default values
|
||||||
except Exception:
|
except Exception:
|
||||||
print ("Error while reading sensor %s" % item[1])
|
print ("Error while reading sensor %s" % item[1])
|
||||||
print (ext_sensors)
|
#print (ext_sensors)
|
||||||
return ext_sensors
|
return ext_sensors
|
||||||
|
|
||||||
|
|
||||||
@@ -337,20 +347,20 @@ def print_measured_values(monitored_values):
|
|||||||
output += " Update Check Interval: {} seconds\n".format(config.update_check_interval)
|
output += " Update Check Interval: {} seconds\n".format(config.update_check_interval)
|
||||||
# Add dynamic measured values with units
|
# Add dynamic measured values with units
|
||||||
measured_values = {
|
measured_values = {
|
||||||
"CPU Load": ("cpu_load", "%"),
|
get_translation("cpu_load"): ("cpu_load", "%"),
|
||||||
"CPU Temp": ("cpu_temp", "°C"),
|
get_translation("cpu_temperature"): ("cpu_temp", "°C"),
|
||||||
"Used Space": ("used_space", "%"),
|
get_translation("used_space"): ("used_space", "%"),
|
||||||
"Voltage": ("voltage", "V"),
|
get_translation("voltage"): ("voltage", "V"),
|
||||||
"CPU Clock Speed": ("sys_clock_speed", "MHz"),
|
get_translation("cpu_clock_speed"): ("sys_clock_speed", "MHz"),
|
||||||
"Swap": ("swap", "%"),
|
get_translation("disk_swap"): ("swap", "%"),
|
||||||
"Memory": ("memory", "%"),
|
get_translation("memory_usage"): ("memory", "%"),
|
||||||
"Online since": ("uptime", ""),
|
get_translation("uptime"): ("uptime", ""),
|
||||||
"Wifi Signal": ("wifi_signal", "%"),
|
get_translation("wifi_signal"): ("wifi_signal", "%"),
|
||||||
"Wifi Signal dBm": ("wifi_signal_dbm", "dBm"),
|
get_translation("wifi_signal_strength")+" [dBm]": ("wifi_signal_dbm", "dBm"),
|
||||||
"RPI5 Fan Speed": ("rpi5_fan_speed", "RPM"),
|
get_translation("fan_speed"): ("rpi5_fan_speed", "RPM"),
|
||||||
"RPI Power Status": ("rpi_power_status", ""),
|
get_translation("rpi_power_status"): ("rpi_power_status", ""),
|
||||||
"Update": ("update", ""),
|
get_translation("update"): ("update", ""),
|
||||||
"External Sensors": ("ext_sensors", "")
|
get_translation("external_sensors"): ("ext_sensors", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
output += "\n:: Measured values\n"
|
output += "\n:: Measured values\n"
|
||||||
@@ -423,77 +433,77 @@ def config_json(what_config, device="0", hass_api=False):
|
|||||||
data["unique_id"] = hostname + "_" + what_config
|
data["unique_id"] = hostname + "_" + what_config
|
||||||
if what_config == "cpu_load":
|
if what_config == "cpu_load":
|
||||||
data["icon"] = "mdi:speedometer"
|
data["icon"] = "mdi:speedometer"
|
||||||
data["name"] = "CPU Usage"
|
data["name"] = get_translation("cpu_load")
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
data["unit_of_measurement"] = "%"
|
data["unit_of_measurement"] = "%"
|
||||||
elif what_config == "cpu_temp":
|
elif what_config == "cpu_temp":
|
||||||
data["icon"] = "hass:thermometer"
|
data["icon"] = "hass:thermometer"
|
||||||
data["name"] = "CPU Temperature"
|
data["name"] = get_translation("cpu_temperature")
|
||||||
data["unit_of_measurement"] = "°C"
|
data["unit_of_measurement"] = "°C"
|
||||||
data["device_class"] = "temperature"
|
data["device_class"] = "temperature"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
elif what_config == "used_space":
|
elif what_config == "used_space":
|
||||||
data["icon"] = "mdi:harddisk"
|
data["icon"] = "mdi:harddisk"
|
||||||
data["name"] = "Disk Usage"
|
data["name"] = get_translation("disk_usage")
|
||||||
data["unit_of_measurement"] = "%"
|
data["unit_of_measurement"] = "%"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
elif what_config == "voltage":
|
elif what_config == "voltage":
|
||||||
data["icon"] = "mdi:flash"
|
data["icon"] = "mdi:flash"
|
||||||
data["name"] = "CPU Voltage"
|
data["name"] = get_translation("cpu_voltage")
|
||||||
data["unit_of_measurement"] = "V"
|
data["unit_of_measurement"] = "V"
|
||||||
data["device_class"] = "voltage"
|
data["device_class"] = "voltage"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
elif what_config == "swap":
|
elif what_config == "swap":
|
||||||
data["icon"] = "mdi:harddisk"
|
data["icon"] = "mdi:harddisk"
|
||||||
data["name"] = "Disk Swap"
|
data["name"] = get_translation("disk_swap")
|
||||||
data["unit_of_measurement"] = "%"
|
data["unit_of_measurement"] = "%"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
elif what_config == "memory":
|
elif what_config == "memory":
|
||||||
data["icon"] = "mdi:memory"
|
data["icon"] = "mdi:memory"
|
||||||
data["name"] = "Memory Usage"
|
data["name"] = get_translation("memory_usage")
|
||||||
data["unit_of_measurement"] = "%"
|
data["unit_of_measurement"] = "%"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
elif what_config == "sys_clock_speed":
|
elif what_config == "sys_clock_speed":
|
||||||
data["icon"] = "mdi:speedometer"
|
data["icon"] = "mdi:speedometer"
|
||||||
data["name"] = "CPU Clock Speed"
|
data["name"] = get_translation("cpu_clock_speed")
|
||||||
data["unit_of_measurement"] = "MHz"
|
data["unit_of_measurement"] = "MHz"
|
||||||
data["device_class"] = "frequency"
|
data["device_class"] = "frequency"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
elif what_config == "uptime":
|
elif what_config == "uptime":
|
||||||
data["icon"] = "mdi:calendar"
|
data["icon"] = "mdi:calendar"
|
||||||
data["name"] = "Uptime"
|
data["name"] = get_translation("uptime")
|
||||||
data["value_template"] = "{{ as_datetime(value) }}"
|
data["value_template"] = "{{ as_datetime(value) }}"
|
||||||
data["device_class"] = "timestamp"
|
data["device_class"] = "timestamp"
|
||||||
elif what_config == "uptime_seconds":
|
elif what_config == "uptime_seconds":
|
||||||
data["icon"] = "mdi:timer-outline"
|
data["icon"] = "mdi:timer-outline"
|
||||||
data["name"] = "Uptime"
|
data["name"] = get_translation("uptime")
|
||||||
data["unit_of_measurement"] = "s"
|
data["unit_of_measurement"] = "s"
|
||||||
data["device_class"] = "duration"
|
data["device_class"] = "duration"
|
||||||
data["state_class"] = "total_increasing"
|
data["state_class"] = "total_increasing"
|
||||||
elif what_config == "wifi_signal":
|
elif what_config == "wifi_signal":
|
||||||
data["icon"] = "mdi:wifi"
|
data["icon"] = "mdi:wifi"
|
||||||
data["name"] = "Wifi Signal"
|
data["name"] = get_translation("wifi_signal")
|
||||||
data["unit_of_measurement"] = "%"
|
data["unit_of_measurement"] = "%"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
data["device_class"] = "signal_strength"
|
data["device_class"] = "signal_strength"
|
||||||
elif what_config == "wifi_signal_dbm":
|
elif what_config == "wifi_signal_dbm":
|
||||||
data["icon"] = "mdi:wifi"
|
data["icon"] = "mdi:wifi"
|
||||||
data["name"] = "Wifi Signal"
|
data["name"] = get_translation("wifi_signal_strength")
|
||||||
data["unit_of_measurement"] = "dBm"
|
data["unit_of_measurement"] = "dBm"
|
||||||
data["device_class"] = "signal_strength"
|
data["device_class"] = "signal_strength"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
elif what_config == "rpi5_fan_speed":
|
elif what_config == "rpi5_fan_speed":
|
||||||
data["icon"] = "mdi:fan"
|
data["icon"] = "mdi:fan"
|
||||||
data["name"] = "Fan Speed"
|
data["name"] = get_translation("fan_speed")
|
||||||
data["unit_of_measurement"] = "RPM"
|
data["unit_of_measurement"] = "RPM"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
elif what_config == "status":
|
elif what_config == "status":
|
||||||
data["icon"] = "mdi:lan-connect"
|
data["icon"] = "mdi:lan-connect"
|
||||||
data["name"] = "Status"
|
data["name"] = get_translation("status")
|
||||||
data["value_template"] = "{{ 'online' if value == '1' else 'offline' }}"
|
data["value_template"] = "{{ 'online' if value == '1' else 'offline' }}"
|
||||||
elif what_config == "git_update":
|
elif what_config == "git_update":
|
||||||
data["icon"] = "mdi:git"
|
data["icon"] = "mdi:git"
|
||||||
data["name"] = "RPi MQTT Monitor"
|
data["name"] = get_translation("rpi_mqtt_monitor")
|
||||||
data["title"] = "Device Update"
|
data["title"] = "Device Update"
|
||||||
data["device_class"] = "update"
|
data["device_class"] = "update"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
@@ -501,7 +511,7 @@ def config_json(what_config, device="0", hass_api=False):
|
|||||||
elif what_config == "update":
|
elif what_config == "update":
|
||||||
version = update.check_git_version_remote(script_dir)
|
version = update.check_git_version_remote(script_dir)
|
||||||
data["icon"] = "mdi:update"
|
data["icon"] = "mdi:update"
|
||||||
data["name"] = "RPi MQTT Monitor"
|
data["name"] = get_translation("rpi_mqtt_monitor")
|
||||||
data["title"] = "New Version"
|
data["title"] = "New Version"
|
||||||
data["state_topic"] = config.mqtt_topic_prefix + "/" + hostname + "/" + "git_update"
|
data["state_topic"] = config.mqtt_topic_prefix + "/" + hostname + "/" + "git_update"
|
||||||
data["value_template"] = "{{ {'installed_version': value_json.installed_ver, 'latest_version': value_json.new_ver } | to_json }}"
|
data["value_template"] = "{{ {'installed_version': value_json.installed_ver, 'latest_version': value_json.new_ver } | to_json }}"
|
||||||
@@ -513,43 +523,43 @@ def config_json(what_config, device="0", hass_api=False):
|
|||||||
data['release_summary'] = get_release_notes(version)
|
data['release_summary'] = get_release_notes(version)
|
||||||
elif what_config == "restart_button":
|
elif what_config == "restart_button":
|
||||||
data["icon"] = "mdi:restart"
|
data["icon"] = "mdi:restart"
|
||||||
data["name"] = "System Restart"
|
data["name"] = get_translation("system_restart")
|
||||||
data["command_topic"] = config.mqtt_discovery_prefix + "/update/" + hostname + "/command"
|
data["command_topic"] = config.mqtt_discovery_prefix + "/update/" + hostname + "/command"
|
||||||
data["payload_press"] = "restart"
|
data["payload_press"] = "restart"
|
||||||
data["device_class"] = "restart"
|
data["device_class"] = "restart"
|
||||||
elif what_config == "shutdown_button":
|
elif what_config == "shutdown_button":
|
||||||
data["icon"] = "mdi:power"
|
data["icon"] = "mdi:power"
|
||||||
data["name"] = "System Shutdown"
|
data["name"] = get_translation("system_shutdown")
|
||||||
data["command_topic"] = config.mqtt_discovery_prefix + "/update/" + hostname + "/command"
|
data["command_topic"] = config.mqtt_discovery_prefix + "/update/" + hostname + "/command"
|
||||||
data["payload_press"] = "shutdown"
|
data["payload_press"] = "shutdown"
|
||||||
data["device_class"] = "restart"
|
data["device_class"] = "restart"
|
||||||
elif what_config == "display_on":
|
elif what_config == "display_on":
|
||||||
data["icon"] = "mdi:monitor"
|
data["icon"] = "mdi:monitor"
|
||||||
data["name"] = "Monitor ON"
|
data["name"] = get_translation("monitor_on")
|
||||||
data["command_topic"] = config.mqtt_discovery_prefix + "/update/" + hostname + "/command"
|
data["command_topic"] = config.mqtt_discovery_prefix + "/update/" + hostname + "/command"
|
||||||
data["payload_press"] = "display_on"
|
data["payload_press"] = "display_on"
|
||||||
data["device_class"] = "restart"
|
data["device_class"] = "restart"
|
||||||
elif what_config == "display_off":
|
elif what_config == "display_off":
|
||||||
data["icon"] = "mdi:monitor"
|
data["icon"] = "mdi:monitor"
|
||||||
data["name"] = "Monitor OFF"
|
data["name"] = get_translation("monitor_off")
|
||||||
data["command_topic"] = config.mqtt_discovery_prefix + "/update/" + hostname + "/command"
|
data["command_topic"] = config.mqtt_discovery_prefix + "/update/" + hostname + "/command"
|
||||||
data["payload_press"] = "display_off"
|
data["payload_press"] = "display_off"
|
||||||
data["device_class"] = "restart"
|
data["device_class"] = "restart"
|
||||||
elif what_config == device + "_temp":
|
elif what_config == device + "_temp":
|
||||||
data["icon"] = "hass:thermometer"
|
data["icon"] = "hass:thermometer"
|
||||||
data["name"] = device + " Temperature"
|
data["name"] = device + " " + get_translation("temperature")
|
||||||
data["unit_of_measurement"] = "°C"
|
data["unit_of_measurement"] = "°C"
|
||||||
data["device_class"] = "temperature"
|
data["device_class"] = "temperature"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
elif what_config == "rpi_power_status":
|
elif what_config == "rpi_power_status":
|
||||||
data["icon"] = "mdi:flash"
|
data["icon"] = "mdi:flash"
|
||||||
data["name"] = "RPi Power Status"
|
data["name"] = get_translation("rpi_power_status")
|
||||||
elif what_config == "apt_updates":
|
elif what_config == "apt_updates":
|
||||||
data["icon"] = "mdi:update"
|
data["icon"] = "mdi:update"
|
||||||
data["name"] = "APT Updates"
|
data["name"] = get_translation("apt_updates")
|
||||||
elif what_config == "ds18b20_status":
|
elif what_config == "ds18b20_status":
|
||||||
data["icon"] = "hass:thermometer"
|
data["icon"] = "hass:thermometer"
|
||||||
data["name"] = device + " Temperature"
|
data["name"] = device + " " + get_translation("temperature")
|
||||||
data["unit_of_measurement"] = "°C"
|
data["unit_of_measurement"] = "°C"
|
||||||
data["device_class"] = "temperature"
|
data["device_class"] = "temperature"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
@@ -558,7 +568,7 @@ def config_json(what_config, device="0", hass_api=False):
|
|||||||
data["unique_id"] = hostname + "_" + what_config + "_" + device
|
data["unique_id"] = hostname + "_" + what_config + "_" + device
|
||||||
elif what_config == "sht21_temp_status":
|
elif what_config == "sht21_temp_status":
|
||||||
data["icon"] = "hass:thermometer"
|
data["icon"] = "hass:thermometer"
|
||||||
data["name"] = device + " Temperature"
|
data["name"] = device + " " + get_translation("temperature")
|
||||||
data["unit_of_measurement"] = "°C"
|
data["unit_of_measurement"] = "°C"
|
||||||
data["device_class"] = "temperature"
|
data["device_class"] = "temperature"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
@@ -567,7 +577,7 @@ def config_json(what_config, device="0", hass_api=False):
|
|||||||
data["unique_id"] = hostname + "_" + what_config + "_" + device
|
data["unique_id"] = hostname + "_" + what_config + "_" + device
|
||||||
elif what_config == "sht21_hum_status":
|
elif what_config == "sht21_hum_status":
|
||||||
data["icon"] = "mdi:water-percent"
|
data["icon"] = "mdi:water-percent"
|
||||||
data["name"] = device + " Humidity"
|
data["name"] = device + " " + get_translation("humidity")
|
||||||
data["unit_of_measurement"] = "%"
|
data["unit_of_measurement"] = "%"
|
||||||
data["device_class"] = "temperature"
|
data["device_class"] = "temperature"
|
||||||
data["state_class"] = "measurement"
|
data["state_class"] = "measurement"
|
||||||
|
|||||||
53
src/translations.ini
Normal file
53
src/translations.ini
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
[en]
|
||||||
|
cpu_load = CPU load
|
||||||
|
cpu_temperature = CPU Temperature
|
||||||
|
disk_usage = Disk Usage
|
||||||
|
cpu_voltage = CPU Voltage
|
||||||
|
disk_swap = Disk Swap
|
||||||
|
memory_usage = Memeory Usage
|
||||||
|
cpu_clock_speed = CPU Clock Speed
|
||||||
|
uptime = Uptime
|
||||||
|
wifi_signal = WiFi Signal
|
||||||
|
wifi_signal_strength = WiFi Signal Strength
|
||||||
|
fan_speed = Fan Speed
|
||||||
|
status = Status
|
||||||
|
rpi_mqtt_monitor = RPi MQTT Monitor
|
||||||
|
system_restart = System Restart
|
||||||
|
system_shutdown = System Shutdown
|
||||||
|
monitor_on = Monitor On
|
||||||
|
monitor_off = Monitor Off
|
||||||
|
temperature = Temperature
|
||||||
|
rpi_power_status = RPi Power Status
|
||||||
|
apt_updates = APT Updates
|
||||||
|
humidity = Humidity
|
||||||
|
used_space = Used Space
|
||||||
|
voltage = Voltage
|
||||||
|
update = update
|
||||||
|
external_sensors = External Sensors
|
||||||
|
|
||||||
|
[de]
|
||||||
|
cpu_load = CPU Auslastung
|
||||||
|
cpu_temperature = CPU Temperatur
|
||||||
|
disk_usage = Festplattennutzung
|
||||||
|
cpu_voltage = CPU Spannung
|
||||||
|
disk_swap = Swapgröße
|
||||||
|
memory_usage = Arbeitsspeichernutzung
|
||||||
|
cpu_clock_speed = Taktfrequenz
|
||||||
|
uptime = Betriebszeit
|
||||||
|
wifi_signal = WLAN Signal
|
||||||
|
wifi_signal_strength = WLAN Signalstärke
|
||||||
|
fan_speed = Lüfter Drehzahl
|
||||||
|
status = Status
|
||||||
|
rpi_mqtt_monitor = RPi MQTT Monitor
|
||||||
|
system_restart = System neustarten
|
||||||
|
system_shutdown = System herunterfahren
|
||||||
|
monitor_on = Monitor ein
|
||||||
|
monitor_off = Monitor aus
|
||||||
|
temperature = Temperatur
|
||||||
|
rpi_power_status = RPi Stromstatus
|
||||||
|
apt_updates = APT Updates
|
||||||
|
humidity = Luftfeuchtigkeit
|
||||||
|
used_space = belegter Speicherplatz
|
||||||
|
voltage = Spannung
|
||||||
|
update = Update
|
||||||
|
external_sensors = Externe Sensoren
|
||||||
Reference in New Issue
Block a user