MQTT auto discovery not working

Anonymous seems a mistake when using the hassio addon

Why would that be a mistake? Does that stand in the way of auto discovery?

It doesn’t seem to work, from my observations on the forum.

What does not seem to work?
Auto discovery or anonymous access. Because anonymous access is working for me.

cat acl.conf 
acl_file /share/mosquitto/accesscontrollist
cat accesscontrollist 
topic readwrite #
topic $SYS/#

Ok lets try this: if you use mqtt_subscribe do you see the discovery messages being published when your device starts up?

Yes.

Publishing:

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

Subsciber:

mosquitto_sub -h 127.0.0.1 -t homeassistant/#
{"name": "garden1", "device_class": "motion", "state_topic": "homeassistant/binary_sensor/garden/state"}
ON

Repeat the test using:

Developer tools > MQTT > Publish a packet
Developer tools > MQTT > Listen to a topic

If these two tools fail then it means Home Assistant is not connected to the MQTT broker.

This put me on the right track. Those tests didn’t work. Then I removed the mqtt integration, but didn’t use the “discovered” mqtt integration, but added one myself and put in the 127.0.0.1 IP (or the network IP of course) and this worked.

Apparently when you add the “discovered” mqtt integration it doesn’t configure the mqtt integration correctly. It doesn’t offer you to put in the IP address. Bug it seems…

I’m going to test and see if discovery does work with the new configuration.

Thanks so far!

Did you figure out the issue you were having because I think I am having the same issue. The Broker is receiving all of the topics I am sending from various sources (Weather, Roon, etc) but devices never get discovered. If I manually add a sensor to the configuration.yaml that individual device (Temperature ex.) works fine.

Do you have discovery turned on in the mqtt configuration?

Give us an example of the discovery messages you see?

Yes, discovery is turned on (I think it was on by default). Install steps I did; Installed MQTT in Supervisor Add-ons and then configured the auto-discovered MQTT in Integrations. Then added mqtt sensors in configuration.yaml and they work but other servers sending MQTT topics to the HA broker is not getting creating devices. Do you have to use the same mqtt user for everything? Thanks for the help!

Here is a sample from the Broker logs:

1611505264: Opening ipv4 listen socket on port 1883.
1611505264: Opening ipv6 listen socket on port 1883.
1611505264: Opening websockets listen socket on port 1884.
1611505264: Warning: Mosquitto should not be run as root/administrator.
1611505265: New connection from 192.168.0.113 on port 1883.
[INFO] found mqtt on Home Assistant
1611505265: New client connected from 192.168. as roon-extension-mqtt-exydm (p2, c1, k60, u’mqtt’).
1611505277: New connection from 192.168 on port 1883.
1611505277: New client connected from 192.168.0.9 as weewx_e (p2, c1, k60, u’mqtt’).
1611505277: Client weewx_e0473da9 disconnected.
1611505289: New connection from 172.30.32.1 on port 1883.
[INFO] found homeassistant on local database
1611505289: New client connected from 172.30.32.1 as XXXXXXXXXXXXXXXX (p2, c1, k60, u’homeassistant’).
1611505336: New connection from 192.168.0.x on port 1883.

MQTT devices created in yaml don’t create devices, only entities. For devices you really need autodiscovery, not configuration.yaml.

This is what I see in the brokerimage

In the screenshot you posted, it is missing a root topic named homeassistant. That’s the default topic Home Assistant uses for MQTT Discovery. It means those “other servers” are not publishing to the MQTT Discovery topic.

I remember seeing homeassistant before reinstalling the add-on and integration. I’ll try some more stuff today to get the homeassistant topic back and go from there. Thanks again for your help!

I reconfigured mqtt to use the HA “mqttuser” account I created and “homeassistant” started showing up in mqtt explorer/broker and it shows “online”. I changed the weather server to publish to homeassistant/weather. If it starts to discover where would I see what it discovers, in the log?

image

Listen in the integration:

homeassistant is the topic to publish discovery information to.

However I don’t see an MQTT weather integration in home assistant https://www.home-assistant.io/integrations/#weather, nor do I see weather as a supported device here https://www.home-assistant.io/docs/mqtt/discovery/

That’s not how Home Assistant’s MQTT Discovery works.

It requires the topic and the payload to conform to a specific format (see the link in the first line). If they do, Home Assistant will use the supplied information to create an entity.

Currently, MQTT Discovery doesn’t support the creation of a weather entity. Moreover, there is no MQTT integration for weather (so it can’t be defined manually either).

MQTT Integrations

What you can do is create an MQTT Sensor for each weather-related parameter (temperature, humidity, wind speed, wind direction, precipitation amount, etc).


EDIT

Didn’t see nickrout’s post displayed until after I posted … so ninja’d again.

Awesome, well not awesome that it doesn’t support weather but now I know why it wasn’t working. I will add the sensors back to my configuration.yaml for now. You wouldn’t happen to know if roon falls under one of the categories listed in “supported devices” would you? The HA Roon integration detected and installed but Roon MQTT seems to have more details.

But your answer is more detailed, so outdone again!