Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
HLW8012 don't count single pulse (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
OttoWinter authored Feb 26, 2019
1 parent 0f192e4 commit 33aaab9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/esphome/sensor/hlw8012.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 33aaab9

Please sign in to comment.