Page 2 of 2

Re: mqtt autodiscovery programmers guide

Posted: Saturday 04 February 2023 10:47
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?

Re: mqtt autodiscovery programmers guide

Posted: Saturday 04 February 2023 13:09
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.

Re: mqtt autodiscovery programmers guide

Posted: Saturday 04 February 2023 19:37
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.

Re: mqtt autodiscovery programmers guide

Posted: Friday 26 May 2023 16:43
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

Re: mqtt autodiscovery programmers guide

Posted: Friday 26 May 2023 21:22
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...