MQTT Discorvery Not Working - What Am I Missing?

Hello

I have been trying to get MQTT Discovery to work but to no avail.

I have a process (pi zero attached to my UPS) that sends MQTT messages to my MQTT server (not the add on, running EMQX on a seperate device). I started with this Sources + Config: https://github.com/ned-kelly/docker-voltronic-homeassistant

I have tested that Home Assistant can read the messages using the test facilities in the intergration:
image

The json looks well formed with the correct required keys:

{
    "name": "main_ups_Battery_float_voltage",
    "unit_of_measurement": "V",
    "state_topic": "homeassistant/sensor/main_ups_Battery_float_voltage/state",
    "icon": "mdi:current-dc",
    "unique_id": "main_ups_Battery_float_voltage"
}

I have also checked that the “add new entities” is enabled as well as Discovery. The topic set to “homeassistant” and it matches the topic being sent.

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2023.3.6",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.10.10",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Africa/Johannesburg",
    "os_name": "Linux",
    "os_version": "5.15.90",
    "supervisor": "2023.03.3",
    "host_os": "Home Assistant OS 9.5",
    "docker_version": "20.10.22",
    "chassis": "vm",
    "run_as_root": true
  },
  "integration_manifest": {
    "domain": "mqtt",
    "name": "MQTT",
    "codeowners": [
      "@emontnemery",
      "@jbouwh"
    ],
    "config_flow": true,
    "dependencies": [
      "file_upload",
      "http"
    ],
    "documentation": "https://www.home-assistant.io/integrations/mqtt",
    "iot_class": "local_push",
    "quality_scale": "gold",
    "requirements": [
      "paho-mqtt==1.6.1"
    ],
    "is_built_in": true
  },
  "data": {
    "connected": true,
    "mqtt_config": {
      "birth_message": {
        "topic": "homeassistant/status",
        "payload": "online",
        "qos": 0,
        "retain": false
      },
      "discovery": true,
      "discovery_prefix": "homeassistant",
      "port": 1883,
      "protocol": "3.1.1",
      "tls_version": "auto",
      "transport": "tcp",
      "will_message": {
        "topic": "homeassistant/status",
        "payload": "offline",
        "qos": 0,
        "retain": false
      },

However no new entity gets added.

I use MQTT with some Tasmota devices, these were manually configured before Discovery was a things and work just fine. Not sure if this is messing with the process? I have nothing in my configuration.yaml for MQTT other than the below, those Tasmota devices:

mqtt:
  sensor: !include mqtt_sensor.yaml
  switch: !include mqtt_switch.yaml
  light: !include mqtt_light.yaml

Any suggestions or advice would be greatly appreciated, thank you!

Did you create a MQTT discovery message ?

Discovery topic

The discovery topic needs to follow a specific format:

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

Text

  • <component>: One of the supported MQTT components, eg. binary_sensor.
  • <node_id> (Optional): ID of the node providing the topic, this is not used by Home Assistant but may be used to structure the MQTT topic. The ID of the node must only consist of characters from the character class [a-zA-Z0-9_-] (alphanumerics, underscore and hyphen).
  • <object_id>: The ID of the device. This is only to allow for separate topics for each device and is not used for the entity_id. The ID of the device must only consist of characters from the character class [a-zA-Z0-9_-] (alphanumerics, underscore and hyphen).

Hi @francisp , yes I did.

Message was sent to:

homeassistant/sensor/main_ups_Battery_float_voltage/config.

This is the breakdown:
discovery_prefix = “homeassistant”
componant = “sensor”
object_id = “main_ups_Battery_float_voltage”

Below is from my testing, shows the topic and the payload:

I published your config payload to your config topic on my system (HA and Mosquitto running in separate Docker containers on my Synology NAS) and:

So it must be something in your MQTT setup that is at fault.

Thanks @Troon.

I gave in and removed the intergration and removed the below from the configuration.yaml.

mqtt:
  sensor: !include mqtt_sensor.yaml
  switch: !include mqtt_switch.yaml
  light: !include mqtt_light.yaml

Then a reboot. After that I added the intergaration back and it picked them up. Not sure if there was a gremlin in the intergration or the configuration was messing with it (the problem of changing two things at the same time).

Working now, so happy.