diff --git a/src/mqtt/hasp_mqtt_paho_async.cpp b/src/mqtt/hasp_mqtt_paho_async.cpp index 5c49c141..642c71e5 100644 --- a/src/mqtt/hasp_mqtt_paho_async.cpp +++ b/src/mqtt/hasp_mqtt_paho_async.cpp @@ -148,12 +148,14 @@ static void mqtt_message_cb(char* topic, char* payload, unsigned int length) dispatch_mtx.unlock(); return; +#ifdef HASP_USE_HA } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) { dispatch_current_state(); mqtt_ha_register_auto_discovery(); } return; +#endif } else { // Other topic diff --git a/src/mqtt/hasp_mqtt_paho_single.cpp b/src/mqtt/hasp_mqtt_paho_single.cpp index d65802d1..c5235a9b 100644 --- a/src/mqtt/hasp_mqtt_paho_single.cpp +++ b/src/mqtt/hasp_mqtt_paho_single.cpp @@ -143,12 +143,14 @@ static void mqtt_message_cb(char* topic, char* payload, unsigned int length) dispatch_topic_payload(topic, (const char*)payload); return; +#ifdef HASP_USE_HA } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) { dispatch_current_state(); mqtt_ha_register_auto_discovery(); } return; +#endif } else { // Other topic @@ -272,7 +274,9 @@ static void onConnect(void* context) mqtt_subscribe(mqtt_client, "hass/status"); /* Home Assistant auto-configuration */ +#ifdef HASP_USE_HA if(mqttHAautodiscover) mqtt_subscribe(mqtt_client, "homeassistant/status"); +#endif mqttPublish(TOPIC LWT_TOPIC, "online", 6, false); diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index 3fe89dff..fd681b42 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -167,12 +167,14 @@ static void mqtt_message_cb(char* topic, byte* payload, unsigned int length) dispatch_topic_payload(topic, (const char*)payload); return; +#ifdef HASP_USE_HA } else if(topic == strstr_P(topic, PSTR("homeassistant/status"))) { // HA discovery topic if(mqttHAautodiscover && !strcasecmp_P((char*)payload, PSTR("online"))) { mqtt_ha_register_auto_discovery(); // auto-discovery first dispatch_current_state(); // send the data } return; +#endif } else { // Other topic @@ -299,7 +301,9 @@ void mqttStart() mqttSubscribeTo(F("hass/status"), mqttClientId); /* Home Assistant auto-configuration */ +#ifdef HASP_USE_HA if(mqttHAautodiscover) mqttSubscribeTo(F("homeassistant/status"), mqttClientId); +#endif // Force any subscribed clients to toggle offline/online when we first connect to // make sure we get a full panel refresh at power on. Sending offline,