From ee0b6e835f5d656b90964bb3ea10c15681d1b1b5 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Fri, 18 Oct 2019 10:22:29 +0200 Subject: [PATCH] Sensor filter_out rounded (#765) Fixes https://github.com/esphome/issues/issues/741 --- esphome/components/sensor/filter.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/esphome/components/sensor/filter.cpp b/esphome/components/sensor/filter.cpp index 3f0d39fcfc..f7a5b5d7ad 100644 --- a/esphome/components/sensor/filter.cpp +++ b/esphome/components/sensor/filter.cpp @@ -166,7 +166,11 @@ optional FilterOutValueFilter::new_value(float value) { else return value; } else { - if (value == this->value_to_filter_out_) + int8_t accuracy = this->parent_->get_accuracy_decimals(); + float accuracy_mult = pow10f(accuracy); + float rounded_filter_out = roundf(accuracy_mult * this->value_to_filter_out_); + float rounded_value = roundf(accuracy_mult * value); + if (rounded_filter_out == rounded_value) return {}; else return value;