forked from peter/volvo2mqtt
Fix offline devices after HA reboot
This commit is contained in:
+6
-1
@@ -40,7 +40,7 @@ def connect():
|
|||||||
|
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
mqtt_client.publish(availability_topic, "online")
|
send_heartbeat()
|
||||||
if len(subscribed_topics) > 0:
|
if len(subscribed_topics) > 0:
|
||||||
for topic in subscribed_topics:
|
for topic in subscribed_topics:
|
||||||
mqtt_client.subscribe(topic)
|
mqtt_client.subscribe(topic)
|
||||||
@@ -92,6 +92,7 @@ def update_loop():
|
|||||||
create_ha_devices()
|
create_ha_devices()
|
||||||
while True:
|
while True:
|
||||||
print("Sending mqtt update...")
|
print("Sending mqtt update...")
|
||||||
|
send_heartbeat()
|
||||||
update_car_data()
|
update_car_data()
|
||||||
print("Mqtt update done. Next run in " + str(settings["updateInterval"]) + " seconds.")
|
print("Mqtt update done. Next run in " + str(settings["updateInterval"]) + " seconds.")
|
||||||
time.sleep(settings["updateInterval"])
|
time.sleep(settings["updateInterval"])
|
||||||
@@ -166,5 +167,9 @@ def create_ha_devices():
|
|||||||
json.dumps(config),
|
json.dumps(config),
|
||||||
retain=True
|
retain=True
|
||||||
)
|
)
|
||||||
|
send_heartbeat()
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
|
|
||||||
|
def send_heartbeat():
|
||||||
mqtt_client.publish(availability_topic, "online")
|
mqtt_client.publish(availability_topic, "online")
|
||||||
|
|||||||
Reference in New Issue
Block a user