9static const uint32_t HLW8012_CLOCK_FREQUENCY = 3579000;
11void HLW8012Component::setup() {
12 float reference_voltage = 0;
20 reference_voltage = 1.218f;
27 reference_voltage = 2.43f;
29 64.0f / 24.0f / HLW8012_CLOCK_FREQUENCY;
34void HLW8012Component::dump_config() {
37 " Change measurement mode every %" PRIu32
"\n"
38 " Current resistor: %.1f mΩ\n"
39 " Voltage Divider: %.1f",
41 LOG_PIN(
" SEL Pin: ", this->
sel_pin_);
42 LOG_PIN(
" CF Pin: ", this->
cf_pin_);
43 LOG_PIN(
" CF1 Pin: ", this->
cf1_pin_);
44 LOG_UPDATE_INTERVAL(
this);
45 LOG_SENSOR(
" ",
"Voltage", this->voltage_sensor_);
46 LOG_SENSOR(
" ",
"Current", this->current_sensor_);
47 LOG_SENSOR(
" ",
"Power", this->power_sensor_);
48 LOG_SENSOR(
" ",
"Energy", this->energy_sensor_);
50void HLW8012Component::update() {
75 ESP_LOGV(TAG,
"Got power=%.1fW, current=%.1fA", power, current);
76 PUBLISH_STATE(this->current_sensor_, current);
79 ESP_LOGV(TAG,
"Got power=%.1fW, voltage=%.1fV", power, voltage);
80 PUBLISH_STATE(this->voltage_sensor_, voltage);
84 PUBLISH_STATE(this->power_sensor_, power);
86 if (this->energy_sensor_ !=
nullptr) {
89 this->energy_sensor_->publish_state(energy);
94 ESP_LOGV(TAG,
"Changing mode to %s mode",
95 this->
current_mode_ ? LOG_STR_LITERAL(
"CURRENT") : LOG_STR_LITERAL(
"VOLTAGE"));