Page 1 of 1
MQTT AD Keepalive exceeded
Posted: Thursday 05 March 2026 12:03
by Stiens
Version: 2025.1 (build 16804)
Platform: Linux Docker container
Plugin/Hardware: MQTT, MQTT-AD
Description:
A few lines lines from my error log:
2026-03-05 11:16:26.638 Error: MQTT AD: Disconnected, restarting (rc=19/Keepalive exceeded)
2026-03-05 11:22:30.683 Error: MQTT AD: Disconnected, restarting (rc=19/Keepalive exceeded)
2026-03-05 11:28:33.669 Error: MQTT AD: Disconnected, restarting (rc=19/Keepalive exceeded)
2026-03-05 11:34:36.655 Error: MQTT AD: Disconnected, restarting (rc=19/Keepalive exceeded)
2026-03-05 11:40:39.621 Error: MQTT AD: Disconnected, restarting (rc=19/Keepalive exceeded)
This problem started after i created a new docker container with a process that generated a lot (200) of (new) topics. I'm using Mosquitto mqtt.
Domoticz finds these new topics, including the topics from Zigbee2mqtt and Zwave js ui and starts to import them. However this process stops after about 2 minutes and restarts after 5 minutes over and over...
Result is that i can't switch on my Hue lights with the Fibaro fob anymore
After some digging in the Domoticz source code i found a file MQTT.cpp with a hardcoded "int keepalive = 120" at line 640.
Could this be reason of my problem

Re: MQTT AD Keepalive exceeded
Posted: Friday 06 March 2026 15:43
by waltervl
Do you post MQTT and MQTT AD topics now in one big folder?
Normal Domoticz MQTT topics (default domoticz/in and domoticz/out) should be separated from Z2M AD (default zigbee2mqtt) and Zwave-JS-ui AD (default zwave) state topics to prevent MQTT AD looking at useless MQTT topics.
Also the discovery topics of Z2M and Zwave-JS-ui (default homeassistant) should not be in the same topic as standard domoticz/in /out and Z2M and Zwave-JS-ui state topic.
Default MQTT topic structure when using MQTT, MQTT-AD, Zwave-JS-UI and Zigbee2MQTT:
Code: Select all
domoticz (for standard MQTT messages)
/in
/out
Zwave (for state topics)
/node1
/node2
Zigbee2MQTT (for state topics)
/device1
/device2
homeassistant (for MQTT AD device creation for Zwave and Zigbee)
/switch
/sensor
/binary_sensor
Re: MQTT AD Keepalive exceeded
Posted: Friday 06 March 2026 20:14
by Stiens
Using default settings for Zigbee2mqtt and Zwave.
Domoticz MQTT AD Prefix is homeassistant
Problem started with the three BMS* topics (see the screenshot).
Strangely when i look in the status logging, the lines with "MQTT AD: Discovered: ....." stops after many lines, like it is ready (after +- 103 seconds). Than it takes 4 minutes for the error message to appear. After the error the MQTT AD messages start all over again.
See below for some log entries.
Last lines from the status log:
2026-03-06 19:52:25.814 Status: MQTT AD: Discovered: Zigbee2MQTT Bridge (Version)/Zigbee2MQTT Bridge (Version) (unique_id: bridge_0xe8e07efffeef2736_version_zigbee2mqtt)
2026-03-06 19:52:25.914 Status: MQTT AD: Discovered: Zigbee2MQTT Bridge (Coordinator version)/Zigbee2MQTT Bridge (Coordinator version) (unique_id: bridge_0xe8e07efffeef2736_coordinator_version_zigbee2mqtt)
2026-03-06 19:52:26.015 Status: MQTT AD: Discovered: Zigbee2MQTT Bridge (Network map)/Zigbee2MQTT Bridge (Network map) (unique_id: bridge_0xe8e07efffeef2736_network_map_zigbee2mqtt)
From the error log:
2026-03-06 19:50:21.634 Error: MQTT AD: Disconnected, restarting (rc=19/Keepalive exceeded)
2026-03-06 19:56:25.684 Error: MQTT AD: Disconnected, restarting (rc=19/Keepalive exceeded)
When i stop the container that generates the BMS topics then after some time Domoticz reads the Auto Discovery topics without the errors.
Re: MQTT AD Keepalive exceeded
Posted: Friday 06 March 2026 23:12
by waltervl
That seems to be strange as Domoticz should ignore the BMS MQTT topics. It look like Domoticz does not get access to the MQTT server due to an overload of MQTT or overall server overload resulting in general slow processing.
if you look at the server, what is the CPU load and what is the top process?
You could also try a Domoticz beta (with care, make a backup) because there something has changed in the queuing of events. I see you are also 1 stable behind....
Re: MQTT AD Keepalive exceeded
Posted: Saturday 07 March 2026 11:18
by Stiens
Thanks for the feedback waltervl
My setup is based on Proxmox with:
- Linux Mint VM. Within this VM i run docker versions if Mosquitto, Domoticz, Zigbee, Zwave and the new BMS container
- Home Assistant VM which connects to Mosquitto. HA sees all to the topics from zigbee, zwave, bms and exported topics from Domoticz. No problem there
Regarding the system load. I checked with "top" and "Monitor". See screenshots. I noticed the system has used some swap. So increased RAM from 12GB to 16GB and rebooted. The error remains
Somehow Domoticz discovered the BMS topics (screenshots). Found in homeassistant/sensor BMS topics (used for MQTT AD?)
Re: MQTT AD Keepalive exceeded
Posted: Saturday 07 March 2026 11:19
by Stiens
Another screenshot...
Re: MQTT AD Keepalive exceeded
Posted: Sunday 08 March 2026 8:14
by waltervl
Ah, OK, so BMS also supports MQTT AD. Then ignore the the previous remarks. On your side it looks fine to me.
Then I have no clue what goes wrong here. Perhaps someone else?
Re: MQTT AD Keepalive exceeded
Posted: Sunday 08 March 2026 11:17
by Kedi
Do a ping <mqtt-broker-ip> and look for abnormal values.
Do a
and look for errors which might clarify the usue.
KeepAlive is hardcoded in Domoticz.
Re: MQTT AD Keepalive exceeded
Posted: Monday 09 March 2026 10:24
by Stiens
Did some pings from a host in my network to the VM with the Mosquitto container. Looks ok to me, no packet loss. A little bit deviation.
1241 packets transmitted, 1241 received, 0% packet loss, time 1268889ms
rtt min/avg/max/mdev = 0.106/0.483/1.160/0.212 ms
The journalctl log failed, cause is that Mosquitto runs in a docker environment. I did an docker logs mosquitto (see screenshot). No errors/warnings, except that the Domoticz client keeps connecting over and over. The last lines in the screenshot are repeated over and over again.... (ip ...113 is HA)
Re: MQTT AD Keepalive exceeded
Posted: Monday 09 March 2026 14:14
by Kedi
I suppose you can get into the container at a bash prompt.
Put this in a file in /etc/mosquitto/conf.d/logging.conf or possibly better in /mosquitto/config/conf.d/logging.conf
and look in the mosquitto.conf file if files from conf.d are included.
Code: Select all
log_type information
log_type notice
log_type warning
log_type error
#log_type debug
#log_type all
log_dest topic
connection_messages true
max_keepalive 65535
log_timestamp true
log_timestamp_format %Y-%m-%dT%H:%M:%S
Restart the container
Uncomment the log_type debug for a short time. Logging increases rapidly. And see what can be found in the mosquitto.log file
B.t.w. The timestamp will now be human readable
Re: MQTT AD Keepalive exceeded
Posted: Monday 09 March 2026 20:02
by Stiens
First, thanks for the help

I hope whe can pinpoint the problem
Restarted Mosquitto with debug option, indeed it creates a lot of logging

Added entries to the config (for the record):
log_type information
log_type notice
log_type warning
log_type error
log_type debug
#log_type all
log_dest topic
connection_messages true
max_keepalive 65535
log_timestamp true
log_timestamp_format %Y-%m-%dT%H:%M:%S
log_dest file /mosquitto/log/mosquittodebug.log
When Domoticz displays the error than at the same time there is a disconnect in de Mosquitto logging. See below. Added Mosquitto screenshot for context.
Domoticz: 2026-03-09 19:41:38.701 Error: MQTT AD: Disconnected, restarting (rc=19/Keepalive exceeded)
Mosquitto: 2026-03-09T19:41:38: Client Domoticz-MQTT-AutoDiscover729e043c-9ed7-4971-bda6-bf72d2dd9ff014 closed its connection.
Re: MQTT AD Keepalive exceeded
Posted: Wednesday 11 March 2026 10:35
by Kedi
So it looks finally that the timeout in Domoticz of 120 seconds is to little in your case.
You could git clone the source, change the 120 in a higher settings and see what happens.
Re: MQTT AD Keepalive exceeded
Posted: Wednesday 11 March 2026 10:52
by jvdz
I guess another option is to use multiple AD Hardware devices, and link each to their own discovery Topic.
You could split Zwave-JS-UI and Zigbee2MQTT into their own AD Topic eg: HAZwave - HAZigbee and define those topics in Zwave-JS-UI and Zigbee2MQTT.
Hopefully you then have 120 secs per Hardware device and you limit the number of devices per HADisovery.
The disadvantage is that devices will be recreated.
The Advantage is that you group devices together per Protocol.
Re: MQTT AD Keepalive exceeded
Posted: Thursday 12 March 2026 10:38
by Stiens
Did a compile of an unmodified Domoticz version 2025.2 build 17356.
Run the executable on my laptop and setup MQTT-AD using the same Mosquitto MQTT server.
Result is that there are no errors generated. The MQTT AD discovery is very fast. 929 entries within 0,1 sec. (2026-03-12 10:15:51.077 to 2026-03-12 10:15:51.162)
Also did a compile with a modified MQTT.cpp (changed 120 to 240). This does not make any difference (as expected).
Conclusion (...) is that Domoticz running in a Docker Container on a Virtual Machine is not optimal

Or the newer version has an optimized MQTT AD.
To do is a test on the VM...
Re: MQTT AD Keepalive exceeded
Posted: Thursday 12 March 2026 10:52
by waltervl
Beta 2025.2 is using newer mosquitto libraries and better MQTT AD handling.
https://github.com/search?q=repo%3Adomo ... pe=commits
Re: MQTT AD Keepalive exceeded
Posted: Thursday 12 March 2026 14:07
by Stiens
Updated Domoticz with a docker compose pull. Now running stable version 2025.2 (build 16818).
Nothing changed compared to the previous version. Shows same behavior.
2026-03-12 13:59:09.658 Error: MQTT AD: Disconnected, restarting (rc=19/Keepalive exceeded)
I'm waiting for the updated version with the new Mosquitto libraries. Version 2026.1 is about to be released i quess (april?).
Re: MQTT AD Keepalive exceeded
Posted: Thursday 12 March 2026 20:47
by gizmocuz
Yes the beta version has increased the processing of MQTT a lot as you have seen.
Conclusion, use the beta (also before reporting issues it is wise to test with the beta first)
Re: MQTT AD Keepalive exceeded
Posted: Friday 13 March 2026 10:05
by Stiens
Did a test with a beta version in the VM with Docker.
Version: 2025.2 (build 17362)
Build Hash: 1b7621a08
Compile Date: 2026-03-12 19:28:12
dzVents Version: 3.1.11
Python Version: 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0]
Results:
2026-03-13 09:44:35.915 Status: MQTT AD: Discovered Line 60
2026-03-13 09:44:36.228 Status: MQTT AD: Discovered Line 988
929 discoveries in 0.313 seconds
So the problem is solved with the new Domoticz MQTT implementation and, nice to know, my hardware/software setup is fine
Thanks to all for the support.