remove sleep time

This commit is contained in:
Christopher Fenner
2024-01-29 22:10:54 +01:00
parent 1907aa38f2
commit 910b6a1738
2 changed files with 2 additions and 27 deletions

View File

@@ -35,9 +35,6 @@ qos = 0
# this is the time between executiuons if the script is used as service (--service option)
service_sleep_time = 120
# This is the time between sending the individual messages
sleep_time = 0.1
cpu_load = True
cpu_temp = True
used_space = True

View File

@@ -306,93 +306,71 @@ def publish_to_mqtt(cpu_load=0, cpu_temp=0, used_space=0, voltage=0, sys_clock_s
client = paho.Client(client_id="rpi-mqtt-monitor-" + hostname)
client.username_pw_set(config.mqtt_user, config.mqtt_password)
client.connect(config.mqtt_host, int(config.mqtt_port))
client.loop_start()
# publish monitored values to MQTT
if config.cpu_load:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_cpuload/config",
config_json('cpuload'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/cpuload", cpu_load, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.cpu_temp:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_cputemp/config",
config_json('cputemp'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/cputemp", cpu_temp, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.used_space:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_diskusage/config",
config_json('diskusage'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/diskusage", used_space, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.voltage:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_voltage/config",
config_json('voltage'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/voltage", voltage, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.swap:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_swap/config",
config_json('swap'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/swap", swap, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.memory:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_memory/config",
config_json('memory'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/memory", memory, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.sys_clock_speed:
if config.discovery_messages:
client.publish(
"homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_sys_clock_speed/config",
config_json('sys_clock_speed'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/sys_clock_speed", sys_clock_speed, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.uptime:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_uptime_days/config",
config_json('uptime_days'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/uptime_days", uptime_days, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.wifi_signal:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_wifi_signal/config",
config_json('wifi_signal'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/wifi_signal", wifi_signal, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.wifi_signal_dbm:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_wifi_signal_dbm/config",
config_json('wifi_signal_dbm'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/wifi_signal_dbm", wifi_signal_dbm, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.rpi5_fan_speed:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_rpi5_fan_speed/config",
config_json('rpi5_fan_speed'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/rpi5_fan_speed", rpi5_fan_speed, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.git_update:
if config.discovery_messages:
client.publish("homeassistant/binary_sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_git_update/config",
config_json('git_update'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/git_update", git_update, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
client.loop_stop()
# disconnect from mqtt server
client.disconnect()