MQTT Audo-discovery

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

Moderator: leecollings

sciurius
Posts: 55
Joined: Monday 26 July 2021 16:39
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: NL
Contact:

MQTT Audo-discovery

Post by sciurius »

I am a bit confused by the information I can find on MQTT Auto-discovery. If I understand correctly, autodiscovery is now natively supported by Domoticz. However I can't seem to get it going.

I tries to manually add a device using some example code I found somewhere.

Code: Select all

mosquitto_pub -t "homeassistant/binary_sensor/garden/config" -m '{"name": "garden", "device_class": "motion", "state_topic": "homeassistant/binary_sensor/garden/state"}'
According to MQTTExplorer the message is correctly received by the broker, but Domoticz doesn't respond.

Do I need to enable the autodetect in Domoticz first?
User avatar
waltervl
Posts: 5847
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: MQTT Audo-discovery

Post by waltervl »

Best to check this page https://www.domoticz.com/wiki/MQTT
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
sciurius
Posts: 55
Joined: Monday 26 July 2021 16:39
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: NL
Contact:

Re: MQTT Audo-discovery

Post by sciurius »

siklosi wrote: Thursday 02 December 2021 21:08 Auto Discovery Prefix should be homeassistant. But this is only in new beta releases.
Thanks. Apparently auto-discovery is not in stable 2021.1.

Waiting for the next version, then...
User avatar
waltervl
Posts: 5847
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: MQTT Audo-discovery

Post by waltervl »

siklosi wrote: Friday 03 December 2021 10:09 When we are on the topic... what is correct procedure to reinitialize autodiscovery from z2m or domoticz in case when device was added to z2m but accept new hardware devices on domoticz was not enabled (aside from enabling accept new hardware devices :) )?
I would expect a trigger from the device (or perhaps some action in Z2M UI) would trigger a device creation in Domoticz.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 5847
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: MQTT Audo-discovery

Post by waltervl »

Perhaps a restart of the Domoticz MQTT gateway by clicking on the UPDATE button when selecting the MQTT Hardware from menu Setup - Hardware?
If you do not change anything on the hardware configuration the hardware will just restart after clicking on Update (not ADD! ;) )
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
heggink
Posts: 979
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: MQTT Audo-discovery

Post by heggink »

siklosi wrote: Friday 03 December 2021 10:09 When we are on the topic... what is correct procedure to reinitialize autodiscovery from z2m or domoticz in case when device was added to z2m but accept new hardware devices on domoticz was not enabled (aside from enabling accept new hardware devices :) )?
This depends on your setitngs in zigbee/zwave2mqtt: in both cases you can specify whether to retain autodiscovery messages. If you do so, the last autodiscovery message is always kept bu the broker. Whenever you restart the hardware in domoticz, it will reload these and create missing devices if you accept new devices. The downside is that deleting devices requires you to manually delete these autodiscovery messages as well as, otherwise, already deleted devices will continue to be recreated.

You can also NOT retain these messages in which case restarting zwavejs/zigbee2mqtt will resend these autodiscovery messages on start. Typically, saving settings in zigbee2mqtt also does that.

I run both on my pi4 where I created a udev rule to restart the docker instance whenever the controller is removed/added. My aeotec gen5 stick is the one that does not work well with a pi4 reboot so I need to put a hub in between that hub occasionally disconnects/reconnects causing the docker instance to get stuck. The udev rule circumvents that by cathing the connect and restarting the docker instance when it does. It also then re-sends the autodiscovery messages.

So, multiple ways ;-).
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
User avatar
waltervl
Posts: 5847
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: MQTT Audo-discovery

Post by waltervl »

heggink wrote: Friday 03 December 2021 11:58
siklosi wrote: Friday 03 December 2021 10:09 When we are on the topic... what is correct procedure to reinitialize autodiscovery from z2m or domoticz in case when device was added to z2m but accept new hardware devices on domoticz was not enabled (aside from enabling accept new hardware devices :) )?
This depends on your setitngs in zigbee/zwave2mqtt: in both cases you can specify whether to retain autodiscovery messages. If you do so, the last autodiscovery message is always kept bu the broker. Whenever you restart the hardware in domoticz, it will reload these and create missing devices if you accept new devices. The downside is that deleting devices requires you to manually delete these autodiscovery messages as well as, otherwise, already deleted devices will continue to be recreated.

You can also NOT retain these messages in which case restarting zwavejs/zigbee2mqtt will resend these autodiscovery messages on start. Typically, saving settings in zigbee2mqtt also does that.
something to put in a wiki, best on Zigbee2MQTT page (https://www.domoticz.com/wiki/Zigbee2MQ ... todiscover) and perhaps a new to be created ZwaveJS2MQTT page....
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 5847
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: MQTT Audo-discovery

Post by waltervl »

waltervl wrote: Friday 03 December 2021 12:05
heggink wrote: Friday 03 December 2021 11:58
siklosi wrote: Friday 03 December 2021 10:09 When we are on the topic... what is correct procedure to reinitialize autodiscovery from z2m or domoticz in case when device was added to z2m but accept new hardware devices on domoticz was not enabled (aside from enabling accept new hardware devices :) )?
This depends on your setitngs in zigbee/zwave2mqtt: in both cases you can specify whether to retain autodiscovery messages. If you do so, the last autodiscovery message is always kept bu the broker. Whenever you restart the hardware in domoticz, it will reload these and create missing devices if you accept new devices. The downside is that deleting devices requires you to manually delete these autodiscovery messages as well as, otherwise, already deleted devices will continue to be recreated.

You can also NOT retain these messages in which case restarting zwavejs/zigbee2mqtt will resend these autodiscovery messages on start. Typically, saving settings in zigbee2mqtt also does that.
something to put in a wiki, best on Zigbee2MQTT page (https://www.domoticz.com/wiki/Zigbee2MQ ... todiscover) and perhaps a new to be created ZwaveJS2MQTT page....
https://www.domoticz.com/wiki/ZwaveJS2MQTT wiki page created and ready to be modified by the community ;)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
marcojpolet
Posts: 63
Joined: Thursday 04 February 2016 20:18
Target OS: -
Domoticz version:
Contact:

Re: MQTT Audo-discovery

Post by marcojpolet »

What a coincidence, I',m also trying out the auto-discovery thing of MQTT integrated in Domoticz. It is working, but when the device sending the config item restarts, new devices are created. This is what I send:
homeassistant/switch/esp_blinds/Mqnas/config/': { "name": "Blind_1_Mqnas", "cmd_t" : "~/set", "stat_t" : "~/state" }
homeassistant/switch/esp_blinds/Mqnas/config/': { "name": "Blind_2_Mqnas", "cmd_t" : "~/set", "stat_t" : "~/state" }

The devices are created (2 switches named Blind_X_Mqnas), but the second start, a second pair of devices is created. They all have different ID values, but these seem to be auto-generated, not sent by me...

Any idea how to prevent this? Or is this just because it's still in beta?

Regards,
Marco
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: MQTT Audo-discovery

Post by jvdz »

Marco,

Just add an uniq_id field to the payload as that is used for recognizing existing devices:

Code: Select all

homeassistant/switch/esp_blinds/Mqnas/config/': { "name": "Blind_1_Mqnas", "cmd_t" : "~/set", "stat_t" : "~/state", "uniq_id":"your_unique_key_for_this_device" }
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
marcojpolet
Posts: 63
Joined: Thursday 04 February 2016 20:18
Target OS: -
Domoticz version:
Contact:

Re: MQTT Audo-discovery

Post by marcojpolet »

Thanks Jos! That was it! I already thought about the unique_id, but thought it needed to be in the /xx/xx/ path, not as an json item! It's working now!
marcojpolet
Posts: 63
Joined: Thursday 04 February 2016 20:18
Target OS: -
Domoticz version:
Contact:

Re: MQTT Audo-discovery

Post by marcojpolet »

Hi all,

I know the Domoticz Auto-discovery is Beta, but is it working at least to a basic level? I can (as seen above) now succesfully add switches automatically, but when I try to turn them on from Domoticz, I get the following error:
Mosq: MQTT_Discovery: Invalid/Unhandled data received! (Topic: switch/Blind_1_Mqnas/set, Message: ON)

Mosq: my MQTT server
This is now my config topic:
homeassistant/switch/Blind_1_Mqnas/config': { "name":"Blind_1_Mqnas", "uniq_id":"Blind_1_Mqnas", "cmd_t":"homeassistant/switch/Blind_1_Mqnas/set", "stat_t":"homeassistant/switch/Blind_1_Mqnas/state" }

Any clue what I'm doing wrong?

Regards,
Marco
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: MQTT Audo-discovery

Post by jvdz »

Think the issue here is that you are using the HA discovery topic to send a status update which isn't supported.
So change your t_cmd to something else than homeassistant/*
eg:

Code: Select all

Topic: homeassistant/switch/Blind_1_Mqnas/config   
Payload:  { "name":"Blind_1_Mqnas", "uniq_id":"Blind_1_Mqnas", "cmd_t":"xx/switch/Blind_1_Mqnas/set", "stat_t":"xx/switch/Blind_1_Mqnas/state" } 
And send the status update to Domoticz:

Code: Select all

Topic: xx/switch/Blind_1_Mqnas/state   
Payload: ON
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
marcojpolet
Posts: 63
Joined: Thursday 04 February 2016 20:18
Target OS: -
Domoticz version:
Contact:

Re: MQTT Audo-discovery

Post by marcojpolet »

Thanks again Jos! That was it!!
rron
Posts: 247
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: MQTT Audo-discovery

Post by rron »

Hello Jos,

I' have the same problem but I don understand this solution. Can you explane where I change this?
Ronald

jvdz wrote: Friday 10 December 2021 13:49 Think the issue here is that you are using the HA discovery topic to send a status update which isn't supported.
So change your t_cmd to something else than homeassistant/*
eg:

Code: Select all

Topic: homeassistant/switch/Blind_1_Mqnas/config   
Payload:  { "name":"Blind_1_Mqnas", "uniq_id":"Blind_1_Mqnas", "cmd_t":"xx/switch/Blind_1_Mqnas/set", "stat_t":"xx/switch/Blind_1_Mqnas/state" } 
And send the status update to Domoticz:

Code: Select all

Topic: xx/switch/Blind_1_Mqnas/state   
Payload: ON
Jos
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: MQTT Audo-discovery

Post by jvdz »

rron wrote: Monday 20 December 2021 15:32 Hello Jos,

I' have the same problem but I don understand this solution. Can you explane where I change this?
Ronald
Well, when you have the same issue, it means you are generating the CONFIG MQTT messages yourself, so that is where you need to change them. ;)
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
rron
Posts: 247
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: MQTT Audo-discovery

Post by rron »

Well I think itś the same. My error looks like this:

Code: Select all

 2021-12-20 14:26:09.637 Error: MQTT: MQTT_Discovery: Invalid/Unhandled data received! (Topic: 18/38/0/currentValue, Message: {"time":1640003037730,"value":99,"nodeName":"Wasmachine","nodeLocation":"Zolder"})
2021-12-20 14:26:09.637 Error: MQTT: MQTT_Discovery: Something other then 'config' received on discovery topic! (23/38/1/currentValue/{"time":1639954365610,"value":0,"nodeName":"Kamer dimmer","nodeLocation":"Huiskamer"})!
2021-12-20 14:26:09.637 Error: MQTT: MQTT_Discovery: Invalid/Unhandled data received! (Topic: 23/38/1/currentValue, Message: {"time":1639954365610,"value":0,"nodeName":"Kamer dimmer","nodeLocation":"Huiskamer"})
2021-12-20 14:26:09.738 Error: MQTT: MQTT_Discovery: Something other then 'config' received on discovery topic! (23/38/2/currentValue/{"time":1639821438142,"value":99,"nodeName":"Kamer dimmer","nodeLocation":"Huiskamer"})!
2021-12-20 14:26:09.738 Error: MQTT: MQTT_Discovery: Invalid/Unhandled data received! (Topic: 23/38/2/currentValue, Message: {"time":1639821438142,"value":99,"nodeName":"Kamer dimmer","nodeLocation":"Huiskamer"}) 
jvdz wrote: Monday 20 December 2021 15:34
rron wrote: Monday 20 December 2021 15:32 Hello Jos,

I' have the same problem but I don understand this solution. Can you explane where I change this?
Ronald
Well, when you have the same issue, it means you are generating the CONFIG MQTT messages yourself, so that is where you need to change them. ;)
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: MQTT Audo-discovery

Post by jvdz »

rron wrote: Monday 20 December 2021 15:41 Well I think itś the same. My error looks like this:

Code: Select all

 2021-12-20 14:26:09.637 Error: MQTT: MQTT_Discovery: Invalid/Unhandled data received! (Topic: 18/38/0/currentValue, Message: {"time":1640003037730,"value":99,"nodeName":"Wasmachine","nodeLocation":"Zolder"})
2021-12-20 14:26:09.637 Error: MQTT: MQTT_Discovery: Something other then 'config' received on discovery topic! (23/38/1/currentValue/{"time":1639954365610,"value":0,"nodeName":"Kamer dimmer","nodeLocation":"Huiskamer"})!
2021-12-20 14:26:09.637 Error: MQTT: MQTT_Discovery: Invalid/Unhandled data received! (Topic: 23/38/1/currentValue, Message: {"time":1639954365610,"value":0,"nodeName":"Kamer dimmer","nodeLocation":"Huiskamer"})
2021-12-20 14:26:09.738 Error: MQTT: MQTT_Discovery: Something other then 'config' received on discovery topic! (23/38/2/currentValue/{"time":1639821438142,"value":99,"nodeName":"Kamer dimmer","nodeLocation":"Huiskamer"})!
2021-12-20 14:26:09.738 Error: MQTT: MQTT_Discovery: Invalid/Unhandled data received! (Topic: 23/38/2/currentValue, Message: {"time":1639821438142,"value":99,"nodeName":"Kamer dimmer","nodeLocation":"Huiskamer"}) 
No this looks different. You are getting updates for discovered devices that cause an error.
Can you share the CONFIG MQTT message for these devices so I can check?
Also: What is your MQTT discovery topic in Domoticz?
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
rron
Posts: 247
Joined: Sunday 30 March 2014 15:24
Target OS: Linux
Domoticz version: Beta
Location: Waterland
Contact:

Re: MQTT Audo-discovery

Post by rron »

jvdz wrote: Monday 20 December 2021 16:33
rron wrote: Monday 20 December 2021 15:41 Well I think itś the same. My error looks like this:

Code: Select all

 2021-12-20 14:26:09.637 Error: MQTT: MQTT_Discovery: Invalid/Unhandled data received! (Topic: 18/38/0/currentValue, Message: {"time":1640003037730,"value":99,"nodeName":"Wasmachine","nodeLocation":"Zolder"})
2021-12-20 14:26:09.637 Error: MQTT: MQTT_Discovery: Something other then 'config' received on discovery topic! (23/38/1/currentValue/{"time":1639954365610,"value":0,"nodeName":"Kamer dimmer","nodeLocation":"Huiskamer"})!
2021-12-20 14:26:09.637 Error: MQTT: MQTT_Discovery: Invalid/Unhandled data received! (Topic: 23/38/1/currentValue, Message: {"time":1639954365610,"value":0,"nodeName":"Kamer dimmer","nodeLocation":"Huiskamer"})
2021-12-20 14:26:09.738 Error: MQTT: MQTT_Discovery: Something other then 'config' received on discovery topic! (23/38/2/currentValue/{"time":1639821438142,"value":99,"nodeName":"Kamer dimmer","nodeLocation":"Huiskamer"})!
2021-12-20 14:26:09.738 Error: MQTT: MQTT_Discovery: Invalid/Unhandled data received! (Topic: 23/38/2/currentValue, Message: {"time":1639821438142,"value":99,"nodeName":"Kamer dimmer","nodeLocation":"Huiskamer"}) 
No this looks different. You are getting updates for discovered devices that cause an error.
Can you share the CONFIG MQTT message for these devices so I can check?
Also: What is your MQTT discovery topic in Domoticz?
You have to help me out, just started this. You are meaning this?

Image
Schermafdruk van 2021-12-20 17-20-51.png
Schermafdruk van 2021-12-20 17-20-51.png (130.03 KiB) Viewed 5957 times
Attachments
Schermafdruk van 2021-12-20 17-25-49.png
Schermafdruk van 2021-12-20 17-25-49.png (202.81 KiB) Viewed 5956 times
Rpi, RFXcom, klikaan klikuit switch,thermosmart, z-wave, espeasy, smartevse
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: MQTT Audo-discovery

Post by jvdz »

You need to set the prefix the same at both sides, so change the domoticz prefix in ZWAVEJS2MQTT to homeassistant as well when that is what you have defined in domoticz/mqtt.
That topic prefix is used to exchange the device CONFIG topics & payload for auto discovery!
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest