Skip to content

Commit

Permalink
fix(filter): fix update frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
tspopp committed Nov 26, 2024
1 parent 5c10329 commit 1f978ef
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions AquaMQTT/src/task/MQTTTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 1f978ef

Please sign in to comment.