From 33aaab9d02c4561c154c2bd0ebfdc79aa5d658b2 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Tue, 26 Feb 2019 16:43:59 +0100 Subject: [PATCH] HLW8012 don't count single pulse (#527) --- src/esphome/sensor/hlw8012.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/esphome/sensor/hlw8012.cpp b/src/esphome/sensor/hlw8012.cpp index a3d29110..5e2b5170 100644 --- a/src/esphome/sensor/hlw8012.cpp +++ b/src/esphome/sensor/hlw8012.cpp @@ -47,8 +47,18 @@ float HLW8012Component::get_setup_priority() const { return setup_priority::HARDWARE_LATE; } void HLW8012Component::update() { - float cf_hz = this->cf_.read_raw_value_() / (this->get_update_interval() / 1000.0f); - float cf1_hz = this->cf1_.read_raw_value_() / (this->get_update_interval() / 1000.0f); + pulse_counter_t raw_cf = this->cf_.read_raw_value_(); + pulse_counter_t raw_cf1 = this->cf1_.read_raw_value_(); + float cf_hz = raw_cf / (this->get_update_interval() / 1000.0f); + if (raw_cf <= 1) { + // don't count single pulse as power + cf_hz = 0.0f; + } + float cf1_hz = raw_cf1 / (this->get_update_interval() / 1000.0f); + if (cf1_hz <= 1) { + // don't count single pulse as anything + cf1_hz = 0.0f; + } if (this->nth_value_++ < 2) { return;