MQTT Auto Discovery Issues

Tags: #<Tag:0x00007fc418adaa78>

Hi all,

I am desperately trying to get to integrate a Node-Red sensor flow into home-assistant via MQTT.

For configuration, I inject the following json message to the config topic homeassistant/sensor/weatherStationHum/config:

{
    "name": "Weather Station Humidity",
    "device_class": "humidity",
    "state_topic": "homeassistant/sensor/weatherStation/weatherStationHum/state",
    "unit_of_measurement": "%",
    "icon":"mdi:thermometer",
    "unique_id":"weatherstation_humidity"
}

The sensor values are published accordingly to homeassistant/sensor/weatherStation/weatherStationHum/state.

However, homeassistant does not display a notification message that a new device has been discovered. I tried to stick to everything in the discovery documentation but am out of ideas by now.

Thankful for any help! :slight_smile:

are you able to see the mqtt messages are published in the state topic?

I find mqtt discovery very tricky and never able to make it work at first try. first maybe try if you can make it work manually by publishing discovery messages with a service call in home-assistant mqtt tab.

if there isn’t a specific reason you want to create sensors via mqtt, you can directly create them with entity node with node-red. listen the mqtt message with mqtt node and push it to homeassistant with entity node. you can set up all the icons, device class etc.

hi @serkank - thanks for your reply!

I do see the messages published in MQTT.

Using an entity node directly is a great idea - I will try that, let’s see how it goes. :slight_smile:

Alright - I didn’t get it to work with the entity node (don’t ask me why).
But: looking for the entity created by the entity node, I found that there were actually entities created by my MQTT attempts in node-red.
I was always waiting for a home-assistant notification indicating there is a new detected entity.

My (working) final setup is this: Sending the following payload to the config topic homeassistant/sensor/weatherStation/ws_hum/config:

{
    "name": "Weather Station Humidity",
    "device_class": "humidity",
    "state_topic": "homeassistant/sensor/weatherStation/ws_hum/state",
    "unit_of_measurement": "%",
    "icon": "mdi:water-percent",
    "unique_id": "weatherstation_humidity",
    "availability_topic": "multi_sensor/status",
    "device": {
        "identifiers": "10521c01c630",
        "name": "multi_sensor"
    }
}

The state values are then sent to homeassistant/sensor/weatherStation/ws_hum/state.

Thanks @serkank again. :slight_smile: