HLW8012 Power Sensor

See Application::make_hlw8012().

API Reference

class HLW8012Component : public PollingComponent

Public Functions

HLW8012Component(GPIOPin *sel_pin, uint8_t cf_pin, uint8_t cf1_pin, uint32_t update_interval = 15000)
void setup()

Where the component’s initialization should happen.

Analogous to Arduino’s setup(). This method is guaranteed to only be called once. Defaults to doing nothing.

void dump_config()
float get_setup_priority() const

priority of setup().

higher -> executed earlier

Defaults to 0.

Return
The setup priority of this component

void update()
HLW8012VoltageSensor *make_voltage_sensor(const std::string &name)
HLW8012CurrentSensor *make_current_sensor(const std::string &name)
HLW8012PowerSensor *make_power_sensor(const std::string &name)
void set_change_mode_every(uint32_t change_mode_every)
void set_current_resistor(float current_resistor)
void set_voltage_divider(float voltage_divider)

Protected Attributes

friend sensor::HLW8012Component::HLW8012CurrentSensor
friend sensor::HLW8012Component::HLW8012VoltageSensor
uint32_t nth_value_ = {0}
bool current_mode_ = {false}
uint32_t change_mode_at_ = {0}
uint32_t change_mode_every_ = {8}
float current_resistor_ = {0.001}
float voltage_divider_ = {2351}
GPIOPin *sel_pin_
PulseCounterBase cf_
PulseCounterBase cf1_
HLW8012VoltageSensor *voltage_sensor_ = {nullptr}
HLW8012CurrentSensor *current_sensor_ = {nullptr}
HLW8012PowerSensor *power_sensor_ = {nullptr}
class HLW8012VoltageSensor : public sensor::EmptySensor<1, ICON_FLASH, UNIT_V>

Public Functions

HLW8012VoltageSensor(const std::string &name, HLW8012Component *parent)
uint32_t update_interval()

Return with which interval the sensor is polled. Return 0 for non-polling mode.

Protected Attributes

HLW8012Component *parent_
class HLW8012CurrentSensor : public sensor::EmptySensor<1, ICON_FLASH, UNIT_A>

Public Functions

HLW8012CurrentSensor(const std::string &name, HLW8012Component *parent)
uint32_t update_interval()

Return with which interval the sensor is polled. Return 0 for non-polling mode.

Protected Attributes

HLW8012Component *parent_
using sensor::HLW8012PowerSensor = typedef EmptyPollingParentSensor<1, ICON_FLASH, UNIT_W>