Endless "setup" while trying to connect to MQTT broker

Hi all!

I’m having HA running as a docker container, started with the provided docker compose file: Alternative - Home Assistant

I’m also having running an Mosquitto MQTT broker as a docker container, which is listening to port 1883/TCP.

When the MQTT integration is about to be set up (either in frontend or via configuration.yaml), HA hangs up. In frontend it’s quite obvious because the circle keeps spinning for minutes (then I aborted). When I configure it via configuration.yaml and restart HA, it’s not coming back, so I only see “connection lost”.

As MQTT broker address I tried:

  • localhost
  • 192.168.1.xx (private IP address of RPi in my LAN)
  • (IP address of the Mosquitto container)
  • It’s neither working with the public test.mosquitto.org server

Nothing works, the same problem as described occurs with all given addresses. While the integration is “setting up”, no log entries are created not even with

  default: debug

The MQTT broker works properly, I can access it both from the RPi and from other LAN devices.

Since the HA container runs with the host network setting, there shouldn’t be any problem with connection (especially with the iptables where 1883 is allowed), right?

I’m quite desperate because I have no idea what else could cause this problem - do you have any idea why HA can’t connect to the MQTT broker?

Many thanks in advance!

With docker logs mosquitto I get the following entries:

  • When using frontend:

New client connected from as auto-B5DCF3CB-6336-96BC-631B-01DE39906DA1 (p2, c1, k60, u’testuser’).

  • When using configuration.yaml:

New client connected from as haclient220128 (p2, c1, k60, u’testuser’).

So obviously I’m getting connected, but then it’s still hanging. The different IPs are caused by different specified broker addresses as mentioned in the main post.

For your information, indeed it was a iptables problem. I solved it by service docker restart and most important adding -A INPUT -p tcp -m tcp --dport 1883 -j ACCEPT to iptables. I’m gonna add more restrictions, but this solved it.