Page 1 of 1
MQTT AD device name creation
Posted: Friday 06 October 2023 14:26
by Kedi
I have a test system with MQTT AD installed.
It used to discover devices with there name as in Zigbee2MQTT Friendly name.
I reinstalled it, and now that name look the same as the ID.
Below the config of 1 of my devices.
Topic
Code: Select all
homeassistant/light/0x8cf681fffef4ed16/light/config
Value
Code: Select all
{"availability":[{"topic":"zigbee2mqtt/bridge/state"}],"brightness":true,"brightness_scale":254,"color_mode":true,"command_topic":"zigbee2mqtt/Overloopplafondlamp/set","device":{"identifiers":["zigbee2mqtt_0x8cf681fffef4ed16"],"manufacturer":"Lidl","model":"Livarno Lux E27 bulb RGB (HG07834C)","name":"Overloop plafondlamp"},"effect":true,"effect_list":["blink","breathe","okay","channel_change","finish_effect","stop_effect"],"json_attributes_topic":"zigbee2mqtt/Overloopplafondlamp","max_mireds":500,"min_mireds":153,"name":null,"object_id":"overloop_plafondlamp","origin":{"name":"Zigbee2MQTT","sw":"1.33.0-dev","url":"https://www.zigbee2mqtt.io"},"schema":"json","state_topic":"zigbee2mqtt/Overloopplafondlamp","supported_color_modes":["xy","color_temp"],"unique_id":"0x8cf681fffef4ed16_light_zigbee2mqtt"}
To me it looks like the "name" is on the right place e.g. [device][name]
Is there anything I do wrong or is that change intended?
Re: MQTT AD device name creation
Posted: Friday 06 October 2023 14:46
by mgugu
IMO, "name", which appears in domoticz device, should be at the upper main level, not at "device" level.
Re: MQTT AD device name creation
Posted: Friday 06 October 2023 15:12
by Kedi
I looked into the Source, but I am not a C++ programmer.
On lines 669 and 670
Code: Select all
//Yes it's optional... but this should be required.. wierd
root["name"] = sensor_unique_id;
Here the root["name"] get filled if it was empty.
On lines 717 and 718
Code: Select all
if (!root["device"]["name"].empty())
pDevice->name = root["device"]["name"].asString();
The devicename gets filled from root["device"]["name"]
So I am confused. I Think I did not change anything in zigbee2mqtt, but I thought that the friendly name was also in the topic.
Re: MQTT AD device name creation
Posted: Sunday 08 October 2023 10:16
by Kedi
Found my solution by making this change in MQTTAutoDiscover.cpp
Code: Select all
// pSensor->name = root["name"].asString();
pSensor->name = root["device"]["name"].asString();
I don't think it is the right way, but it did the trick.
For me at least was this a solution.
I hope that someone can make a 'valid' change in the source.
If root["device"]["name"] is present and at root level there is no name then this one is used.
Because now if at root there is no name it is prefilled with sensor_unique_id while there is a name present in root["device"]
Re: MQTT AD device name creation
Posted: Sunday 08 October 2023 14:14
by gizmocuz
Made a patch for this in beta 15589....
Still strange that name=null ?
Re: MQTT AD device name creation
Posted: Sunday 08 October 2023 15:27
by Kedi
Tnx. Love it. The only problem is that devices with the same name are created.
If it could be enhanced by the device charistics like Volt, Watt, etc...
Then you have unique devices names and can see what the device will show.
A lot of devices in my latest zigbee2mqtt have name=null
I don't know why, because it does not make sense.
Re: MQTT AD device name creation
Posted: Sunday 08 October 2023 16:40
by Kedi
object_id might be a good idea to add to the device name.
I think it will be unique and the user has a good idea what the device is.
I tried it and it looks good.

Re: MQTT AD device name creation
Posted: Monday 09 October 2023 7:42
by gizmocuz
I'm sorry, I had to revert my patch as it was indeed creating devices with the same name.
Not sure why this patch was needed as on my system I have unique names
Looking at the object ID, I have some devices that has the same name as the object_id, giving it double names.
As MQTT-AD is now implemented for quite some time, and this is the first time I received this request, I guess for the majority of users it already works as it is.
Re: MQTT AD device name creation
Posted: Monday 09 October 2023 10:50
by Kedi
In my test environment I had the same experiance in the past that devices were discovered by name and something extra.
But I 'reinstalled' MQTT-AD on test env. and found out that the discovery worked different conc. the names of the devices.
Hence my request for a solution.
Now I compile it once with the object_id extra. If everything is discovered I switch back to the default domoticz executable.
Still have to figure out what was changed. I suspect in zigbee2mqtt because name=null on some devices.
Re: MQTT AD device name creation
Posted: Monday 09 October 2023 12:39
by Kedi
Found the place where the name: null was introduced (2 month ago) in zigbee2mqtt.
Now looking for a solution.
Re: MQTT AD device name creation
Posted: Monday 09 October 2023 14:53
by Kedi
Still I get duplicate names.
All my thermostats have a "Holiday start stop" because they have no prefix. And there are more devices without a prefix, like "Power outage count", "Child lock" and many others. So the reverted solution still has duplicated device names.