MQTT AD device name creation

For devices supporting the Auto Discovery feature. Like ZWaveJS2MQTT, Zigbee2MQTT.

Moderator: leecollings

Post Reply
Kedi
Posts: 577
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

MQTT AD device name creation

Post 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?
Logic will get you from A to B. Imagination will take you everywhere.
mgugu
Posts: 220
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: MQTT AD device name creation

Post by mgugu »

IMO, "name", which appears in domoticz device, should be at the upper main level, not at "device" level.
Kedi
Posts: 577
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: MQTT AD device name creation

Post 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.
Logic will get you from A to B. Imagination will take you everywhere.
Kedi
Posts: 577
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: MQTT AD device name creation

Post 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"]
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
gizmocuz
Posts: 2552
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: MQTT AD device name creation

Post by gizmocuz »

Made a patch for this in beta 15589....
Still strange that name=null ?
Quality outlives Quantity!
Kedi
Posts: 577
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: MQTT AD device name creation

Post 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.
Logic will get you from A to B. Imagination will take you everywhere.
Kedi
Posts: 577
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: MQTT AD device name creation

Post 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. :)
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
gizmocuz
Posts: 2552
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: MQTT AD device name creation

Post 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.
Quality outlives Quantity!
Kedi
Posts: 577
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: MQTT AD device name creation

Post 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.
Logic will get you from A to B. Imagination will take you everywhere.
Kedi
Posts: 577
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: MQTT AD device name creation

Post by Kedi »

Found the place where the name: null was introduced (2 month ago) in zigbee2mqtt.
Now looking for a solution.
Logic will get you from A to B. Imagination will take you everywhere.
Kedi
Posts: 577
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: MQTT AD device name creation

Post 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.
Logic will get you from A to B. Imagination will take you everywhere.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest