[SOLVED] Home assistant mqtt autodiscovery not working

Hi everyone. Thanks for the awesome forum.

I wanted to check if someone has some wisdom on the issue that has been killing me for a couple of days now T.T

My setup is the following:

  • Three zigbee temperature and humidity sensors
  • Zigbee2Mqtt
  • Mosquitto

I have been able to add the temperature readings as a sensor manually, but I am not able to make autodiscovery work, the mqtt broker shows nothing, not matter what I configure.

Here is a picture of the topics:

The sensors seem the be published properly, and for example, the content of the temperature config is:

{
  "availability": [
    {
      "topic": "zigbee2mqtt/bridge/state",
      "value_template": "{{ value_json.state }}"
    }
  ],
  "default_entity_id": "sensor.th_habitaculo_temperature",
  "device": {
    "configuration_url": "xxx.xxx.x.xxx:xxxx/#/device/0/0xa4c138c4bc834ff5/info",
    "hw_version": 0,
    "identifiers": [
      "zigbee2mqtt_0xa4c138c4bc834ff5"
    ],
    "manufacturer": "Zbeacon",
    "model": "Temperature and humidity sensor",
    "model_id": "TH01",
    "name": "th_habitaculo",
    "sw_version": "0122052017",
    "via_device": "zigbee2mqtt_bridge_0x00124b0038a9169b"
  },
  "device_class": "temperature",
  "enabled_by_default": true,
  "object_id": "th_habitaculo_temperature",
  "origin": {
    "name": "Zigbee2MQTT",
    "sw": "2.12.0",
    "url": "https://www.zigbee2mqtt.io"
  },
  "state_class": "measurement",
  "state_topic": "zigbee2mqtt/th_habitaculo",
  "unique_id": "0xa4c138c4bc834ff5_temperature_zigbee2mqtt",
  "unit_of_measurement": "°C",
  "value_template": "{{ value_json[\"temperature\"] }}"
}

and this is the payload of one of the th_ topics under zigbee2mqtt/

{
  "battery": 72,
  "device": {
    "applicationVersion": 147,
    "friendlyName": "th_habitacion",
    "hardwareVersion": 0,
    "ieeeAddr": "0xa4c138b887d9d961",
    "manufacturerID": 4742,
    "manufacturerName": "Zbeacon",
    "model": "TH01",
    "networkAddress": 28416,
    "powerSource": "Battery",
    "softwareBuildID": "0122052017",
    "stackVersion": 2,
    "type": "EndDevice",
    "zclVersion": 3
  },
  "humidity": 32.68,
  "linkquality": 61,
  "temperature": 27.64,
  "voltage": 2600
}

For some reason home assistant is not showing the sensors, I've read the mqtt-discovery page and everything seems alright, unless the object_id in <discovery_prefix>//[<node_id>/]<object_id>/config needs to be unique, in which case I'm screwed because the unique part is in the "component".

thank you all.

You have to put them in the place that HA is looking for them to be auto-discovered.
You can create entities manually to look in other places, but for auto if you have not changed HA's default you need to be dropping files in /homeassistant/{whatever your integration is}/{rest of your path you create}. This is clearly in the docs.

But isn't that precisely where it is?

The discovery topic needs to follow a specific format:

<discovery_prefix>/<component>/[<node_id>/]<object_id>/config

Which in my case is:

homeassistant/sensor/0xa4c138c4bc834ff5/temperature/config

Do you have the MQTT integration installed?

The MQTT integration connects Home Assistant to your Mosquitto MQTT Broker.

Yes, I've added the integration. I was able to add a sensor manually.

Also the configuration has the proper IP, user and password.

Hey! I hadn't checked the logs in the integration!! Stupid of me :frowning:

Error 'invalid url for dictionary value @ data['device']['configuration_url']' when processing MQTT discovery message topic: 'homeassistant/sensor/0xa4c138b887d9d961/temperature/config', message: '{'availability': [{'topic': 'zigbee2mqtt/bridge/state', 'value_template': '{{ value_json.state }}'}], 'default_entity_id': 'sensor.th_habitacion_temperature', 'device': {'configuration_url': '192.168.1.143:8099/#/device/0/0xa4c138b887d9d961/info', 'hw_version': 0, 'identifiers': ['zigbee2mqtt_0xa4c138b887d9d961'], 'manufacturer': 'Zbeacon', 'model': 'Temperature and humidity sensor', 'model_id': 'TH01', 'sw_version': '0122052017', 'via_device': 'zigbee2mqtt_bridge_0x00124b0038a9169b', 'name': 'th_habitacion'}, 'device_class': 'temperature', 'enabled_by_default': True, 'object_id': 'th_habitacion_temperature', 'origin': {'support_url': 'https://www.zigbee2mqtt.io', 'sw_version': '2.12.0', 'name': 'Zigbee2MQTT'}, 'state_class': 'measurement', 'state_topic': 'zigbee2mqtt/th_habitacion', 'unique_id': '0xa4c138b887d9d961_temperature_zigbee2mqtt', 'unit_of_measurement': '°C', 'value_template': '{{ value_json["temperature"] }}'}'

So it doesn't like the "configuration_url': '192.168.1.143:8099/#/device/0/0xa4c138b887d9d961/info" but now I have to find if I can fix this somehow -.-

In case anyone finds this. The issue was with the Zigbee2Mqtt interface configuration:


I added the http:// in front of the ip and now home assistant does not complain and the sensors appear. :smiley:

Right, because it's a Uniform Resource Locator (URL) which requires the scheme (protocol) to be specified (http, https, ftp, etc).

FWIW, I have always left that option blank and never encountered problems with Home Assistant discovering Zigbee devices via Zigbee2MQTT.