MQTT Device Discovery with 1 Json definition for DHT22 not working

Hello,
I am trying to define a DHT22 sensor (temperature & humidity) with 1 Json definition according to the example in the MQTT documentation.
So I am having 1 device (dht22_1) with 2 components (dht22_t and dht22_h) and the objective is to send 1 config message for both components (at least this is my understanding about the device based discovery scheme).

The config message is received and the config payload seems to be right. Also the state payload can be seen and is linked to the dht22_1 device.
However, no sensor value is really recognized and is shown up in the MQTT broker or as individual homeassistant sensor entity.

My config payload:

{
  "device": {
    "identifiers": "dht22_1",
    "name": "dht22_1c"
  },
  "origin": {
    "name": "cellar_1"
  },
  "components": {
    "dht22_t": {
      "platform": "sensor",
      "device_class": "temperature",
      "unit_of_measurement": "°C",
      "value_template": "{{value_json.temperature}}",
      "unique_id": "DHT22_t1"
    },
    "dht22_h": {
      "platform": "sensor",
      "device_class": "humidity",
      "unit_of_measurement": "%",
      "value_template": "{{value_json.humidity}}",
      "unique_id": "dht22_h1"
    }
  },
  "state_topic": "homeassistant/sensor/dht22_1/state"
}

My config topic: homeassistant/sensor/dht22_1/config

My state topic: homeassistant/sensor/dht22_1/state
with the payload of {“temperature”:19.8,“humidity”:45}

The only entity I do see is in the the homeassistant entity overview is a mqtt sensor:

Inside the mqtt debug session I find:
[homeassistant.components.mqtt.discovery] Pending discovery for (‘sensor’, ‘dht22_1’): deque() which means that the discovery is pending, but I don’t know why.
So, what I am doing wrong as this is almost identical to the example in the documentation?

Thanks for your help in advance.

Hello ebefra,

Troubleshooting MQTT? MQTT-Explorer can help you be successful!

If you have Add-ons available, try adding this Add-on repository to your Add-on list. GitHub - GollumDom/addon-repository.

With this you can see that the broker sees and likely find the bug.

Hi SG,
certainly I do have MQTT explorer installed and using it. Txs for the suggestion!

And I can see the messages and they all seems to be correct. But the error seems to be in the logic, not in the message format.
And although spending hours on it, I can’t see what is wrong.

So again to the folks out there:
I have the classical DHT sensor, which I want to treat with automatic discovery having the 2 components inside.
Objective: Send only 1 config message, sensing only 1 status message.

Can someone help?

Txs

Hello all, I found my error and copying the solution here in case someone is searching on the same:
The only change I had to do was replacing the “sensor” by “device” in the config & in the state topic & in the “state_topic” variable in the json config payload message.

So:

  • my config topic: homeassistant/device/dht22_1/config

  • my config payload (shortened as 95% same as above):
    {
    “device”: {
    “identifiers”: “dht22_1”,
    “name”: “dht22_1c”
    },
    “origin”: {
    “name”: “cellar_1”
    },
    “components”: {
    “dht22_t”: {

    },
    “dht22_h”: {

    }
    },
    “state_topic”: “homeassistant/device/dht22_1/state”
    }

  • my state topic: homeassistant/device/dht22_1/state

  • my state payload: {“temperature”:20.7,“humidity”:63.9}

Then the auto discovery worked like a charm and I got a new device named dht1_c in my homeassistant overview with 2 sensors grouped inside.