ESPHome  2024.12.2
pzem004t.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace pzem004t {
9 
10 class PZEM004T : public PollingComponent, public uart::UARTDevice {
11  public:
12  void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; }
13  void set_current_sensor(sensor::Sensor *current_sensor) { current_sensor_ = current_sensor; }
14  void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; }
15  void set_energy_sensor(sensor::Sensor *energy_sensor) { energy_sensor_ = energy_sensor; }
16 
17  void setup() override;
18 
19  void loop() override;
20 
21  void update() override;
22 
23  void dump_config() override;
24 
25  protected:
30 
32  SET_ADDRESS = 0xB4,
33  READ_VOLTAGE = 0xB0,
34  READ_CURRENT = 0xB1,
35  READ_POWER = 0xB2,
36  READ_ENERGY = 0xB3,
37  DONE = 0x00,
38  } read_state_{DONE};
39 
41 
42  uint32_t last_read_{0};
43 };
44 
45 } // namespace pzem004t
46 } // namespace esphome
sensor::Sensor * power_sensor_
Definition: pzem004t.h:28
sensor::Sensor * voltage_sensor_
Definition: pzem004t.h:26
sensor::Sensor * energy_sensor_
Definition: pzem004t.h:29
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_power_sensor(sensor::Sensor *power_sensor)
Definition: pzem004t.h:14
void loop() override
Definition: pzem004t.cpp:18
sensor::Sensor * current_sensor_
Definition: pzem004t.h:27
void set_current_sensor(sensor::Sensor *current_sensor)
Definition: pzem004t.h:13
void set_voltage_sensor(sensor::Sensor *voltage_sensor)
Definition: pzem004t.h:12
void dump_config() override
Definition: pzem004t.cpp:118
void setup() override
Definition: pzem004t.cpp:10
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void update() override
Definition: pzem004t.cpp:98
Base-class for all sensors.
Definition: sensor.h:57
void write_state_(PZEM004TReadState state)
Definition: pzem004t.cpp:99
enum esphome::pzem004t::PZEM004T::PZEM004TReadState DONE
bool state
Definition: fan.h:34
void set_energy_sensor(sensor::Sensor *energy_sensor)
Definition: pzem004t.h:15