Resetting MQTT Broker Confusion

Hi,

I run Home Assistant in Docker on Ubuntu (ie I do not use Hassio). I also run MQTT as a separate docker container. I use docker compose to run these. These 2 containers previously worked fine together.

I need to reset my MQTT broker to use new credentials. I tried the following:

  1. In the MQTT intergration in the HA GUI I deleted the existing MQTT broker.
  2. I then opened a terminal on the PC and stopped my docker containers using docker-compose down, removed the containers via docker stop container id/docker rm container id and deleted the mosquitto folder (that contained sub folders for config,data and logs) from Docker (by deleting the physical mapped folder on my PC)
  3. I then rebuilt my containers (although it said as they all used images there was nothing to build) and then used docker-compose up to start my containers.
  4. If I then try to create a new MQTT broker via the HA GUI then I get a Failed to Connect error in the GUI and HA wipes what I just filled in for Broker,Username and Password.
  5. I then instead create a new MQTT broker via the configuration.yaml file as per https://www.home-assistant.io/docs/mqtt/broker/. Using this and setting a username, password, port and broker address result in a new MQTT broker successfully being added to Home Assistant and visible in the HA integrations page. However when I check the logs I see the following error Failed to connect to MQTT server due to exception: [Errno 111] Connection refused.

I assume that I am failing to delete some reference to the old MQTT broker but I am at a loss as to where it could be other than in the mosquitto container folder. Short of completely wiping everything and starting again does anyone have any ideas as to why, even when I am able to create a new MQTT broker that Home Assistant fails to connect to it?

Thanks

So you run „Home Assistant Container“ (not supervised).

No, you deleted the settings to connect Home Assistant to a broker as a client

and with this, you also removed the configuration (including accounts) from your dedicated MQTT broker. I guess (from the directory layout): Eclipse Mosquitto.

… a new MQTT client …

… because your MQTT broker (Mosquitto) no longer has a user record for Home Assistant as a client. You need to recreate the account for Home Assistant by issuing the following command inside the running Mosquitto container.

 mosquitto_passwd -c /mosquitto/config/passwd <username>

and then enter a password when prompted. Restart Mosquitto afterwards.

Use the username and password again when setting up MQTT integration in HA again.

Hi,

Thanks for the response and sorry for confusing things. If I am honest I really don’t remember setting up MQTT previously (it was 2 computers ago, last time I migrated to this PC I just reset the MQTT integration in HA and I was good to go.
I was incorrectly under the impression that all I had to do was setup my docker compose file and the HA integration and I would be all set.

You are correct that I am using Eclipse Mosquitto as my MQTT broker.

I tried what you said using the command:
docker exec -it 31xxxxx3c4f7 mosquitto_passwd -c /mosquitto/config/passwd ha

(client username=ha)and it asked me for a new password which I typed in twice and then restarted the MQTT container. However when I then log into HA GUI I am unable to setup a MQTT client via the integration using the new password that I just set (I get the same Failed to Connect error as before).

I had a backup of my complete HA instance so I was able to recover everything to before I deleted my mosquitto folder. Once I restored this, I can still successfully create a new MQTT client in HA via the integrations page using the original MQTT client username, password, address and port.

How can I completely remove the old MQTT broker and client from my system and setup a new one ?

Sorry if I am being silly, I have gotten myself quite confused with this.

Thanks

For the client it should be sufficient to remove the MQTT integration (via UI and/or from configuration.yaml).

Then

docker-compose down

without deleting any containers or images, not needed.

Then remove the host‘s directory/directories which provide volumes to the Mosquitto container (config, log, data).

Restart Mosquitto using

docker-compose up -d <service>

using the Mosquitto service name from your docker-compose file. Repeat the step above to set new username/password for Home Assistant MQTT integration.

Check that Mosquitto starts up fine

docker-compose logs —tail 30 <service>

Start the remaining services

docker-compose up -d

Login to HA, install & configure MQTT integration using UI.

1 Like

Thank you so much, that’s it working now.

An additional step that I had to add was run

docker-compose up -d mqtt

to create my new config,data and log folders and then create an empty file

sudo nano mosquitto/config/mosquitto.conf

(as the container would not start due to this file not existing), and then rerun

docker-compose up -d mqtt

Thanks for your help, I was going crazy with that!

1 Like