ESPHome  2023.8.3
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 *const TAG = "ade7953";
8 
10  ESP_LOGCONFIG(TAG, "ADE7953:");
11  LOG_PIN(" IRQ Pin: ", irq_pin_);
12  LOG_I2C_DEVICE(this);
13  LOG_UPDATE_INTERVAL(this);
14  LOG_SENSOR(" ", "Voltage Sensor", this->voltage_sensor_);
15  LOG_SENSOR(" ", "Current A Sensor", this->current_a_sensor_);
16  LOG_SENSOR(" ", "Current B Sensor", this->current_b_sensor_);
17  LOG_SENSOR(" ", "Active Power A Sensor", this->active_power_a_sensor_);
18  LOG_SENSOR(" ", "Active Power B Sensor", this->active_power_b_sensor_);
19 }
20 
21 #define ADE_PUBLISH_(name, val, factor) \
22  if (err == i2c::ERROR_OK && this->name##_sensor_) { \
23  float value = (val) / (factor); \
24  this->name##_sensor_->publish_state(value); \
25  }
26 #define ADE_PUBLISH(name, val, factor) ADE_PUBLISH_(name, val, factor)
27 
29  if (!this->is_setup_)
30  return;
31 
32  uint32_t val;
33  i2c::ErrorCode err = ade_read_32_(0x0312, &val);
34  ADE_PUBLISH(active_power_a, (int32_t) val, 154.0f);
35  err = ade_read_32_(0x0313, &val);
36  ADE_PUBLISH(active_power_b, (int32_t) val, 154.0f);
37  err = ade_read_32_(0x031A, &val);
38  ADE_PUBLISH(current_a, (uint32_t) val, 100000.0f);
39  err = ade_read_32_(0x031B, &val);
40  ADE_PUBLISH(current_b, (uint32_t) val, 100000.0f);
41  err = ade_read_32_(0x031C, &val);
42  ADE_PUBLISH(voltage, (uint32_t) val, 26000.0f);
43 
44  // auto apparent_power_a = this->ade_read_<int32_t>(0x0310);
45  // auto apparent_power_b = this->ade_read_<int32_t>(0x0311);
46  // auto reactive_power_a = this->ade_read_<int32_t>(0x0314);
47  // auto reactive_power_b = this->ade_read_<int32_t>(0x0315);
48  // auto power_factor_a = this->ade_read_<int16_t>(0x010A);
49  // auto power_factor_b = this->ade_read_<int16_t>(0x010B);
50 }
51 
52 } // namespace ade7953
53 } // namespace esphome
sensor::Sensor * current_a_sensor_
Definition: ade7953.h:90
mopeka_std_values val[4]
sensor::Sensor * current_b_sensor_
Definition: ade7953.h:91
InternalGPIOPin * irq_pin_
Definition: ade7953.h:87
sensor::Sensor * active_power_b_sensor_
Definition: ade7953.h:93
void dump_config() override
Definition: ade7953.cpp:9
sensor::Sensor * voltage_sensor_
Definition: ade7953.h:89
sensor::Sensor * active_power_a_sensor_
Definition: ade7953.h:92
i2c::ErrorCode ade_read_32_(uint16_t reg, uint32_t *value)
Definition: ade7953.h:68
void update() override
Definition: ade7953.cpp:28