ESPHome  2024.11.1
sdm_meter.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 #include <vector>
8 
9 namespace esphome {
10 namespace sdm_meter {
11 
13  public:
14  void set_voltage_sensor(uint8_t phase, sensor::Sensor *voltage_sensor) {
15  this->phases_[phase].setup = true;
16  this->phases_[phase].voltage_sensor_ = voltage_sensor;
17  }
18  void set_current_sensor(uint8_t phase, sensor::Sensor *current_sensor) {
19  this->phases_[phase].setup = true;
20  this->phases_[phase].current_sensor_ = current_sensor;
21  }
22  void set_active_power_sensor(uint8_t phase, sensor::Sensor *active_power_sensor) {
23  this->phases_[phase].setup = true;
24  this->phases_[phase].active_power_sensor_ = active_power_sensor;
25  }
26  void set_apparent_power_sensor(uint8_t phase, sensor::Sensor *apparent_power_sensor) {
27  this->phases_[phase].setup = true;
28  this->phases_[phase].apparent_power_sensor_ = apparent_power_sensor;
29  }
30  void set_reactive_power_sensor(uint8_t phase, sensor::Sensor *reactive_power_sensor) {
31  this->phases_[phase].setup = true;
32  this->phases_[phase].reactive_power_sensor_ = reactive_power_sensor;
33  }
34  void set_power_factor_sensor(uint8_t phase, sensor::Sensor *power_factor_sensor) {
35  this->phases_[phase].setup = true;
36  this->phases_[phase].power_factor_sensor_ = power_factor_sensor;
37  }
38  void set_phase_angle_sensor(uint8_t phase, sensor::Sensor *phase_angle_sensor) {
39  this->phases_[phase].setup = true;
40  this->phases_[phase].phase_angle_sensor_ = phase_angle_sensor;
41  }
42  void set_total_power_sensor(sensor::Sensor *total_power_sensor) { this->total_power_sensor_ = total_power_sensor; }
43  void set_frequency_sensor(sensor::Sensor *frequency_sensor) { this->frequency_sensor_ = frequency_sensor; }
44  void set_import_active_energy_sensor(sensor::Sensor *import_active_energy_sensor) {
45  this->import_active_energy_sensor_ = import_active_energy_sensor;
46  }
47  void set_export_active_energy_sensor(sensor::Sensor *export_active_energy_sensor) {
48  this->export_active_energy_sensor_ = export_active_energy_sensor;
49  }
50  void set_import_reactive_energy_sensor(sensor::Sensor *import_reactive_energy_sensor) {
51  this->import_reactive_energy_sensor_ = import_reactive_energy_sensor;
52  }
53  void set_export_reactive_energy_sensor(sensor::Sensor *export_reactive_energy_sensor) {
54  this->export_reactive_energy_sensor_ = export_reactive_energy_sensor;
55  }
56 
57  void update() override;
58 
59  void on_modbus_data(const std::vector<uint8_t> &data) override;
60 
61  void dump_config() override;
62 
63  protected:
64  struct SDMPhase {
65  bool setup{false};
73  } phases_[3];
80 };
81 
82 } // namespace sdm_meter
83 } // namespace esphome
sensor::Sensor * import_active_energy_sensor_
Definition: sdm_meter.h:76
void dump_config() override
Definition: sdm_meter.cpp:86
void set_apparent_power_sensor(uint8_t phase, sensor::Sensor *apparent_power_sensor)
Definition: sdm_meter.h:26
void set_power_factor_sensor(uint8_t phase, sensor::Sensor *power_factor_sensor)
Definition: sdm_meter.h:34
struct esphome::sdm_meter::SDMMeter::SDMPhase phases_[3]
void set_total_power_sensor(sensor::Sensor *total_power_sensor)
Definition: sdm_meter.h:42
void set_export_reactive_energy_sensor(sensor::Sensor *export_reactive_energy_sensor)
Definition: sdm_meter.h:53
sensor::Sensor * frequency_sensor_
Definition: sdm_meter.h:74
void set_active_power_sensor(uint8_t phase, sensor::Sensor *active_power_sensor)
Definition: sdm_meter.h:22
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_frequency_sensor(sensor::Sensor *frequency_sensor)
Definition: sdm_meter.h:43
void set_export_active_energy_sensor(sensor::Sensor *export_active_energy_sensor)
Definition: sdm_meter.h:47
void set_import_active_energy_sensor(sensor::Sensor *import_active_energy_sensor)
Definition: sdm_meter.h:44
sensor::Sensor * apparent_power_sensor_
Definition: sdm_meter.h:69
sensor::Sensor * reactive_power_sensor_
Definition: sdm_meter.h:70
sensor::Sensor * export_active_energy_sensor_
Definition: sdm_meter.h:77
void set_import_reactive_energy_sensor(sensor::Sensor *import_reactive_energy_sensor)
Definition: sdm_meter.h:50
void set_voltage_sensor(uint8_t phase, sensor::Sensor *voltage_sensor)
Definition: sdm_meter.h:14
void set_phase_angle_sensor(uint8_t phase, sensor::Sensor *phase_angle_sensor)
Definition: sdm_meter.h:38
sensor::Sensor * export_reactive_energy_sensor_
Definition: sdm_meter.h:79
sensor::Sensor * import_reactive_energy_sensor_
Definition: sdm_meter.h:78
void set_reactive_power_sensor(uint8_t phase, sensor::Sensor *reactive_power_sensor)
Definition: sdm_meter.h:30
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void on_modbus_data(const std::vector< uint8_t > &data) override
Definition: sdm_meter.cpp:13
sensor::Sensor * total_power_sensor_
Definition: sdm_meter.h:75
Base-class for all sensors.
Definition: sensor.h:57
void set_current_sensor(uint8_t phase, sensor::Sensor *current_sensor)
Definition: sdm_meter.h:18