mqtt autodiscovery programmers guide

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

Moderator: leecollings

akamming
Posts: 386
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: mqtt autodiscovery programmers guide

Post by akamming »

mgugu wrote: Monday 26 December 2022 10:42 I also needed such device. The best I found for 0-100 numbers is to setup a light with only brightness : "brightness_state_topic". No need to specify a device class
I tried, but both HA en Domoticz give me errors if i don't specify a command topic.

Do you have a sample discovery message?
mgugu
Posts: 220
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: mqtt autodiscovery programmers guide

Post by mgugu »

akamming wrote: Saturday 04 February 2023 10:47 I tried, but both HA en Domoticz give me errors if i don't specify a command topic.
Do you have a sample discovery message?
The cmd topic is mandatory for non sensor devices. You can set it with a dummy value if not used.
For pure sensor, appearaing in domoticz utilities, I use that:

Code: Select all

topic_config : `<autodiscovery prefix>/sensor/.../config`
payload_config :
 {
    "~": `<update prefix>/../..`,
    "name": `<name in domoticz>`,
    "device_class": "power_factor",
    "unit_of_measurement": "%",
    "stat_t": "~/state",
    "unique_id": `<unique id>`
}
I your case you may need a value template directive:

Code: Select all

"value_template": "{{ value_json.value }}"
You can put other unit_of_measurement.
Many other device classes are available in HA but not all are implemented in domoticz.
akamming
Posts: 386
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: mqtt autodiscovery programmers guide

Post by akamming »

mgugu wrote: Saturday 04 February 2023 13:09
akamming wrote: Saturday 04 February 2023 10:47 I tried, but both HA en Domoticz give me errors if i don't specify a command topic.
Do you have a sample discovery message?
The cmd topic is mandatory for non sensor devices. You can set it with a dummy value if not used.
For pure sensor, appearaing in domoticz utilities, I use that:

Code: Select all

topic_config : `<autodiscovery prefix>/sensor/.../config`
payload_config :
 {
    "~": `<update prefix>/../..`,
    "name": `<name in domoticz>`,
    "device_class": "power_factor",
    "unit_of_measurement": "%",
    "stat_t": "~/state",
    "unique_id": `<unique id>`
}
I your case you may need a value template directive:

Code: Select all

"value_template": "{{ value_json.value }}"
You can put other unit_of_measurement.
Many other device classes are available in HA but not all are implemented in domoticz.
that's clear, but i responded to your statement here:
mgugu wrote: Monday 26 December 2022 10:42 I also needed such device. The best I found for 0-100 numbers is to setup a light with only brightness : "brightness_state_topic". No need to specify a device class
so what's the discovery message for that one? the goal is to have a sensor without unit of measurement.
mcipjvw
Posts: 1
Joined: Friday 26 May 2023 15:54
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: mqtt autodiscovery programmers guide

Post by mcipjvw »

akamming wrote: Tuesday 06 December 2022 20:34
waltervl wrote: Tuesday 06 December 2022 16:56 I believe this can be solved by setting retained mqtt messages on. Downside is that after deleting of the device and not deleting the retained mqtt message you get the deleted device back in Domoticz :)
The ha docs specifically State not to use retained mesaages for this Reason. Any other suggestions?

UPDATE: The HA docs seem to contradict themselves. Now also found this link: , stating
Retain: The -r switch is added to retain the configuration topic in the broker. Without this, the sensor will not be available after Home Assistant restarts.
where i read somewhere else this is bad practive (if you delete a device it will be rediscovered). Anyway not happy with it.

I will do some testing, see what works better: Retained messages or periodically publishing the discovery messages.
Hi! Interesting. Seems that I have the same problem: the need of configuring all devices again after startup the raspberry. Did you find a clean solution for this? Looking forward for your findings! Grtz Martin
akamming
Posts: 386
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: mqtt autodiscovery programmers guide

Post by akamming »

mcipjvw wrote: Friday 26 May 2023 16:43
akamming wrote: Tuesday 06 December 2022 20:34
waltervl wrote: Tuesday 06 December 2022 16:56 I believe this can be solved by setting retained mqtt messages on. Downside is that after deleting of the device and not deleting the retained mqtt message you get the deleted device back in Domoticz :)
The ha docs specifically State not to use retained mesaages for this Reason. Any other suggestions?

UPDATE: The HA docs seem to contradict themselves. Now also found this link: , stating
Retain: The -r switch is added to retain the configuration topic in the broker. Without this, the sensor will not be available after Home Assistant restarts.
where i read somewhere else this is bad practive (if you delete a device it will be rediscovered). Anyway not happy with it.

I will do some testing, see what works better: Retained messages or periodically publishing the discovery messages.
Hi! Interesting. Seems that I have the same problem: the need of configuring all devices again after startup the raspberry. Did you find a clean solution for this? Looking forward for your findings! Grtz Martin
i did not find a clean solutions.

My workaroudn is that All my devices now sent persistent messages.

The pro is: Device is still there when i restart domoticz. The con is: When i delete a device i have to manually remove the persistent message from the mosquitto queue to prevent domoticz rediscovering ghost devices...
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest