Temp/Humidity sensor autodiscovery

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

Moderator: leecollings

Post Reply
sundansx
Posts: 10
Joined: Tuesday 30 May 2017 8:16
Target OS: Windows
Domoticz version:
Contact:

Temp/Humidity sensor autodiscovery

Post by sundansx »

I am trying to prototype a humidity/temperature (just starting with a temperature) sensor on the mosquito_pub commandline using autodiscovery and am having some problems understanding the nomenclature. I did this:

Code: Select all

mosquitto_pub -r -h beeboxslim -p 1883 -t "homeassistant/sensor/123456/config" -m '{"name": "goveeGarden", "stat_t": "domoticz/sensor/123456/state", "unit_of_meas":"C", "uniq_id": "123456"}'
which showed this in the log:

Code: Select all

mqtt-autodisc:  discovered 123456/goveeGarden {unique_id: 123456}
At this point should I expect to see a new device in the device list with an ID of 123456? I do not see that in the device list

I tried to send an update to it

Code: Select all

mosquitto_pub -r -h beeboxslim -p 1883 -t "domoticz/in" -m '{"command":"udevice", "idx":123456, "nvalue":0, "svalue":"20"}'
and domoticz said:

Code: Select all

2022-04-14 00:19:20.739  Error: mqtt-sensors: unknown idx received! (idx 123456)
I have looked through a lot of stuff to find out how to form the autodiscover message and have not really gotten a concrete example/answer. Please help.
sundansx
Posts: 10
Joined: Tuesday 30 May 2017 8:16
Target OS: Windows
Domoticz version:
Contact:

Re: Temp/Humidity sensor autodiscovery

Post by sundansx »

I made some progress from this https://www.home-assistant.io/docs/mqtt/discovery/ using their examples. I was able to add a swtich using this example:
mosquitto_pub -r -h 127.0.0.1 -p 1883 -t "homeassistant/binary_sensor/garden/config" -m '{"name": "garden", "device_class": "motion", "state_topic": "homeassistant/binary_sensor/garden/state"}'
domoticz reported this:
2022-04-15 00:20:57.590 Status: mqtt-autodisc: discovered: 5509d77a-96d0-429d-849a-9581041ba518/garden (unique_id: 5509d77a-96d0-429d-849a-9581041ba518)

using the example below and trying to add a tempertaure sensor and domoticz did not add a new device:
mosquitto_pub -r -h 127.0.0.1 -p 1883 -t "homeassistant/sensor/sensorBedroomT/config" -m '{"name": "Temperature", "device_class": "temperature", "state_topic": "homeassistant/sensor/sensorBedroom/state", "unit_of_measurement": "°C", "value_template": "{{ value_json.temperature}}" }'

even though domoticz reported this:
2022-04-15 00:18:34.383 Status: mqtt-autodisc: discovered: 47aa0786-a6b1-4de4-89e2-b535c45388eb/Temperature (unique_id: 47aa0786-a6b1-4de4-89e2-b535c45388eb)

any idea why the temp sensor is not appearing? domoticz borken? I am using 2022.1 stable on windows. thanks for any help.
sundansx
Posts: 10
Joined: Tuesday 30 May 2017 8:16
Target OS: Windows
Domoticz version:
Contact:

Re: Temp/Humidity sensor autodiscovery

Post by sundansx »

..and one step back. The switch I created is not able to be controlled via MQTT or from the web page...it errors out when manuipulated from the web page and just does not do any thing with :

Code: Select all

mosquitto_pub -h 127.0.0.1 -p 1883 -t "homeassistant/binary_sensor/garden/state" -m ON
created as above with:

Code: Select all

mosquitto_pub -r -h 127.0.0.1 -p 1883 -t "homeassistant/binary_sensor/garden/config" -m '{"name": "garden", "device_class": "motion", "state_topic": "homeassistant/binary_sensor/garden/state"}'
anyone have any ideas here?
redswan
Posts: 15
Joined: Monday 23 October 2017 17:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11535
Contact:

Re: Temp/Humidity sensor autodiscovery

Post by redswan »

Hi,

I have just been going through exactly the same process as you Sundansx.

I've been trying to get working, so far without success, a Sonoff SNZB-02 temperature/humidity sensor paired to a Sonoff Zigbee 3.0 USB Dongle plus.

Like you all seems correct in MQTTexplorer and I see the same messages in Domoticz but no devices created.

As you, I also tried the examples; to the same effect. Switch created but impossible to change state.
Domoticz shows an error message : Error: MQTT: MQTT_Discovery: Invalid/Unhandled data received! (Topic: binary_sensor/garden/state, Message: OFF)

A side effect I noticed is that if you restart Domoticz a new switch device is created with a new ID!!

Did you manage to solve this problem and if so how?

Any help would be very much appreciated as I've been on this for days now and haven't got much hair left :?

Installation:

Domoticz 2022.1 build 14352
Mosquitto 2.0.14
Zigbee2mqtt 1.25.2

All installed in docker on Rpi3b with Bullseye.
redswan
Posts: 15
Joined: Monday 23 October 2017 17:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11535
Contact:

Re: Temp/Humidity sensor autodiscovery

Post by redswan »

Still trying to figure this out, nobody have an idea?

The config topic payload is :

Code: Select all

{"availability":[{"topic":"homeassistant/bridge/state","value_template":"{{ value_json.state }}"}],"device":{"identifiers":["zigbee2mqtt_0x00124b00251ca8fe"],"manufacturer":"SONOFF","model":"Temperature and humidity sensor (SNZB-02)","name":"Temp_Sensor_2"},"device_class":"temperature","enabled_by_default":true,"name":"Temp_Sensor_2_temperature","state_class":"measurement","state_topic":"homeassistant/Temp_Sensor_2","unique_id":"0x00124b00251ca8fe_temperature_homeassistant","unit_of_measurement":"°C","value_template":"{{ value_json.temperature }}"}
and the data payload from the sensor is :

Code: Select all

{"battery":100,"humidity":70.78,"linkquality":42,"temperature":24.7,"voltage":3200}
I have installed Homeassistant and these devices are detected correctly, so I guess the format is correct. It really looks like it's a problem with Domoticz :?

For the moment I'm using Homeassistant and an automation to forward the data via the JSON/API to the correct device in Domoticz. This works but it would be nice to get the data directly!!

Thanks,

Chris
redswan
Posts: 15
Joined: Monday 23 October 2017 17:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11535
Contact:

Re: SOLVED: Temp/Humidity sensor autodiscovery

Post by redswan »

It took me some time to get there but with the patient help of Gizmocuz here's the explanation:

Domoticz expects the autodiscovery topic to be published in the folder "homeassistant/....

and

the state payload in a folder like zwavejs2mqtt/... or zigbee2mqtt/... or tasmota/... or myhardware/...

The idea being to keep separate autodiscovery and state information.

So taking the HA examples previously used they should look like this:

Switch:
config:

Code: Select all

mosquitto_pub -r -h 127.0.0.1 -p 1883 -t homeassistant/binary_sensor/garden/config" -m '{"name": "garden", "device_class": "motion", "state_topic": "myhardware/binary_sensor/garden/state"}'
state:

Code: Select all

mosquitto_pub -h 127.0.0.1 -p 1883 -t "myhardware/binary_sensor/garden/state" -m ON
same thing for the temperature and humidity.

If you want Domoticz to create a single temp/humidity device then you need to add a device descriptor to of the the config payloads as shown in the HA example, e.g.

"device": { "identifiers": [ "myhardware_1234" ], "manufacturer": "ME", "model": "Temperature and humidity sensor", "name": "Bedroom" },

If you don't add this then Domoticz will create independant temperature and humidity devices.

You should also add a "unique_id" field otherwise at each restart Domoticz (may) think this is a new device!

Domoticz says these sensors are discovered but treats them differently, the switch device is created immediately but the temperature/humidity devices only on first reception of the state information!

I was confused at first because I expected Ha and Domoticz to react in the same way, they don't. Using the HA examples as is in HA works as expected but not in Domoticz where the interpretation/representation is different.

Hope this helps someone.

Chris aka Redswan
blueberryPie
Posts: 18
Joined: Sunday 19 November 2017 20:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Temp/Humidity sensor autodiscovery

Post by blueberryPie »

Domoticz 2024.4 MQTT Auto Discover not processing the jinja2 value_template.

I have the following MQTT AD topic:

Code: Select all

domoticz/sensor/openevse/temperature/config
With the value:

Code: Select all

{
  "value_template": "{{ float(value) / 10.0 }}",
  "unit_of_measurement": "°C",
  "state_class": "measurement",
  "device_class": "temperature",
  "state_topic": "openevse/openevse/temp",
  "device": {
    "identifiers": [
      "openevse_mqtt"
    ],
    "name": "OpenEVSE"
  },
  "name": "OpenEVSE Temperature",
  "unique_id": "openevse_temperature"
}
With state_topic:

Code: Select all

openevse/openevse/temp
Value:

Code: Select all

125
Which is a raw value. Shown as
temp = 125
in MQTT Explorer. Which is 12.5°C.

Domoticz creates the temperature device and populates it with the value however it is the raw value (125) not the value / 10 (12.5).
I have tried various variations of the value_template:

Code: Select all

  "value_template": "{{ value | multiply(0.1) | float }}",
  "value_template": "{{ float(value) / 10.0 }}",
  "value_template": "{{ value | float / 10 }}",
  "value_template": "{{ value | multiply(0.1) }}",
  "value_template": "{{ int(value) | float / 10.0 }}",
  "value_template": "{{ value | int / 10 }}",
None of these work and Domoticz will not divide the value by 10.
I also tried:

Code: Select all

"value_template": "{{ 32 }}",

Domoticz still just populates the value of the temperature sensor with the value from the state_topic so clearly it is just ignoring the value_template completely.

If I change the °C to °F Domoticz converts the value from F to F instead of from C to F so It is reading some of the configuration in the AD. And of course it is creating the device and populating it with the state_topic value. It is just not processing the value_template.

Anyone have any idea why this is not working and how to get it working.

Thanks.
User avatar
waltervl
Posts: 5363
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Temp/Humidity sensor autodiscovery

Post by waltervl »

Domoticz MQTT AD cannot handle value topics with logic. So you will have to get OpenEvse send a temperate as a normal temperature value.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests