Mosquitto MQTT continually disconnects and reconnects

Mosquitto MQTT v. 4.1
HASSIO v. 89.2

I am continually getting this in my logs It appears the MQTT server is constantly losing connection and reconnecting.

2019-03-16 19:36:07 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2019-03-16 19:36:07 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2019-03-16 19:37:07 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server
2019-03-16 19:38:07 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server

Sometimes when it reconnects it actually sets my alarm to “armed_home”. This is really hurting my WAF points. I’ve tried uninstalling and reinstalling Mosquitto MQTT add-on but that isn’t fixing it. Any idea what else I can try?

If it helps anyone else, I downgraded to HA v. 0.89.0 and no longer have this problem.

What is the setup you are using for the addon?

Here is my setup

{
“logins”: [
{
“username”: “HASSIO”,
“password”: “SECRET”
}
],
“anonymous”: false,
“customize”: {
“active”: false,
“folder”: “mosquitto”
},
“certfile”: “fullchain.pem”,
“keyfile”: “privkey.pem”
}

It’s been working great on HA 0.89.0

I upgraded to 0.90.1 to see if that fixed my issue and it did not. I’m still having the same issues. My MQTT devices are very unreliable on anything above HA v0.89.0. It appears that Mosquitto MQTT keeps losing a connection. I’m consistently getting messages like this in my log

2019-03-24 17:17:17 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server

2019-03-24 17:20:31 WARNING (Thread-2) [homeassistant.components.mqtt] Disconnected from MQTT (1). Trying to reconnect in 1 s

2019-03-24 17:20:32 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server

2019-03-24 17:22:04 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server

2019-03-24 17:22:32 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server

2019-03-24 17:23:32 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server

Anyone else seeing this?

1 Like

I’d recommend you file a bug report on github. This is normally caused by the MQTT client event loop not being given processing time. MQTT sends a “keep alive” packet every N seconds and if the broker doesn’t see that packet, it drops the connection. If the client code is not letting the connection send a keep alive packet often enough, it will to reconnect. So either the broker (if that changed) in 0.9 has been changed to have a shorter interval (seems unlikely) or the MQTT client event loop isn’t working right (more likely).

Hi, I am running Hass.IO 0.90.1 and I am not seeing any problems with MQTT broker using the MQTT server and web client but my config looks different to yours. This addon has also just updated to version 1. My config is essentially same as the example config with just my details added.
I monitor the MQTT activity with MQTT-spy, maybe that would help you see what is happening.

Are you using Mosquitto MQTT? My Mosquitto MQTT add-on is on version 4.1

My Mosquitto MQTT config is the same as the default, with the exception of my username and password.

I created a bug report
https://github.com/home-assistant/hassio/issues/969

Hi Brad, I am not using the mosquitto MQTT addon, I am using the MQTT Server & Web client addon, which I understand contains mosquitto MQTT. Sorry my mistake not taking more notice of what you wrote. The version I use includes a nice web page by HiveMQ that enables one to publish messages for testing and also to subscribe to messages for testing. I wish you luck in finding a solution.

Hi all i have similary issue with my ha…
i use:
homeassistant 0.104.3
System Health

arch armv7l
dev false
docker true
hassio true
os_name Linux
python_version 3.7.6
timezone Europe/Rome
version 0.104.3
virtualenv false

Lovelace

mode storage
resources 2
views 11

mosquitto broker addon 5.1

and this is some log:

2020-01-29T15:26:48.453022085Z 1580311608: Client btn_comodino-tano has exceeded timeout, disconnecting.
2020-01-29T15:26:48.475525586Z 1580311608: Client ctr_lavastoviglie has exceeded timeout, disconnecting.
2020-01-29T15:26:48.496725796Z 1580311608: Client btn_scala-interna has exceeded timeout, disconnecting.
2020-01-29T15:26:48.516782675Z 1580311608: Client btn_comodino-cameretta has exceeded timeout, disconnecting.
2020-01-29T15:26:48.535395192Z 1580311608: Client dst_bagno has exceeded timeout, disconnecting.
2020-01-29T15:26:49.457206528Z 1580311609: Client ctr_cappa has exceeded timeout, disconnecting.
2020-01-29T15:26:49.475004781Z 1580311609: Client btn_finestra-bagno has exceeded timeout, disconnecting.
2020-01-29T15:26:49.492982142Z 1580311609: Client ctr_luci has exceeded timeout, disconnecting.
2020-01-29T15:26:49.493781220Z 1580311609: Client btn_cancellino has exceeded timeout, disconnecting.
2020-01-29T15:26:51.417167381Z 1580311611: Client btn_cortile has exceeded timeout, disconnecting.
2020-01-29T15:26:51.435712306Z 1580311611: Client ctr_cantina has exceeded timeout, disconnecting.
2020-01-29T15:26:51.454013161Z 1580311611: Client btn_cantina has exceeded timeout, disconnecting.
2020-01-29T15:26:57.383900390Z 1580311617: Client shellydimmer-DB2E2B has exceeded timeout, disconnecting.
2020-01-29T15:26:59.282893044Z 1580311619: New connection from 10.10.10.22 on port 1883.
2020-01-29T15:26:59.286712864Z 1580311619: New client connected from 10.10.10.22 as ctr_pcottura (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:26:59.286847992Z 1580311619: New connection from 10.10.10.42 on port 1883.
2020-01-29T15:26:59.286911991Z 1580311619: New client connected from 10.10.10.42 as dst_living-1 (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:26:59.286970971Z 1580311619: New connection from 10.10.10.80 on port 1883.
2020-01-29T15:26:59.290236412Z 1580311619: New client connected from 10.10.10.80 as shellydimmer-DB2E2B (p2, c0, k60, u'cg-mqtt').
2020-01-29T15:26:59.455247843Z 1580311619: New connection from 10.10.10.14 on port 1883.
2020-01-29T15:26:59.470127593Z 1580311619: New client connected from 10.10.10.14 as ctr_cameretta (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:27:01.168454738Z 1580311621: New connection from 10.10.10.70 on port 1883.
2020-01-29T15:27:01.168698363Z 1580311621: New client connected from 10.10.10.70 as btn_ingresso (p2, c1, k30, u'cg-mqtt').
[...]
2020-01-29T15:27:08.350704279Z 1580311628: New client connected from 10.10.10.19 as ctr_cantina (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:27:08.439959410Z 1580311628: New connection from 10.10.10.82 on port 1883.
2020-01-29T15:27:08.440329978Z 1580311628: New client connected from 10.10.10.82 as btn_cantina (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:27:08.589366697Z 1580311628: New connection from 172.30.32.1 on port 1883.
2020-01-29T15:27:08.589904798Z 1580311628: New client connected from 172.30.32.1 as mqtt_1890188e.a4e0f7 (p1, c1, k60, u'cg-mqtt').
2020-01-29T15:28:11.595420261Z 1580311691: New connection from 10.10.10.83 on port 1883.
2020-01-29T15:28:12.533130768Z [INFO] found cg-mqtt on Home Assistant
2020-01-29T15:28:12.534542113Z 1580311692: New client connected from 10.10.10.83 as btn_scala-esterna (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:30:32.436542644Z 1580311832: Client btn_antibagno has exceeded timeout, disconnecting.
2020-01-29T15:30:49.015295071Z 1580311849: New connection from 10.10.10.73 on port 1883.
2020-01-29T15:30:49.017030577Z 1580311849: New client connected from 10.10.10.73 as btn_antibagno (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:30:53.443545709Z 1580311853: Client mqtt_1890188e.a4e0f7 has exceeded timeout, disconnecting.
2020-01-29T15:31:28.417879976Z 1580311888: Client ctr_living-2 has exceeded timeout, disconnecting.
2020-01-29T15:31:28.418187026Z 1580311888: Client btn_scala-esterna has exceeded timeout, disconnecting.
2020-01-29T15:31:30.462025666Z 1580311890: Client ctr_ups has exceeded timeout, disconnecting.
2020-01-29T15:31:52.405612803Z 1580311912: Client btn_cancellino has exceeded timeout, disconnecting.
2020-01-29T15:31:58.419700686Z 1580311918: Client dst_living-2 has exceeded timeout, disconnecting.
2020-01-29T15:32:05.455807376Z 1580311925: Client btn_cucina has exceeded timeout, disconnecting.
2020-01-29T15:32:05.494332125Z 1580311925: Client btn_area-comune has exceeded timeout, disconnecting.
2020-01-29T15:32:05.534628342Z 1580311925: Client ctr_frigo has exceeded timeout, disconnecting.
2020-01-29T15:32:20.090398854Z 1580311940: Socket error on client btn_antibagno, disconnecting.
2020-01-29T15:32:21.420163215Z 1580311941: Client btn_ingresso has exceeded timeout, disconnecting.
2020-01-29T15:32:21.460592171Z 1580311941: Client ctr_forno has exceeded timeout, disconnecting.
2020-01-29T15:32:21.501020941Z 1580311941: Client ctr_bagno has exceeded timeout, disconnecting.
[...]
2020-01-29T15:33:49.423517928Z 1580312029: Client btn_finestra-bagno has exceeded timeout, disconnecting.
2020-01-29T15:38:27.694144608Z 1580312307: New connection from 10.10.10.80 on port 1883.
2020-01-29T15:38:28.643399506Z [INFO] found cg-mqtt on Home Assistant
2020-01-29T15:38:28.644843165Z 1580312308: New client connected from 10.10.10.80 as shellydimmer-DB2E2B (p2, c0, k60, u'cg-mqtt').
2020-01-29T15:38:28.645473173Z 1580312308: New connection from 10.10.10.83 on port 1883.
2020-01-29T15:38:28.645917239Z 1580312308: New connection from 10.10.10.70 on port 1883.
2020-01-29T15:38:28.646093236Z 1580312308: New connection from 10.10.10.42 on port 1883.
2020-01-29T15:38:28.646367305Z 1580312308: New connection from 10.10.10.76 on port 1883.
2020-01-29T15:38:28.646883351Z 1580312308: New connection from 10.10.10.14 on port 1883.
[...]
2020-01-29T15:38:28.651995890Z 1580312308: New client connected from 10.10.10.11 as ctr_bagno (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:38:28.652018945Z 1580312308: New client connected from 172.30.32.1 as mqtt_1890188e.a4e0f7 (p1, c1, k60, u'cg-mqtt').
2020-01-29T15:38:28.654881209Z 1580312308: New client connected from 172.30.32.1 as mqttjs_fc4fe6c9 (p2, c1, k60, u'cg-mqtt').
2020-01-29T15:38:30.742545707Z 1580312310: New connection from 10.10.10.73 on port 1883.
2020-01-29T15:38:30.742624520Z 1580312310: New connection from 10.10.10.85 on port 1883.
2020-01-29T15:38:30.742807609Z 1580312310: New connection from 10.10.10.74 on port 1883.
2020-01-29T15:38:30.742873571Z 1580312310: New connection from 10.10.10.19 on port 1883.
2020-01-29T15:38:30.742901608Z 1580312310: New connection from 10.10.10.21 on port 1883.
2020-01-29T15:38:30.743109419Z 1580312310: New connection from 10.10.10.71 on port 1883.
[...]
2020-01-29T15:38:30.869429038Z 1580312310: New client connected from 10.10.10.71 as btn_cucina (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:38:30.870121451Z 1580312310: New client connected from 10.10.10.90 as btn_finestra-bagno (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:38:30.870800217Z 1580312310: New client connected from 10.10.10.26 as ctr_frigo (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:38:30.871577055Z 1580312310: New client connected from 10.10.10.72 as btn_soggiorno (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:38:30.872459391Z 1580312310: New client connected from 10.10.10.15 as ctr_ups (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:38:31.501894858Z 1580312311: New connection from 10.10.10.40 on port 1883.
[...]
2020-01-29T15:38:31.540961699Z 1580312311: New client connected from 10.10.10.40 as dst_camera01 (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:39:06.158073773Z 1580312346: New connection from 10.10.10.81 on port 1883.
2020-01-29T15:39:06.160689707Z 1580312346: New client connected from 10.10.10.81 as btn_scala-interna (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:39:18.207310189Z 1580312358: New connection from 10.10.10.24 on port 1883.
2020-01-29T15:39:18.207472371Z 1580312358: New client connected from 10.10.10.24 as ctr_lavatrice (p2, c1, k30, u'cg-mqtt').
2020-01-29T15:40:29.416858585Z 1580312429: New connection from 10.10.10.78 on port 1883.

I went home last night and the devices were not working, I had to reinstall mosquitto and redo the integration. from this morning continues to connect and disconnect the devices

Hi, I have the same. Hassio 0.106.0. Any one can solve this problem?

Hi, i have the same issue after upgrading to 0.107.5
168 reconnects on 10min interval.

Any idea?

Log:

Logger: homeassistant.core
Source: components/mqtt/__init__.py:1018
First occurred: 16:52:55 (168 occurrences)
Last logged: 17:02:55
Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/mqtt/__init__.py", line 911, in _async_perform_subscription
    _raise_on_error(result)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/__init__.py", line 1018, in _raise_on_error
    f"Error talking to MQTT: {mqtt.error_string(result_code)}"
homeassistant.exceptions.HomeAssistantError: Error talking to MQTT: The client is not currently connected.
1 Like

I have the same issue, my HA doesn’t work properly any longer with zigbee2mqtt.

1 Like

No problem with mqtt here.

I don’t have issues with zigbee2mqtt but I’m seeing the same problem with my esphome controlled esp8266.

You don’t by any chance have two MQTT clients using the same clientID do you ? That’s not allowed and MQTT will immediately disconnect one of the clients,

108.5 working very dependably here

2 Likes

I am noticing odd dropouts on MQTT Using the MosQuiTTo add-on as well. Using HA 108.9 and MosQuiTTO plugin version 5.1.
It seems to drop for a minute or two and then reconnect. Multiple clients do the same thing, all with unique client ID’s. Tested with just one client and also getting same thing.
I can’t find a pattern or consistency to the drops though. WiFi is good, within 2 mtrs of the Router. Sometimes it will stay connected for long times, sometimes with will do a few random drops/reconnects in a row.
Any advise would be approciated.

mosquitto produces a log.

Yes, which shows connection from new client, as per the previous log posted 10 months ago :slight_smile:
I will just keep looking around to find out why it does it.
Thanks

You haven’t posted your log in this thread. When you do, mske sure you are setting your miaquitto logging to get more than the standard. See http://www.steves-internet-guide.com/mosquitto-logging/