diff --git a/src/mqtt/hasp_mqtt_pubsubclient.cpp b/src/mqtt/hasp_mqtt_pubsubclient.cpp index a485721b..3fe89dff 100644 --- a/src/mqtt/hasp_mqtt_pubsubclient.cpp +++ b/src/mqtt/hasp_mqtt_pubsubclient.cpp @@ -169,8 +169,8 @@ static void mqtt_message_cb(char* topic, byte* payload, unsigned int length) } 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(); + mqtt_ha_register_auto_discovery(); // auto-discovery first + dispatch_current_state(); // send the data } return;