From 1f978ef8944d528e9b816b219820d904b70461d8 Mon Sep 17 00:00:00 2001 From: Thomas Popp Date: Tue, 26 Nov 2024 21:14:15 +0100 Subject: [PATCH] fix(filter): fix update frequency --- AquaMQTT/src/task/MQTTTask.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/AquaMQTT/src/task/MQTTTask.cpp b/AquaMQTT/src/task/MQTTTask.cpp index 169ef50..6159085 100644 --- a/AquaMQTT/src/task/MQTTTask.cpp +++ b/AquaMQTT/src/task/MQTTTask.cpp @@ -1470,23 +1470,22 @@ void MQTTTask::publishFiltered( if (message->hasAttr(attribute)) { - float hotWaterTempRaw = message->getAttr(attribute); + float rawValue = message->getAttr(attribute); auto previousFilteredValue = mFilteredValue; - mFilteredValue = filter.updateEstimate(hotWaterTempRaw); + mFilteredValue = std::round(filter.updateEstimate(rawValue) * 10.0f) / 10.0f; if (fullUpdate) { publishFloat( MAIN_SUBTOPIC, topic, - config::MQTT_FILTER_TEMPERATURE_NOISE ? mFilteredValue : hotWaterTempRaw); + config::MQTT_FILTER_TEMPERATURE_NOISE ? mFilteredValue : rawValue); } else if (!config::MQTT_FILTER_TEMPERATURE_NOISE && message->hasChanged(attribute)) { - publishFloat(MAIN_SUBTOPIC, topic, hotWaterTempRaw); + publishFloat(MAIN_SUBTOPIC, topic, rawValue); } - // FIXME: this is broken - else if (config::MQTT_FILTER_TEMPERATURE_NOISE/* && (std::fabs(previousFilteredValue - mFilteredValue) >= 0.01)*/) + else if (config::MQTT_FILTER_TEMPERATURE_NOISE && previousFilteredValue != mFilteredValue) { publishFloat(MAIN_SUBTOPIC, topic, mFilteredValue); }