From cacc8f1eb0bf2646c5ac7dca547412d5ef9d8a24 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sat, 22 May 2021 16:25:02 +0200 Subject: [PATCH] Fix discovery on MQTT reconnect Fix discovery on MQTT reconnect (#12140) --- tasmota/xdrv_12_discovery.ino | 9 +++++++-- tasmota/xdrv_12_home_assistant.ino | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tasmota/xdrv_12_discovery.ino b/tasmota/xdrv_12_discovery.ino index 0e04303f1..16cca756b 100644 --- a/tasmota/xdrv_12_discovery.ino +++ b/tasmota/xdrv_12_discovery.ino @@ -220,13 +220,13 @@ void TasDiscovery(void) { } void TasRediscover(void) { - TasmotaGlobal.discovery_counter = 1; // Delayed discovery or clear retained messages + TasmotaGlobal.discovery_counter = 1; // Delayed discovery or clear retained messages } void TasDiscoverInit(void) { if (ResetReason() != REASON_DEEP_SLEEP_AWAKE) { Settings.flag.hass_discovery = 0; // SetOption19 - Enable Tasmota discovery and Disable legacy Hass discovery - TasmotaGlobal.discovery_counter = 10; // Delayed discovery + TasmotaGlobal.discovery_counter = 10; // Delayed discovery } } @@ -281,6 +281,11 @@ bool Xdrv12(uint8_t function) { case FUNC_COMMAND: result = DecodeCommand(kTasDiscoverCommands, TasDiscoverCommand, kTasDiscoverSynonyms); break; + case FUNC_MQTT_SUBSCRIBE: + if (0 == Mqtt.initial_connection_state) { + TasRediscover(); + } + break; case FUNC_MQTT_INIT: TasDiscoverInit(); break; diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index 323c1b2c5..7f203f54c 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -1179,6 +1179,7 @@ bool Xdrv12(uint8_t function) case FUNC_ANY_KEY: HAssAnyKey(); break; +/* case FUNC_MQTT_INIT: hass_mode = 0; // Discovery only if Settings.flag.hass_discovery is set TasmotaGlobal.discovery_counter = 10; // Delayed discovery @@ -1186,9 +1187,11 @@ bool Xdrv12(uint8_t function) // NewHAssDiscovery(); // } break; - +*/ case FUNC_MQTT_SUBSCRIBE: HassLwtSubscribe(hasslwt); + hass_mode = 0; // Discovery only if Settings.flag.hass_discovery is set + TasmotaGlobal.discovery_counter = (0 == Mqtt.initial_connection_state) ? 1 : 10; // Delayed discovery break; case FUNC_MQTT_DATA: result = HAssMqttLWT();