From 4a5449dbd685be4061f72f18236880cf5d63b6a4 Mon Sep 17 00:00:00 2001 From: Meatballs1 Date: Wed, 20 Mar 2024 12:14:40 +0000 Subject: [PATCH] Add online message --- hc2mqtt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hc2mqtt b/hc2mqtt index 71abdc1..c0311c6 100755 --- a/hc2mqtt +++ b/hc2mqtt @@ -41,6 +41,10 @@ def hc2mqtt( mqtt_keyfile: str, mqtt_clientname: str, ): + + def on_connect(client, userdata, flags, rc): + client.publish(f"{mqtt_prefix}LWT", payload="Online", qos=0, retain=True) + click.echo( f"Hello {devices_file=} {mqtt_host=} {mqtt_prefix=} " f"{mqtt_port=} {mqtt_username=} {mqtt_password=} " @@ -66,7 +70,8 @@ def hc2mqtt( else: client.tls_set(cert_reqs=ssl.CERT_NONE) - client.will_set(f"{mqtt_prefix}status", payload="Offline", qos=0, retain=True) + client.will_set(f"{mqtt_prefix}LWT", payload="Offline", qos=0, retain=True) + client.on_connect = on_connect client.connect(host=mqtt_host, port=mqtt_port, keepalive=70) for device in devices: