I’ve started a bit early on my New Year resolution of converting my new house into a smart home. I’ve been spending the last few days tinkering with Home Assistant on my Raspberry Pi 3B in a Docker environment.
After learning about the need for a specific Raspberry Pi Docker image to run Home Assistant, I got everything up and running. Next mission, using the Mosquitto MQTT broker.
Fairly easy that was up and running as well. My initial tests with
mosquitto_sub -h 192.168.1.240 -v -t "/homeassistant/test" -u "rugaard" -P "secret"
connects smoothly and looks nice and pretty in the logs.
But as soon as I setup Home Assistant to connect to the Mosquitto (by following the official docs) it keeps getting
Connection Refused: not authorised and in the Mosquitto logs it looks like it’s because it tries to connect with an incorrect auth (or without auth):
1546249748: mosquitto version 1.5.5 starting 1546249748: Config loaded from /mosquitto/config/mosquitto.conf. 1546249748: Opening ipv4 listen socket on port 1883. 1546249748: Opening ipv6 listen socket on port 1883. 1546249761: New connection from 192.168.1.240 on port 1883. 1546249761: Socket error on client <unknown>, disconnecting.
And the Home Assistant logs prints the following:
2018-12-31 09:49:21 ERROR (Thread-2) [homeassistant.components.mqtt] Unable to connect to the MQTT broker: Connection Refused: not authorised.
I’m really confused to how this can happen, when I’m using the exact same username and password in Home Assistant, as I did in my initial test with
mosquitto_sub where it worked perfectly.
I’ve searched Google thin and tried all kinds of solution here in the Home Assistant community. None of them with any hint of success.
My Home Assistant configuration for MQTT looks like this (follwed the official docs)
mqtt: broker: 192.168.1.240 client_id: home-assistant keepalive: 60 username: !secret mqtt_username password: !secret mqtt_password
docker-compose.yml file looks like this:
version: '2.1' services: homeassistant: container_name: home-assistant image: homeassistant/raspberrypi3-homeassistant depends_on: mosquitto: condition: service_started volumes: - /home/pi/homeassistant:/config - /etc/localtime:/etc/localtime:ro network_mode: host healthcheck: test: ["CMD", "curl", "-f", "http://192.168.1.240:8123"] interval: 30s timeout: 10s retries: 6 restart: on-failure mosquitto: container_name: mqtt image: eclipse-mosquitto user: 1000:1000 volumes: - /srv/docker/mosquitto/config:/mosquitto/config - /srv/docker/mosquitto/data:/mosquitto/data - /srv/docker/mosquitto/log:/mosquitto/log - /etc/localtime:/etc/localtime:ro network_mode: host restart: on-failure
I’ve tried removing the
network_mode: host and used
ports instead as was mentioned as a solution in this post: https://community.home-assistant.io/t/solved-docker-mqtt-mosquitto-setup-what-am-i-missing/87381
But since my problem isn’t connection to the broker, but rather the authenticating, I’m not sure what to do.
Any help or suggestions is MUCH appreciated!
Happy new year everyone