From ecab30d4ac5eafbdea8d85a63f4e2462f898a8f7 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Tue, 16 Dec 2025 08:27:21 +0100 Subject: [PATCH 1/2] do not flood mqtt queue if publish on change is set --- src/core/emsesp.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/core/emsesp.cpp b/src/core/emsesp.cpp index cab2ae0b7..5a4722ea5 100644 --- a/src/core/emsesp.cpp +++ b/src/core/emsesp.cpp @@ -1191,16 +1191,20 @@ bool EMSESP::process_telegram(std::shared_ptr telegram) { found_device = emsdevice.get(); if (emsdevice->handle_telegram(telegram)) { telegram_found = true; - if (Mqtt::connected() - && ((mqtt_.get_publish_onchange(found_device->device_type()) && found_device->has_update()) - || (telegram->type_id == publish_id_ && telegram->dest == EMSbus::ems_bus_id()))) { - if (telegram->type_id == publish_id_) { + if (Mqtt::connected()) { + // publish device data if it was a validate after write + if (telegram->type_id == publish_id_ && telegram->dest == EMSbus::ems_bus_id()) { publish_id_ = 0; - } - found_device->has_update(false); // reset flag - if (!Mqtt::publish_single()) { + found_device->has_update(false); // reset flag publish_device_values(found_device->device_type()); // publish to MQTT if we explicitly have too } + // auto publish: timeinterval 0 and publish single not set, only if queue is empty + else if (mqtt_.get_publish_onchange(found_device->device_type()) && found_device->has_update() && mqtt_.publish_queued() == 0) { + found_device->has_update(false); // reset flag + if (!Mqtt::publish_single()) { + publish_device_values(found_device->device_type()); + } + } } break; // remove this to handle same telegrams on multiple devices } From 18909489245eaa927e7fb19161cdf1589e909ad2 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Tue, 16 Dec 2025 11:36:58 +0100 Subject: [PATCH 2/2] mqtt-queue check also for publish-on-change analog/temperature --- src/core/analogsensor.cpp | 2 +- src/core/temperaturesensor.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/analogsensor.cpp b/src/core/analogsensor.cpp index 7ac9c793b..9428fcb36 100644 --- a/src/core/analogsensor.cpp +++ b/src/core/analogsensor.cpp @@ -600,7 +600,7 @@ bool AnalogSensor::update(uint8_t gpio, const char * org_name, double offset, do // check to see if values have been updated bool AnalogSensor::updated_values() { - if (changed_) { + if (changed_ && Mqtt::publish_queued() == 0) { changed_ = false; return true; } diff --git a/src/core/temperaturesensor.cpp b/src/core/temperaturesensor.cpp index e16d9103e..69f4d7b72 100644 --- a/src/core/temperaturesensor.cpp +++ b/src/core/temperaturesensor.cpp @@ -370,7 +370,7 @@ bool TemperatureSensor::update(const char * id, const char * name, int16_t offse // check to see if values have been updated bool TemperatureSensor::updated_values() { - if (changed_) { + if (changed_ && Mqtt::publish_queued() == 0) { changed_ = false; return true; }