9static const char *
const TAG =
"atm90e32";
13 for (uint8_t phase = 0; phase < 3; phase++) {
14 if (this->
phase_[phase].voltage_sensor_ !=
nullptr)
17 if (this->
phase_[phase].current_sensor_ !=
nullptr)
20 if (this->
phase_[phase].power_sensor_ !=
nullptr)
23 if (this->
phase_[phase].power_factor_sensor_ !=
nullptr)
26 if (this->
phase_[phase].reactive_power_sensor_ !=
nullptr)
29 if (this->
phase_[phase].apparent_power_sensor_ !=
nullptr)
32 if (this->
phase_[phase].forward_active_energy_sensor_ !=
nullptr)
35 if (this->
phase_[phase].reverse_active_energy_sensor_ !=
nullptr)
38 if (this->
phase_[phase].phase_angle_sensor_ !=
nullptr)
41 if (this->
phase_[phase].harmonic_active_power_sensor_ !=
nullptr)
44 if (this->
phase_[phase].peak_current_sensor_ !=
nullptr)
48 if (this->
phase_[phase].voltage_sensor_ !=
nullptr)
51 if (this->
phase_[phase].current_sensor_ !=
nullptr)
54 if (this->
phase_[phase].power_sensor_ !=
nullptr)
57 if (this->
phase_[phase].power_factor_sensor_ !=
nullptr)
60 if (this->
phase_[phase].reactive_power_sensor_ !=
nullptr)
63 if (this->
phase_[phase].apparent_power_sensor_ !=
nullptr)
66 if (this->
phase_[phase].forward_active_energy_sensor_ !=
nullptr) {
71 if (this->
phase_[phase].reverse_active_energy_sensor_ !=
nullptr) {
76 if (this->
phase_[phase].phase_angle_sensor_ !=
nullptr)
79 if (this->
phase_[phase].harmonic_active_power_sensor_ !=
nullptr) {
84 if (this->
phase_[phase].peak_current_sensor_ !=
nullptr)
96 if (this->
read16_(ATM90E32_REGISTER_METEREN) != 1) {
103#ifdef USE_TEXT_SENSOR
111 ESP_LOGCONFIG(TAG,
"Setting up ATM90E32 Component...");
114 uint16_t mmode0 = 0x87;
115 uint16_t high_thresh = 0;
116 uint16_t low_thresh = 0;
133 this->
write16_(ATM90E32_REGISTER_SOFTRESET, 0x789A);
135 this->
write16_(ATM90E32_REGISTER_CFGREGACCEN, 0x55AA);
137 ESP_LOGW(TAG,
"Could not initialize ATM90E32 IC, check SPI settings");
142 this->
write16_(ATM90E32_REGISTER_METEREN, 0x0001);
143 this->
write16_(ATM90E32_REGISTER_SAGPEAKDETCFG, 0xFF3F);
144 this->
write16_(ATM90E32_REGISTER_PLCONSTH, 0x0861);
145 this->
write16_(ATM90E32_REGISTER_PLCONSTL, 0xC468);
146 this->
write16_(ATM90E32_REGISTER_ZXCONFIG, 0xD654);
147 this->
write16_(ATM90E32_REGISTER_MMODE0, mmode0);
149 this->
write16_(ATM90E32_REGISTER_FREQHITH, high_thresh);
150 this->
write16_(ATM90E32_REGISTER_FREQLOTH, low_thresh);
151 this->
write16_(ATM90E32_REGISTER_PSTARTTH, 0x1D4C);
152 this->
write16_(ATM90E32_REGISTER_QSTARTTH, 0x1D4C);
153 this->
write16_(ATM90E32_REGISTER_SSTARTTH, 0x1D4C);
154 this->
write16_(ATM90E32_REGISTER_PPHASETH, 0x02EE);
155 this->
write16_(ATM90E32_REGISTER_QPHASETH, 0x02EE);
168 ESP_LOGI(TAG,
"[CALIBRATION] Power & Voltage/Current offset calibration is disabled. Using config file values.");
169 for (uint8_t phase = 0; phase < 3; ++phase) {
171 static_cast<uint16_t
>(this->
offset_phase_[phase].voltage_offset_));
173 static_cast<uint16_t
>(this->
offset_phase_[phase].current_offset_));
188 ESP_LOGI(TAG,
"[CALIBRATION] Successfully restored gain calibration from memory.");
190 for (uint8_t phase = 0; phase < 3; ++phase) {
196 ESP_LOGI(TAG,
"[CALIBRATION] Gain calibration is disabled. Using config file values.");
198 for (uint8_t phase = 0; phase < 3; ++phase) {
210 this->
write16_(ATM90E32_REGISTER_SAGTH, sagth);
211 this->
write16_(ATM90E32_REGISTER_OVTH, ovth);
213 this->
write16_(ATM90E32_REGISTER_CFGREGACCEN, 0x0000);
217 ESP_LOGCONFIG(
"",
"ATM90E32:");
218 LOG_PIN(
" CS Pin: ", this->
cs_);
220 ESP_LOGE(TAG,
"Communication with ATM90E32 failed!");
222 LOG_UPDATE_INTERVAL(
this);
223 LOG_SENSOR(
" ",
"Voltage A", this->
phase_[
PHASEA].voltage_sensor_);
224 LOG_SENSOR(
" ",
"Current A", this->
phase_[
PHASEA].current_sensor_);
225 LOG_SENSOR(
" ",
"Power A", this->
phase_[
PHASEA].power_sensor_);
226 LOG_SENSOR(
" ",
"Reactive Power A", this->
phase_[
PHASEA].reactive_power_sensor_);
227 LOG_SENSOR(
" ",
"Apparent Power A", this->
phase_[
PHASEA].apparent_power_sensor_);
228 LOG_SENSOR(
" ",
"PF A", this->
phase_[
PHASEA].power_factor_sensor_);
229 LOG_SENSOR(
" ",
"Active Forward Energy A", this->
phase_[
PHASEA].forward_active_energy_sensor_);
230 LOG_SENSOR(
" ",
"Active Reverse Energy A", this->
phase_[
PHASEA].reverse_active_energy_sensor_);
231 LOG_SENSOR(
" ",
"Harmonic Power A", this->
phase_[
PHASEA].harmonic_active_power_sensor_);
232 LOG_SENSOR(
" ",
"Phase Angle A", this->
phase_[
PHASEA].phase_angle_sensor_);
233 LOG_SENSOR(
" ",
"Peak Current A", this->
phase_[
PHASEA].peak_current_sensor_);
234 LOG_SENSOR(
" ",
"Voltage B", this->
phase_[
PHASEB].voltage_sensor_);
235 LOG_SENSOR(
" ",
"Current B", this->
phase_[
PHASEB].current_sensor_);
236 LOG_SENSOR(
" ",
"Power B", this->
phase_[
PHASEB].power_sensor_);
237 LOG_SENSOR(
" ",
"Reactive Power B", this->
phase_[
PHASEB].reactive_power_sensor_);
238 LOG_SENSOR(
" ",
"Apparent Power B", this->
phase_[
PHASEB].apparent_power_sensor_);
239 LOG_SENSOR(
" ",
"PF B", this->
phase_[
PHASEB].power_factor_sensor_);
240 LOG_SENSOR(
" ",
"Active Forward Energy B", this->
phase_[
PHASEB].forward_active_energy_sensor_);
241 LOG_SENSOR(
" ",
"Active Reverse Energy B", this->
phase_[
PHASEB].reverse_active_energy_sensor_);
242 LOG_SENSOR(
" ",
"Harmonic Power B", this->
phase_[
PHASEB].harmonic_active_power_sensor_);
243 LOG_SENSOR(
" ",
"Phase Angle B", this->
phase_[
PHASEB].phase_angle_sensor_);
244 LOG_SENSOR(
" ",
"Peak Current B", this->
phase_[
PHASEB].peak_current_sensor_);
245 LOG_SENSOR(
" ",
"Voltage C", this->
phase_[
PHASEC].voltage_sensor_);
246 LOG_SENSOR(
" ",
"Current C", this->
phase_[
PHASEC].current_sensor_);
247 LOG_SENSOR(
" ",
"Power C", this->
phase_[
PHASEC].power_sensor_);
248 LOG_SENSOR(
" ",
"Reactive Power C", this->
phase_[
PHASEC].reactive_power_sensor_);
249 LOG_SENSOR(
" ",
"Apparent Power C", this->
phase_[
PHASEC].apparent_power_sensor_);
250 LOG_SENSOR(
" ",
"PF C", this->
phase_[
PHASEC].power_factor_sensor_);
251 LOG_SENSOR(
" ",
"Active Forward Energy C", this->
phase_[
PHASEC].forward_active_energy_sensor_);
252 LOG_SENSOR(
" ",
"Active Reverse Energy C", this->
phase_[
PHASEC].reverse_active_energy_sensor_);
253 LOG_SENSOR(
" ",
"Harmonic Power C", this->
phase_[
PHASEC].harmonic_active_power_sensor_);
254 LOG_SENSOR(
" ",
"Phase Angle C", this->
phase_[
PHASEC].phase_angle_sensor_);
255 LOG_SENSOR(
" ",
"Peak Current C", this->
phase_[
PHASEC].peak_current_sensor_);
266 uint8_t addrh = (1 << 7) | ((a_register >> 8) & 0x03);
267 uint8_t addrl = (a_register & 0xFF);
277 output = (uint16_t(data[0] & 0xFF) << 8) | (data[1] & 0xFF);
278 ESP_LOGVV(TAG,
"read16_ 0x%04" PRIX16
" output 0x%04" PRIX16, a_register, output);
283 const uint16_t val_h = this->
read16_(addr_h);
284 const uint16_t val_l = this->
read16_(addr_l);
285 const int32_t
val = (val_h << 16) | val_l;
288 "read32_ addr_h 0x%04" PRIX16
" val_h 0x%04" PRIX16
" addr_l 0x%04" PRIX16
" val_l 0x%04" PRIX16
290 addr_h, val_h, addr_l, val_l,
val);
296 ESP_LOGVV(TAG,
"write16_ 0x%04" PRIX16
" val 0x%04" PRIX16, a_register,
val);
333 const uint16_t voltage = this->
read16_(ATM90E32_REGISTER_URMS + phase);
335 return (
float) voltage / 100;
339 const uint8_t reads = 10;
340 uint32_t accumulation = 0;
341 uint16_t voltage = 0;
342 for (uint8_t i = 0; i < reads; i++) {
343 voltage = this->
read16_(ATM90E32_REGISTER_URMS + phase);
345 accumulation += voltage;
347 voltage = accumulation / reads;
353 const uint8_t reads = 10;
354 uint32_t accumulation = 0;
355 uint16_t current = 0;
356 for (uint8_t i = 0; i < reads; i++) {
357 current = this->
read16_(ATM90E32_REGISTER_IRMS + phase);
359 accumulation += current;
361 current = accumulation / reads;
367 const uint16_t current = this->
read16_(ATM90E32_REGISTER_IRMS + phase);
369 return (
float) current / 1000;
373 const int val = this->
read32_(ATM90E32_REGISTER_PMEAN + phase, ATM90E32_REGISTER_PMEANLSB + phase);
374 return val * 0.00032f;
378 const int val = this->
read32_(ATM90E32_REGISTER_QMEAN + phase, ATM90E32_REGISTER_QMEANLSB + phase);
379 return val * 0.00032f;
383 const int val = this->
read32_(ATM90E32_REGISTER_SMEAN + phase, ATM90E32_REGISTER_SMEANLSB + phase);
384 return val * 0.00032f;
388 uint16_t powerfactor = this->
read16_(ATM90E32_REGISTER_PFMEAN + phase);
390 return (
float) ((int16_t) powerfactor) / 1000;
394 const uint16_t
val = this->
read16_(ATM90E32_REGISTER_APENERGY + phase);
395 if ((UINT32_MAX - this->
phase_[phase].cumulative_forward_active_energy_) >
val) {
401 return ((
float) this->
phase_[phase].cumulative_forward_active_energy_ * (10.0f / 3200.0f));
405 const uint16_t
val = this->
read16_(ATM90E32_REGISTER_ANENERGY + phase);
406 if (UINT32_MAX - this->
phase_[phase].cumulative_reverse_active_energy_ >
val) {
412 return ((
float) this->
phase_[phase].cumulative_reverse_active_energy_ * (10.0f / 3200.0f));
416 int val = this->
read32_(ATM90E32_REGISTER_PMEANH + phase, ATM90E32_REGISTER_PMEANHLSB + phase);
417 return val * 0.00032f;
421 uint16_t
val = this->
read16_(ATM90E32_REGISTER_PANGLE + phase) / 10.0;
422 return (
val > 180) ? (float) (
val - 360.0f) : (float)
val;
426 int16_t
val = (float) this->
read16_(ATM90E32_REGISTER_IPEAK + phase);
430 return (
val * this->
phase_[phase].ct_gain_ / 8192000.0);
434 const uint16_t freq = this->
read16_(ATM90E32_REGISTER_FREQ);
435 return (
float) freq / 100;
439 const uint16_t ctemp = this->
read16_(ATM90E32_REGISTER_TEMP);
440 return (
float) ctemp;
445 ESP_LOGW(TAG,
"[CALIBRATION] Gain calibration is disabled! Enable it first with enable_gain_calibration: true");
449 float ref_voltages[3] = {
457 ESP_LOGI(TAG,
"[CALIBRATION] ");
458 ESP_LOGI(TAG,
"[CALIBRATION] ========================= Gain Calibration =========================");
459 ESP_LOGI(TAG,
"[CALIBRATION] ---------------------------------------------------------------------");
461 "[CALIBRATION] | Phase | V_meas (V) | I_meas (A) | V_ref | I_ref | V_gain (old→new) | I_gain (old→new) |");
462 ESP_LOGI(TAG,
"[CALIBRATION] ---------------------------------------------------------------------");
464 for (uint8_t phase = 0; phase < 3; phase++) {
468 float ref_voltage = ref_voltages[phase];
469 float ref_current = ref_currents[phase];
474 bool did_voltage =
false;
475 bool did_current =
false;
478 if (ref_voltage <= 0.0f) {
479 ESP_LOGW(TAG,
"[CALIBRATION] Phase %s - Skipping voltage calibration: reference voltage is 0.",
481 }
else if (measured_voltage == 0.0f) {
482 ESP_LOGW(TAG,
"[CALIBRATION] Phase %s - Skipping voltage calibration: measured voltage is 0.",
485 uint32_t new_voltage_gain =
static_cast<uint16_t
>((ref_voltage / measured_voltage) * current_voltage_gain);
486 if (new_voltage_gain == 0) {
487 ESP_LOGW(TAG,
"[CALIBRATION] Phase %s - Voltage gain would be 0. Check reference and measured voltage.",
490 if (new_voltage_gain >= 65535) {
493 "[CALIBRATION] Phase %s - Voltage gain exceeds 65535. You may need a higher output voltage transformer.",
495 new_voltage_gain = 65535;
503 if (ref_current == 0.0f) {
504 ESP_LOGW(TAG,
"[CALIBRATION] Phase %s - Skipping current calibration: reference current is 0.",
506 }
else if (measured_current == 0.0f) {
507 ESP_LOGW(TAG,
"[CALIBRATION] Phase %s - Skipping current calibration: measured current is 0.",
510 uint32_t new_current_gain =
static_cast<uint16_t
>((ref_current / measured_current) * current_current_gain);
511 if (new_current_gain == 0) {
512 ESP_LOGW(TAG,
"[CALIBRATION] Phase %s - Current gain would be 0. Check reference and measured current.",
515 if (new_current_gain >= 65535) {
516 ESP_LOGW(TAG,
"[CALIBRATION] Phase %s - Current gain exceeds 65535. You may need to turn up pga gain.",
518 new_current_gain = 65535;
526 ESP_LOGI(TAG,
"[CALIBRATION] | %c | %9.2f | %9.4f | %5.2f | %6.4f | %5u → %-5u | %5u → %-5u |",
527 'A' + phase, measured_voltage, measured_current, ref_voltage, ref_current, current_voltage_gain,
528 did_voltage ? this->
gain_phase_[phase].voltage_gain : current_voltage_gain, current_current_gain,
529 did_current ? this->
gain_phase_[phase].current_gain : current_current_gain);
532 ESP_LOGI(TAG,
"[CALIBRATION] =====================================================================\n");
543 ESP_LOGI(TAG,
"[CALIBRATION] Gain calibration saved to memory.");
546 ESP_LOGE(TAG,
"[CALIBRATION] Failed to save gain calibration to memory!");
552 ESP_LOGW(TAG,
"[CALIBRATION] Offset calibration is disabled! Enable it first with enable_offset_calibration: true");
556 for (uint8_t phase = 0; phase < 3; phase++) {
562 ESP_LOGI(TAG,
"[CALIBRATION] Phase %c - offset_voltage: %d, offset_current: %d",
'A' + phase, voltage_offset,
573 "[CALIBRATION] Offset power calibration is disabled! Enable it first with enable_offset_calibration: true");
577 for (uint8_t phase = 0; phase < 3; ++phase) {
583 ESP_LOGI(TAG,
"[CALIBRATION] Phase %c - offset_active_power: %d, offset_reactive_power: %d",
'A' + phase,
584 active_offset, reactive_offset);
591 this->
write16_(ATM90E32_REGISTER_CFGREGACCEN, 0x55AA);
593 for (
int phase = 0; phase < 3; phase++) {
598 this->
write16_(ATM90E32_REGISTER_CFGREGACCEN, 0x0000);
611 this->
write16_(ATM90E32_REGISTER_CFGREGACCEN, 0x55AA);
614 this->
write16_(ATM90E32_REGISTER_CFGREGACCEN, 0x0000);
627 this->
write16_(ATM90E32_REGISTER_CFGREGACCEN, 0x55AA);
630 this->
write16_(ATM90E32_REGISTER_CFGREGACCEN, 0x0000);
635 ESP_LOGI(TAG,
"[CALIBRATION] Restoring saved gain calibrations to registers:");
637 for (uint8_t phase = 0; phase < 3; phase++) {
640 ESP_LOGI(TAG,
"[CALIBRATION] Phase %c - Voltage Gain: %u, Current Gain: %u",
'A' + phase, v_gain, i_gain);
647 ESP_LOGI(TAG,
"[CALIBRATION] Gain calibration loaded and verified successfully.");
650 ESP_LOGE(TAG,
"[CALIBRATION] Gain verification failed! Calibration may not be applied correctly.");
654 ESP_LOGW(TAG,
"[CALIBRATION] No stored gain calibrations found. Using config file values.");
660 ESP_LOGI(TAG,
"[CALIBRATION] Successfully restored offset calibration from memory.");
662 for (uint8_t phase = 0; phase < 3; phase++) {
665 ESP_LOGI(TAG,
"[CALIBRATION] Phase %c - offset_voltage:: %d, offset_current: %d",
'A' + phase,
666 offset.voltage_offset_, offset.current_offset_);
669 ESP_LOGW(TAG,
"[CALIBRATION] No stored offset calibrations found. Using default values.");
675 ESP_LOGI(TAG,
"[CALIBRATION] Successfully restored power offset calibration from memory.");
677 for (uint8_t phase = 0; phase < 3; ++phase) {
680 ESP_LOGI(TAG,
"[CALIBRATION] Phase %c - offset_active_power: %d, offset_reactive_power: %d",
'A' + phase,
681 offset.active_power_offset, offset.reactive_power_offset);
684 ESP_LOGW(TAG,
"[CALIBRATION] No stored power offsets found. Using default values.");
689 ESP_LOGI(TAG,
"[CALIBRATION] Clearing stored gain calibrations and restoring config-defined values...");
691 for (
int phase = 0; phase < 3; phase++) {
700 ESP_LOGI(TAG,
"[CALIBRATION] Gain calibrations cleared. Config values restored:");
701 for (
int phase = 0; phase < 3; phase++) {
702 ESP_LOGI(TAG,
"[CALIBRATION] Phase %c - Voltage Gain: %u, Current Gain: %u",
'A' + phase,
706 ESP_LOGE(TAG,
"[CALIBRATION] Failed to clear gain calibrations!");
713 for (uint8_t phase = 0; phase < 3; phase++) {
719 ESP_LOGI(TAG,
"[CALIBRATION] Offsets cleared.");
723 for (uint8_t phase = 0; phase < 3; phase++) {
729 ESP_LOGI(TAG,
"[CALIBRATION] Power offsets cleared.");
733 const uint8_t num_reads = 5;
734 uint64_t total_value = 0;
736 for (uint8_t i = 0; i < num_reads; ++i) {
737 uint32_t reading = voltage ? this->
read32_(ATM90E32_REGISTER_URMS + phase, ATM90E32_REGISTER_URMSLSB + phase)
738 : this->
read32_(ATM90E32_REGISTER_IRMS + phase, ATM90E32_REGISTER_IRMSLSB + phase);
739 total_value += reading;
742 const uint32_t average_value = total_value / num_reads;
743 const uint32_t shifted = average_value >> 7;
744 const uint32_t offset = ~shifted + 1;
745 return static_cast<int16_t
>(offset);
749 const uint8_t num_reads = 5;
750 uint64_t total_value = 0;
752 for (uint8_t i = 0; i < num_reads; ++i) {
753 uint32_t reading = reactive ? this->
read32_(ATM90E32_REGISTER_QMEAN + phase, ATM90E32_REGISTER_QMEANLSB + phase)
754 : this->
read32_(ATM90E32_REGISTER_PMEAN + phase, ATM90E32_REGISTER_PMEANLSB + phase);
755 total_value += reading;
758 const uint32_t average_value = total_value / num_reads;
759 const uint32_t power_offset = ~average_value + 1;
760 return static_cast<int16_t
>(power_offset);
765 for (uint8_t phase = 0; phase < 3; phase++) {
769 if (read_voltage != this->
gain_phase_[phase].voltage_gain ||
770 read_current != this->
gain_phase_[phase].current_gain) {
771 ESP_LOGE(TAG,
"[CALIBRATION] Mismatch detected for Phase %s!",
phase_labels[phase]);
778#ifdef USE_TEXT_SENSOR
780 uint16_t state0 = this->
read16_(ATM90E32_REGISTER_EMMSTATE0);
781 uint16_t state1 = this->
read16_(ATM90E32_REGISTER_EMMSTATE1);
783 for (
int phase = 0; phase < 3; phase++) {
787 status +=
"Over Voltage; ";
789 status +=
"Voltage Sag; ";
794 const char *phase_name = sensor ? sensor->
get_name().
c_str() :
"Unknown Phase";
798 ESP_LOGW(TAG,
"%s: %s", phase_name,
status.c_str());
799 if (sensor !=
nullptr)
800 sensor->publish_state(
status);
802 if (sensor !=
nullptr)
803 sensor->publish_state(
"Okay");
809 uint16_t state1 = this->
read16_(ATM90E32_REGISTER_EMMSTATE1);
811 std::string freq_status;
813 if (state1 & ATM90E32_STATUS_S1_FREQHIST) {
814 freq_status =
"HIGH";
815 }
else if (state1 & ATM90E32_STATUS_S1_FREQLOST) {
818 freq_status =
"Normal";
820 ESP_LOGW(TAG,
"Frequency status: %s", freq_status.c_str());
828 constexpr float max_current_threshold = 65.53f;
830 for (uint8_t phase = 0; phase < 3; phase++) {
834 if (current_val > max_current_threshold) {
835 ESP_LOGW(TAG,
"Over current detected on Phase %c: %.2f A",
'A' + phase, current_val);
836 ESP_LOGW(TAG,
"You may need to half your gain_ct: value & multiply the current and power values by 2");
848 float nominal_voltage = (line_freq == 60) ? 120.0f : 220.0f;
849 float target_voltage = nominal_voltage * multiplier;
851 float peak_01v = target_voltage * 100.0f * std::sqrt(2.0f);
852 float divider = (2.0f * ugain) / 32768.0f;
854 float threshold = peak_01v / divider;
856 return static_cast<uint16_t
>(threshold);
860 uint16_t last = this->
read16_(ATM90E32_REGISTER_LASTSPIDATA);
861 if (last != expected) {
862 if (context !=
nullptr) {
863 ESP_LOGW(TAG,
"[%s] SPI read mismatch: expected 0x%04X, got 0x%04X", context, expected, last);
865 ESP_LOGW(TAG,
"SPI read mismatch: expected 0x%04X, got 0x%04X", expected, last);
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message="unspecified")
void status_clear_warning()
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
const StringRef & get_name() const
virtual std::string dump_summary() const =0
constexpr const char * c_str() const
bool enable_offset_calibration_
float get_local_phase_reactive_power_(uint8_t phase)
float get_phase_forward_active_energy_(uint8_t phase)
sensor::Sensor * freq_sensor_
void run_gain_calibrations()
float get_phase_current_avg_(uint8_t phase)
float get_local_phase_apparent_power_(uint8_t phase)
text_sensor::TextSensor * freq_status_text_sensor_
ESPPreferenceObject power_offset_pref_
const uint16_t voltage_gain_registers[3]
float get_phase_voltage_avg_(uint8_t phase)
void write_power_offsets_to_registers_(uint8_t phase, int16_t p_offset, int16_t q_offset)
const uint16_t current_gain_registers[3]
void run_offset_calibrations()
float get_reference_voltage(uint8_t phase)
struct esphome::atm90e32::ATM90E32Component::GainCalibration gain_phase_[3]
bool get_publish_interval_flag_()
const uint16_t current_offset_registers[3]
static const uint8_t PHASEB
float get_phase_reverse_active_energy_(uint8_t phase)
float get_local_phase_harmonic_active_power_(uint8_t phase)
void check_phase_status()
float get_phase_angle_(uint8_t phase)
float get_local_phase_current_(uint8_t phase)
bool validate_spi_read_(uint16_t expected, const char *context=nullptr)
void restore_offset_calibrations_()
const uint16_t reactive_power_offset_registers[3]
const uint16_t over_voltage_flags[3]
void clear_power_offset_calibrations()
float get_phase_voltage_(uint8_t phase)
float get_chip_temperature_()
int16_t calibrate_offset(uint8_t phase, bool voltage)
float get_local_phase_reverse_active_energy_(uint8_t phase)
void dump_config() override
void restore_gain_calibrations_()
float get_local_phase_forward_active_energy_(uint8_t phase)
bool peak_current_signed_
struct esphome::atm90e32::ATM90E32Component::OffsetCalibration offset_phase_[3]
void restore_power_offset_calibrations_()
uint16_t calculate_voltage_threshold(int line_freq, uint16_t ugain, float multiplier)
float get_local_phase_power_factor_(uint8_t phase)
float get_phase_reactive_power_(uint8_t phase)
void clear_offset_calibrations()
const uint16_t phase_loss_flags[3]
float get_phase_apparent_power_(uint8_t phase)
void write_gains_to_registers_()
float get_local_phase_voltage_(uint8_t phase)
void check_over_current()
void write16_(uint16_t a_register, uint16_t val)
ESPPreferenceObject gain_calibration_pref_
void write_offsets_to_registers_(uint8_t phase, int16_t voltage_offset, int16_t current_offset)
static const uint8_t PHASEA
struct esphome::atm90e32::ATM90E32Component::PowerOffsetCalibration power_offset_phase_[3]
float get_reference_current(uint8_t phase)
bool verify_gain_writes_()
bool using_saved_calibrations_
float get_phase_peak_current_(uint8_t phase)
void clear_gain_calibrations()
float get_phase_harmonic_active_power_(uint8_t phase)
const uint16_t voltage_sag_flags[3]
float get_phase_active_power_(uint8_t phase)
void run_power_offset_calibrations()
bool enable_gain_calibration_
static const uint8_t PHASEC
const uint16_t power_offset_registers[3]
float get_setup_priority() const override
uint16_t read16_(uint16_t a_register)
int read32_(uint16_t addr_h, uint16_t addr_l)
sensor::Sensor * chip_temperature_sensor_
float get_phase_power_factor_(uint8_t phase)
float get_local_phase_angle_(uint8_t phase)
const uint16_t voltage_offset_registers[3]
void save_gain_calibration_to_memory_()
text_sensor::TextSensor * phase_status_text_sensor_[3]
float get_phase_current_(uint8_t phase)
float get_local_phase_peak_current_(uint8_t phase)
void set_publish_interval_flag_(bool flag)
int16_t calibrate_power_offset(uint8_t phase, bool reactive)
struct esphome::atm90e32::ATM90E32Component::ATM90E32Phase phase_[3]
const char * phase_labels[3]
ESPPreferenceObject offset_pref_
float get_local_phase_active_power_(uint8_t phase)
void publish_state(float state)
Publish a new state to the front-end.
float state
This member variable stores the last state that has passed through all filters.
void write_byte16(uint16_t data)
void spi_setup() override
void write_byte(uint8_t data)
void read_array(uint8_t *data, size_t length)
void publish_state(const std::string &state)
const float IO
For components that represent GPIO pins like PCF8573.
Providing packet encoding functions for exchanging data with a remote host.
uint32_t fnv1_hash(const std::string &str)
Calculate a FNV-1 hash of str.
ESPPreferences * global_preferences
void IRAM_ATTR HOT delay_microseconds_safe(uint32_t us)
Delay for the given amount of microseconds, possibly yielding to other processes during the wait.
void IRAM_ATTR HOT delay(uint32_t ms)
uint32_t cumulative_reverse_active_energy_
float reverse_active_energy_
int16_t active_power_offset_
sensor::Sensor * reactive_power_sensor_
sensor::Sensor * peak_current_sensor_
float forward_active_energy_
sensor::Sensor * power_factor_sensor_
sensor::Sensor * phase_angle_sensor_
sensor::Sensor * apparent_power_sensor_
sensor::Sensor * power_sensor_
sensor::Sensor * current_sensor_
sensor::Sensor * forward_active_energy_sensor_
sensor::Sensor * harmonic_active_power_sensor_
int16_t reactive_power_offset_
sensor::Sensor * reverse_active_energy_sensor_
float harmonic_active_power_
sensor::Sensor * voltage_sensor_
uint32_t cumulative_forward_active_energy_
int16_t reactive_power_offset
int16_t active_power_offset