From c3e2c36b188b24d69589e71fca3fe2262e88440d Mon Sep 17 00:00:00 2001 From: nordeep Date: Fri, 16 Oct 2020 22:05:26 +0300 Subject: [PATCH] Update HomeAssistantDiscoveryClient.cpp --- lib/MQTT/HomeAssistantDiscoveryClient.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 +}