I’m trying to set up an mqtt broker using the official addon, but I keep getting this same error and my ESPHome device cannot connect to it. Logs and steps below:
I downloaded the mqtt broker addon, set up a unique user called mqtt-user, allowed them to log in, local only, and gave them a password. I wnt into integrations and added the mqtt broker, input the username and password, proceeded to the next screen where I left everything default for now, and then attempted to listen to a room (button, for example) and I publish to that same room using the UI and I see the message pop up. When I go to check my ESPHome device, I have provided it with the same username and password via a secrets file, and it continues to pop up the error:
[18:40:04][C][mqtt:030]: Setting up MQTT...
[18:40:04][I][mqtt:175]: Connecting to MQTT...
[18:40:34][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[18:40:34][I][mqtt:175]: Connecting to MQTT...
[18:41:04][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[18:41:04][I][mqtt:175]: Connecting to MQTT...
[18:41:34][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[18:41:34][I][mqtt:175]: Connecting to MQTT...
[18:42:04][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[18:42:04][I][mqtt:175]: Connecting to MQTT...
I check the Home Assistant OS logs and I see the following error pop up every time I restart the mqtt broker addon:
Disconnected from MQTT server core-mosquitto:1883
and the log from the mqtt broker addon itself:
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] mosquitto.sh: executing...
[17:20:03] INFO: SSL is not enabled
[cont-init.d] mosquitto.sh: exited 0.
[cont-init.d] nginx.sh: executing...
[cont-init.d] nginx.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[17:20:03] INFO: Starting NGINX for authentication handling...
[services.d] done.
[17:20:03] INFO: Starting mosquitto MQTT broker...
1644798003: mosquitto version 1.6.12 starting
1644798003: |-- *** auth-plug: startup
[17:20:03] INFO: Successfully send discovery information to Home Assistant.
[17:20:03] INFO: Successfully send service information to the Supervisor.
This same error happens if I use the host name or if I use the IP address for HA. I’ve checked IP addresses and host names, changed the username and password multiple times and checked via the UI to confirm that I can listen and receive the messages from the test, I’ve uninstalled and reinstalled the addon, deleted the config, nothing is working to resolve this.
Ozymandias:
I wnt into integrations and added the mqtt broker, input the username and password
That might be your issue.
The integration uses a special user (homeassistant). You should not have to specify a username and password for the integration if you are using the Mosquitto addon. With the broker running try removing the mqtt integration, restart home assistant and then try adding the integration again.
https://github.com/home-assistant/addons/blob/89112f96e0db8f207adfb1c988f2d5a26bac9877/mosquitto/DOCS.md#how-to-use
Awesome! Thank you! This removed the HA error but my ESPHome device is still unable to connect. I used the username and password I set up before and the log loops:
[21:06:18][I][mqtt:175]: Connecting to MQTT...
[21:06:49][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[21:06:49][I][mqtt:175]: Connecting to MQTT...
[21:07:18][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[21:07:18][I][mqtt:175]: Connecting to MQTT...
[21:07:48][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[21:07:48][I][mqtt:175]: Connecting to MQTT...
[21:08:19][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
mqtt broker logs show the following:
1644810408: Socket error on client <unknown>, disconnecting.
1644810528: New connection from 172.30.32.2 on port 1883.
1644810528: Socket error on client <unknown>, disconnecting.
1644810554: Saving in-memory database to /data/mosquitto.db.
1644810648: New connection from 172.30.32.2 on port 1883.
1644810648: Socket error on client <unknown>, disconnecting.
1644810768: New connection from 172.30.32.2 on port 1883.
1644810768: Socket error on client <unknown>, disconnecting.
1644810888: New connection from 172.30.32.2 on port 1883.
1644810888: Socket error on client <unknown>, disconnecting.
1644811008: New connection from 172.30.32.2 on port 1883.
1644811008: Socket error on client <unknown>, disconnecting.
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ssid: "Iotbutton001 Fallback Hotspot"
password: "<snip>"
And my mqtt config (Options → Addons → mqtt broker → config):
certfile: fullchain.pem
customize:
active: false
folder: mosquitto
keyfile: privkey.pem
logins: []
require_certificate: false
I don’t have any usernames or passwords in my mqtt config because I made a Home Assistant user by the name of mqtt-user and the documentation says that all HA users should work automatically. I can log in to a third party app on a different LAN PC using that username and password and IP.
Same issue:
[21:57:51][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[21:57:51][I][mqtt:175]: Connecting to MQTT...
But I can use mqtt_user and the pass to log in via MQTT Explorer on a different PC on the LAN.
### The problem
in my home assistant mosquito add-on, an unknown client no clie…nt id is connecting and disconnecting as a loop forever
the IP address of the client looks like a docker container IP address (172.30.32.2). my network address is 192.168.0.1 , but I can't find any what container is trying to connect .pleas help me
### What is version of Home Assistant Core has the issue?
core-2021.6.2
### What was the last working version of Home Assistant Core?
core-2021.4.0
### What type of installation are you running?
Home Assistant OS
### Integration causing the issue
### Link to integration documentation on our website
https://www.home-assistant.io/integrations/mqtt/
### Example YAML snippet
```yaml
logins:
- username: user
password: 123456789
customize:
active: false
folder: mosquitto
certfile: fullchain.pem
keyfile: privkey.pem
require_certificate: false
### Anything in the logs that might be useful for us?
```txt
1623126169: New connection from 192.168.0.110 on port 1883.
1623126169: New client connected from 192.168.0.110 as sonofflight1 (p2, c1, k30, u'hassio').
1623126184: New connection from 192.168.0.117 on port 1883.
1623126184: New client connected from 192.168.0.117 as keypad (p2, c1, k30, u'hassio').
1623126204: New connection from 172.30.32.1 on port 1883.
1623126204: New client connected from 172.30.32.1 as 2he2ok6kXNV7syNo9EIH5K (p2, c1, k60, u'hassio').
1623126373: New connection from 172.30.32.2 on port 1883.
1623126373: Socket error on client <unknown>, disconnecting.
1623126431: New connection from 172.30.33.5 on port 1883.
1623126431: New client connected from 172.30.33.5 as mqttjs_c8632349 (p2, c1, k60, u'hassio').
1623126493: New connection from 172.30.32.2 on port 1883.
1623126493: Socket error on client <unknown>, disconnecting.
1623126613: New connection from 172.30.32.2 on port 1883.
1623126613: Socket error on client <unknown>, disconnecting.
1623126733: New connection from 172.30.32.2 on port 1883.
1623126733: Socket error on client <unknown>, disconnecting.
1623126853: New connection from 172.30.32.2 on port 1883.
1623126853: Socket error on client <unknown>, disconnecting.
1623126973: New connection from 172.30.32.2 on port 1883.
1623126973: Socket error on client <unknown>, disconnecting.
1623127093: New connection from 172.30.32.2 on port 1883.
1623127093: Socket error on client <unknown>, disconnecting.
1623127213: New connection from 172.30.32.2 on port 1883.
1623127213: Socket error on client <unknown>, disconnecting.
1623127333: New connection from 172.30.32.2 on port 1883.
1623127333: Socket error on client <unknown>, disconnecting.
1623127453: New connection from 172.30.32.2 on port 1883.
1623127453: Socket error on client <unknown>, disconnecting.
1623127573: New connection from 172.30.32.2 on port 1883.
1623127573: Socket error on client <unknown>, disconnecting.
1623127693: New connection from 172.30.32.2 on port 1883.
1623127693: Socket error on client <unknown>, disconnecting.
1623127813: New connection from 172.30.32.2 on port 1883.
1623127813: Socket error on client <unknown>, disconnecting.
1623127933: New connection from 172.30.32.2 on port 1883.
1623127933: Socket error on client <unknown>, disconnecting.
1623127960: Saving in-memory database to /data/mosquitto.db.
1623128053: New connection from 172.30.32.2 on port 1883.
1623128053: Socket error on client <unknown>, disconnecting.
1623128173: New connection from 172.30.32.2 on port 1883.
1623128173: Socket error on client <unknown>, disconnecting.
1623128293: New connection from 172.30.32.2 on port 1883.
1623128293: Socket error on client <unknown>, disconnecting.
1623128413: New connection from 172.30.32.2 on port 1883.
1623128413: Socket error on client <unknown>, disconnecting.
1623128533: New connection from 172.30.32.2 on port 1883.
1623128533: Socket error on client <unknown>, disconnecting.
1623128653: New connection from 172.30.32.2 on port 1883.
1623128653: Socket error on client <unknown>, disconnecting.
1623128773: New connection from 172.30.32.2 on port 1883.
1623128773: Socket error on client <unknown>, disconnecting.
1623128893: New connection from 172.30.32.2 on port 1883.
1623128893: Socket error on client <unknown>, disconnecting.
1623129013: New connection from 172.30.32.2 on port 1883.
1623129013: Socket error on client <unknown>, disconnecting.
1623129133: New connection from 172.30.32.2 on port 1883.
1623129133: Socket error on client <unknown>, disconnecting.
1623129253: New connection from 172.30.32.2 on port 1883.
1623129253: Socket error on client <unknown>, disconnecting.
1623129373: New connection from 172.30.32.2 on port 1883.
1623129373: Socket error on client <unknown>, disconnecting.
1623129493: New connection from 172.30.32.2 on port 1883.
1623129493: Socket error on client <unknown>, disconnecting.
1623129613: New connection from 172.30.32.2 on port 1883.
1623129613: Socket error on client <unknown>, disconnecting.
1623129733: New connection from 172.30.32.2 on port 1883.
1623129733: Socket error on client <unknown>, disconnecting.
1623129761: Saving in-memory database to /data/mosquitto.db.
1623129853: New connection from 172.30.32.2 on port 1883.
1623129853: Socket error on client <unknown>, disconnecting.
1623129973: New connection from 172.30.32.2 on port 1883.
### Additional information
_No response_
Good catch on the api portion. I have it left out of my other ones but forgot it on this one. I am getting this error now in ESPHome wifi logs:
ERROR Cannot connect to MQTT broker: [Errno 113] No route to host
I moved the mqtt section down to the bottom but maybe I need a longer delay before I call it to allow time to connect to the network?
Not yet but the idea is to wire the button to the reset pin, have the device reboot when the button is pressed, send the mqtt message then go into deep sleep.
I’m not sure why but typing my HA IP in plaintext worked even though my secrets has it correct and all my other ESPHome devices use it!