External MQTT Broker no connection

Hello,

i want to switch from openhab to HA.
After a install on Proxmox i want to integrate my Sensors.
The Matter Integraton is very good.
Now i want to stat qith my MQTT und Homematic device.

And on my first step, the MQTT i don´t can integrate my external Mosquitto Broker.
I have read some Forum s(like here: External Mosquitto Mqtt Connection Failed) but no Solution.

I use 2024.12.5 core.
Then i go to Settings und Devices. I add MQTT and select “g<ib die Verbindungsdaten manuell ein”.

I fill in all information Hostname, Port 1883, username und password. Then i become am “Verbindung nicht möglich”. No further information, in all test i become once a connect, but by the discover, the error ():

error (mainthread) [homeassistant.components.mqtt.client] failed to connect to mqtt server due to exception: [errno 111] connection refused

When i fill the configuratiion with

mqtt:
broker:
username:
password:

i become:

2024-12-28 19:05:48.570 ERROR (MainThread) [homeassistant.config] Invalid config for ‘mqtt’ at configuration.yaml, line 13: ‘broker’ is an invalid option for ‘mqtt’, check: mqtt->0->broker, please check the docs at MQTT - Home Assistant
Invalid config for ‘mqtt’ at configuration.yaml, line 13: ‘discovery’ is an invalid option for ‘mqtt’, check: mqtt->0->discovery, please check the docs at MQTT - Home Assistant
Invalid config for ‘mqtt’ at configuration.yaml, line 13: ‘discovery_prefix’ is an invalid option for ‘mqtt’, check: mqtt->0->discovery_prefix, please check the docs at MQTT - Home Assistant
Invalid config for ‘mqtt’ at configuration.yaml, line 13: ‘password’ is an invalid option for ‘mqtt’, check: mqtt->0->password, please check the docs at MQTT - Home Assistant
Invalid config for ‘mqtt’ at configuration.yaml, line 13: ‘port’ is an invalid option for ‘mqtt’, check: mqtt->0->port, please check the docs at MQTT - Home Assistant
Invalid config for ‘mqtt’ at configuration.yaml, line 13: ‘username’ is an invalid option for ‘mqtt’, check: mqtt->0->username, please check the docs at MQTT - Home Assistant

Have someone an idea?

With greetings,

Michael

Hi Michael,

Using both openHAB and HA on either an openHAB or HA hosted broker is possible as I parallel-ran both systems for several months in a phased transition:

Here’s a basic check-list for MQTT issues:

The HA MQTT client docs are pretty clear, so my guess from the error messages you post and my own experience is you may be struggling with the indentation and syntax of YAML (very different from openHAB).

I personally would configure the HA MQTT client entirely from the GUI, and NOT from configuration.yaml.

HA is moving away from editing YAML (apart from ESPhome, and perhaps templating in automations) as many new users have problems spotting indentation and syntax issues. Like Python, YAML is sensitive to tabs/ spaces/ indentation which is easy to got wrong. Sometimes pasting YAML into an external linter website can help fix problems - here, just use the GUI to connect to the broker.

Ignore the rest of the MQTT client config docs - get MQTT devices into HA + openHAB via auto-discovery FIRST. From my linked post:

Top Tip: If you use the Tasmota alternative ESPxx firmware, it moved away from HASS Discovery to Tasmota Discovery . Read up on SetOption19=0.

Once connected to one broker, you can manually define MQTT entities (devices) with custom topics. Just like openHAB, that config is awkward and error-prone!

If this helps, :heart: this post!

Hello James,

thanks for the answer. But my problem starts at the beginning when I want to establish the connection to the MQTT broker.
I can’t get a connection here.
I always get the message that the connection fails when I enter the access data via the UI. Unfortunately, HA is silent here, so no error message is generated in the log. But entering it manually in the YAML doesn’t work either. I don’t see any connection being established in the broker’s log either. But Openhab has a connection to the broker, as does Z2M and its own Python script, which controls external ventilation via MQTT. So I suspect a problem with the MQTT integration. But without log entries, I don’t know how to find the error.

Q: Need i install the internal MQTT Broker, that HA have the MQTT Sources to Connect to an external Broker?

Best greetings,

Michael

hi, you can definitely use an external broker.
Are you sure there is network connection between HA and broker?
Can you check broker connection using mqtt explorer to make sure it is up and correct user/password?

What do your broker logs say?

  • Try using a plain IPv4 address as HA might not be able to resolve a hostname via DNS / mDNS inside the HAOS VM. (IPv6 is getting better, but didn’t work with MQTT.)
  • Read the step-by-step link (ignore setting up a new broker) - tips like " don’t use a long text password with characters you could mis-type !£$^"@~" fix systems.
  • What do the MQTT Integration logs say?
    (MQTT Integration = client)
    (MQTT Add-On = Mosquitto broker)
    (Tasmota Discovery support is a seperate Tasmota Integration)
  • Ignore broker logs like the extract below - HA reguarly disconnects from the MQTT broker.
    The IPv4 addresses below are internal to HA (HA is in one VM, and if you use it, the Add-On Mosquitto broker is in another so the IPv4 are mapped externally via ports)
2024-12-29 11:43:50: New connection from 172.30.32.2:32880 on port 1883.
2024-12-29 11:43:50: Client <unknown> closed its connection.
2024-12-29 11:45:50: New connection from 172.30.32.2:41320 on port 1883.
2024-12-29 11:45:50: Client <unknown> closed its connection.
2024-12-29 11:47:50: New connection from 172.30.32.2:43268 on port 1883.

If this helps, :heart: this post!

Hello,

I have found the error.
The HA have the URL homeassistant.local
I use pihole as DNS Blocker.
The MQTT dont know homeassistant.local
So i have add homeassistant.local to pihole know Network Device and MQTT find the way back to HA.

Spooky, my network have the prefix fritz.box and not .local

Best of all,

Michael

.local is reserved by mDNS so there is a lot of argument about RFC6762 and .local .home .lan .box .alt (RFC 9476)…