diff --git a/lib/MQTT/HomeAssistantDiscoveryClient.cpp b/lib/MQTT/HomeAssistantDiscoveryClient.cpp index b7445523..5687a184 100644 --- a/lib/MQTT/HomeAssistantDiscoveryClient.cpp +++ b/lib/MQTT/HomeAssistantDiscoveryClient.cpp @@ -35,11 +35,15 @@ void HomeAssistantDiscoveryClient::removeConfig(const BulbId& bulbId) { void HomeAssistantDiscoveryClient::addConfig(const char* alias, const BulbId& bulbId) { String topic = buildTopic(bulbId); DynamicJsonDocument config(1024); + + char uniqidBuffer[30]; + sprintf_P(uniqidBuffer, PSTR("%X-%s"), ESP.getChipId(), alias); config[F("schema")] = F("json"); config[F("name")] = alias; config[F("command_topic")] = mqttClient->bindTopicString(settings.mqttTopicPattern, bulbId); config[F("state_topic")] = mqttClient->bindTopicString(settings.mqttStateTopicPattern, bulbId); + config[F("uniq_id")] = mqttClient->bindTopicString(uniqidBuffer, bulbId); JsonObject deviceMetadata = config.createNestedObject(F("device")); deviceMetadata[F("manufacturer")] = F("esp8266_milight_hub"); @@ -170,4 +174,4 @@ void HomeAssistantDiscoveryClient::addNumberedEffects(JsonArray& effectList, uin for (uint8_t i = start; i <= end; ++i) { effectList.add(String(i)); } -} \ No newline at end of file +}