MQTT messages not getting through from network computer

In case anyone else has this problem. I figured it out.
From the command line on a RaspberryPi Zero W I was able to send a message with

mosquitto_pub -h homeassistant -t /this/is/a/topic -u mqtt-user -P password -m "this is a message"

But I could not send to “homeassistant” host using paho-mqtt or with mosquitto_pub on my Mac because it would complain that “homeassistant” is not a valid network address. If I sent to “homeassistant.local”, the message would not get to Home Assistant.
I tried something that I didn’t think would work but it did. I changed the “Discovery prefix” in the Home Assistant MQTT configuration to “homeassistant.local”.

Discovery prefix has nothing to with your the hostname homeassistant.local.

You should change that back to homeassistant because you just broke all auto device detection that HA uses.

Hi,

  • The MQTT protocol connects over TCP/IP, and uses IPv4 / IPv6 / DNS / mDNS.

  • HA MQTT discovery is specific to the MQTT protocol. It is completely unrelated to DNS.

They are very different and operate at completely different layers.

Get the IPv4 address of your HA machine which has the MQTT broker running on it, and use that to connect to the MQTT broker. Use the HA Settings → System → Network, or try pinging HA (ping homeassistant.local or similar to get the address).

Here’s an example that works with the IPv4 loopback address from the HA console itself locally:

Install MQTT Explorer and get it connected to your HA broker.

Here’s a step by step explanation of setting up MQTT on HA which I usually trot out…

If this helps, :heart: this post!

Okay. I put it back. But what had tripped me up is (for example) on my MacBook if I put in

mosquitto_pub -h homeassistant -t /this/is/a/topic -u mqtt-user -P pwd -m "this is a message"

I get

Unable to connect (Lookup error.)

I also get that message if use paho-mqtt in python.

I did not get the error if I put in homeassistant.local for the host. But HA did not receive the message.

HA did receive the message when I changed the prefix as I did in the screenshot.

So now I changed the prefix back to homeassistant and I used the ip address of the HA instance. (as FloatingBoater suggested) HA receives the message doing it that way.

Thank you both for your help.

Yes, because -h is looking for the hostname, which is homeassistant.local or your ip address.

This has no relationship to discovery_prefix, which is the MQTT topic prefix for the topics home assistant scans to find new devices.

Did you change the name in the top of your network settings in HA?

I’m not sure what you are asking. If you mean the name of the HA on the network, it is homeassistant. To access it the HA instance (i.e. with ssh), I normally use homeassistant.local. But now I am using the IP address (192.168.1.x)

The name is the text inserted on the top field on the network settings page in HA.
It is default homeassistant, but sometimes an user change it without knowing the consequences.