Added energy sensor to hlw8012 (#1198)

This commit is contained in:
Frank Bakker
2021-02-13 09:57:06 +01:00
committed by GitHub
parent 57d6185374
commit 81b512a7b3
4 changed files with 18 additions and 2 deletions
+6
View File
@@ -79,6 +79,12 @@ void HLW8012Component::update() {
this->power_sensor_->publish_state(power);
}
if (this->energy_sensor_ != nullptr) {
cf_total_pulses_ += raw_cf;
float energy = cf_total_pulses_ * power_multiplier_micros / 3600 / 1000000.0f;
this->energy_sensor_->publish_state(energy);
}
if (this->change_mode_at_++ == this->change_mode_every_) {
this->current_mode_ = !this->current_mode_;
ESP_LOGV(TAG, "Changing mode to %s mode", this->current_mode_ ? "CURRENT" : "VOLTAGE");