From b7794d837b45ad637b81e936b6de2042a319b452 Mon Sep 17 00:00:00 2001 From: Linus Dietz <45101649+Dielee@users.noreply.github.com> Date: Mon, 26 Jun 2023 07:16:41 +0200 Subject: [PATCH] Fix offline devices after HA reboot --- src/mqtt.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/mqtt.py b/src/mqtt.py index d0b3b5b..09b92a9 100644 --- a/src/mqtt.py +++ b/src/mqtt.py @@ -40,7 +40,7 @@ def connect(): def on_connect(client, userdata, flags, rc): - mqtt_client.publish(availability_topic, "online") + send_heartbeat() if len(subscribed_topics) > 0: for topic in subscribed_topics: mqtt_client.subscribe(topic) @@ -92,6 +92,7 @@ def update_loop(): create_ha_devices() while True: print("Sending mqtt update...") + send_heartbeat() update_car_data() print("Mqtt update done. Next run in " + str(settings["updateInterval"]) + " seconds.") time.sleep(settings["updateInterval"]) @@ -166,5 +167,9 @@ def create_ha_devices(): json.dumps(config), retain=True ) + send_heartbeat() time.sleep(2) + + +def send_heartbeat(): mqtt_client.publish(availability_topic, "online")