MQTT Housekeeping

Moderator: leecollings

Post Reply
User avatar
elzorrovega
Posts: 64
Joined: Friday 08 May 2020 19:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: Bordeaux, France
Contact:

MQTT Housekeeping

Post by elzorrovega »

Good housekeeping of your MQTT gateway is essential to trouble free communication with peripheral applications such as NodeRED
Initially, I overlooked devices/variables published to MQTT gateway. To make things even more challenging, Domoticz was setup to request Weather forecast data for six locations. To add insult to injury, there was a time triggered MQTT script publishing Domoticz data every minute. A “small data” cocktail too rich for two Raspberry PI (RPI) 4b.

Firstly, choose parameters which should be available in MQTT gateway. If there are many devices in your respective system and you do not filter data exchanged, there may be unnecessary network traffic. Please refer to Setup, Hardware, Mosquitto MQTT page.

Secondly, if you are requesting weather forecast for numerous locations, spread the queries. Domoticz instance uses Norwegian Meteorological Institute and data comes every 5 minutes. This frequency seems to be hard-coded and there is no possibility to change. Enable your locations some 30 seconds apart so that data also is received at different intervals. You wish to avoid all locations data arriving at the same time.

Thirdly, if there are any Domoticz MQTT scripts publishing/subscribing data please make sure that they are event and not time triggered. As previously mentioned, a Domoticz and a NodeRED instance run in different RPIs. There was another Domoticz script switching On/Off Night lights triggered at sunrise and sunset. Respective Wall plugs turned On/Off as requested; however, at times their states did not coincide in NodeRED. At first, I suspected my NodeRED flow. Using MQTT-Explorer and the debug function in NodeRED, I came to the conclusion that sometimes Domoticz messages simply were not published to MQTT Gateway. This was probably due to heavy network traffic at specific times and outbound communication buffers probably saturate!

Time triggered Domoticz MQTT script serves as a communication watchdog. If NodeRED did not receive a message within 150 seconds, Domoticz/NodeRED link was declared dead.

Decided to use a dummy temperature sensor in Domoticz as watchdog. NodeRED generates a random temperature value published every 67 seconds - a prime number. This is to minimize number of messages every 1 minute. Dummy temperature change triggers Domoticz MQTT script to send data back to NodeRED.

Thanks to related comments in both Domoticz and NodeRED forums, I followed a few leads. Once above housekeeping was made, messages did not appear to be lost. I follow the situation in both Domoticz and NodeRED and for the moment all looks good. Feel free to ask for more details if this blurb is not enough!
The solution to the problem changes the problem!

Rasberry Pi 4 Model B; Bullseye -64 bit OS 6.1.21-v8+ #1642
Domoticz Version: 2024.7
zwave-js-ui: 9.30.1.46a9eda
zwave-js: 14.3.8
home id: 3714679688
home hex: 0xdd698388*
User avatar
waltervl
Posts: 5850
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: MQTT Housekeeping

Post by waltervl »

Another root cause to flood your MQTT broker: a very high P1 meter update frequency (eg every 1-10 seconds). As this updates a lot of devices in Domoticz and sends out a lot of MQTT messages when normal MQTT hardware gateway is activated (without MQTT filtering).
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest