MQTT AD Keepalive exceeded

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!

Moderators: leecollings, remb0

Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
Stiens
Posts: 14
Joined: Sunday 25 October 2020 15:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

MQTT AD Keepalive exceeded

Post 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 :?:
User avatar
waltervl
Posts: 7002
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: MQTT AD Keepalive exceeded

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Stiens
Posts: 14
Joined: Sunday 25 October 2020 15:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT AD Keepalive exceeded

Post 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.
Attachments
MQTT Screenshot.png
MQTT Screenshot.png (75.42 KiB) Viewed 7990 times
User avatar
waltervl
Posts: 7002
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: MQTT AD Keepalive exceeded

Post 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....
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Stiens
Posts: 14
Joined: Sunday 25 October 2020 15:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT AD Keepalive exceeded

Post 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?)
Attachments
Screenshot from 2026-03-07 10-42-55.png
Screenshot from 2026-03-07 10-42-55.png (48.35 KiB) Viewed 7945 times
Screenshot from 2026-03-07 10-43-19.png
Screenshot from 2026-03-07 10-43-19.png (80.67 KiB) Viewed 7945 times
Screenshot from 2026-03-07 11-13-29.png
Screenshot from 2026-03-07 11-13-29.png (189.54 KiB) Viewed 7945 times
Stiens
Posts: 14
Joined: Sunday 25 October 2020 15:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT AD Keepalive exceeded

Post by Stiens »

Another screenshot...
Attachments
Screenshot from 2026-03-07 10-51-36.jpg
Screenshot from 2026-03-07 10-51-36.jpg (315.25 KiB) Viewed 7945 times
User avatar
waltervl
Posts: 7002
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: MQTT AD Keepalive exceeded

Post 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?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Kedi
Posts: 622
Joined: Monday 20 March 2023 14:41
Target OS: Linux
Domoticz version: latest
Location: Somewhere in NL
Contact:

Re: MQTT AD Keepalive exceeded

Post by Kedi »

Do a ping <mqtt-broker-ip> and look for abnormal values.
Do a

Code: Select all

sudo journalctl -u mosquitto
and look for errors which might clarify the usue.
KeepAlive is hardcoded in Domoticz.
Logic will get you from A to B. Imagination will take you everywhere.
Stiens
Posts: 14
Joined: Sunday 25 October 2020 15:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT AD Keepalive exceeded

Post 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)
Attachments
Screenshot from 2026-03-09 10-10-17.png
Screenshot from 2026-03-09 10-10-17.png (181.18 KiB) Viewed 7796 times
Kedi
Posts: 622
Joined: Monday 20 March 2023 14:41
Target OS: Linux
Domoticz version: latest
Location: Somewhere in NL
Contact:

Re: MQTT AD Keepalive exceeded

Post 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
Logic will get you from A to B. Imagination will take you everywhere.
Stiens
Posts: 14
Joined: Sunday 25 October 2020 15:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT AD Keepalive exceeded

Post 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.
Attachments
Screenshot from 2026-03-09 19-50-57.png
Screenshot from 2026-03-09 19-50-57.png (192.03 KiB) Viewed 7746 times
Kedi
Posts: 622
Joined: Monday 20 March 2023 14:41
Target OS: Linux
Domoticz version: latest
Location: Somewhere in NL
Contact:

Re: MQTT AD Keepalive exceeded

Post 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.
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
jvdz
Posts: 2476
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: MQTT AD Keepalive exceeded

Post 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.
Stiens
Posts: 14
Joined: Sunday 25 October 2020 15:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT AD Keepalive exceeded

Post 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...
User avatar
waltervl
Posts: 7002
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2026.3
Location: NL
Contact:

Re: MQTT AD Keepalive exceeded

Post by waltervl »

Beta 2025.2 is using newer mosquitto libraries and better MQTT AD handling.
https://github.com/search?q=repo%3Adomo ... pe=commits
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Stiens
Posts: 14
Joined: Sunday 25 October 2020 15:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT AD Keepalive exceeded

Post 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?).
User avatar
gizmocuz
Posts: 3020
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: MQTT AD Keepalive exceeded

Post 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)
Quality outlives Quantity!
Stiens
Posts: 14
Joined: Sunday 25 October 2020 15:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT AD Keepalive exceeded

Post 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 :o

So the problem is solved with the new Domoticz MQTT implementation and, nice to know, my hardware/software setup is fine :D

Thanks to all for the support.
Post Reply