ESPHome  1.15.2
ade7953.cpp
Go to the documentation of this file.
1 #include "ade7953.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace ade7953 {
6 
7 static const char *TAG = "ade7953";
8 
10  ESP_LOGCONFIG(TAG, "ADE7953:");
11  LOG_I2C_DEVICE(this);
12  LOG_UPDATE_INTERVAL(this);
13  LOG_SENSOR(" ", "Voltage Sensor", this->voltage_sensor_);
14  LOG_SENSOR(" ", "Current A Sensor", this->current_a_sensor_);
15  LOG_SENSOR(" ", "Current B Sensor", this->current_b_sensor_);
16  LOG_SENSOR(" ", "Active Power A Sensor", this->active_power_a_sensor_);
17  LOG_SENSOR(" ", "Active Power B Sensor", this->active_power_b_sensor_);
18 }
19 
20 #define ADE_PUBLISH_(name, factor) \
21  if (name && this->name##_sensor_) { \
22  float value = *name / factor; \
23  this->name##_sensor_->publish_state(value); \
24  }
25 #define ADE_PUBLISH(name, factor) ADE_PUBLISH_(name, factor)
26 
28  if (!this->is_setup_)
29  return;
30 
31  auto active_power_a = this->ade_read_<int32_t>(0x0312);
32  ADE_PUBLISH(active_power_a, 154.0f);
33  auto active_power_b = this->ade_read_<int32_t>(0x0313);
34  ADE_PUBLISH(active_power_b, 154.0f);
35  auto current_a = this->ade_read_<uint32_t>(0x031A);
36  ADE_PUBLISH(current_a, 100000.0f);
37  auto current_b = this->ade_read_<uint32_t>(0x031B);
38  ADE_PUBLISH(current_b, 100000.0f);
39  auto voltage = this->ade_read_<uint32_t>(0x031C);
40  ADE_PUBLISH(voltage, 26000.0f);
41 
42  // auto apparent_power_a = this->ade_read_<int32_t>(0x0310);
43  // auto apparent_power_b = this->ade_read_<int32_t>(0x0311);
44  // auto reactive_power_a = this->ade_read_<int32_t>(0x0314);
45  // auto reactive_power_b = this->ade_read_<int32_t>(0x0315);
46  // auto power_factor_a = this->ade_read_<int16_t>(0x010A);
47  // auto power_factor_b = this->ade_read_<int16_t>(0x010B);
48 }
49 
50 } // namespace ade7953
51 } // namespace esphome
sensor::Sensor * current_a_sensor_
Definition: ade7953.h:60
sensor::Sensor * current_b_sensor_
Definition: ade7953.h:61
sensor::Sensor * active_power_b_sensor_
Definition: ade7953.h:63
void dump_config() override
Definition: ade7953.cpp:9
Definition: a4988.cpp:4
sensor::Sensor * voltage_sensor_
Definition: ade7953.h:59
sensor::Sensor * active_power_a_sensor_
Definition: ade7953.h:62
void update() override
Definition: ade7953.cpp:27