15 if (data.size() < MODBUS_REGISTER_COUNT * 2) {
16 ESP_LOGW(TAG,
"Invalid size for SelecMeter!");
20 auto selec_meter_get_float = [&](
size_t i,
float unit) ->
float {
21 uint32_t temp =
encode_uint32(data[i + 2], data[i + 3], data[i], data[i + 1]);
24 memcpy(&f, &temp,
sizeof(f));
28 float total_active_energy = selec_meter_get_float(SELEC_TOTAL_ACTIVE_ENERGY * 2, NO_DEC_UNIT);
29 float import_active_energy = selec_meter_get_float(SELEC_IMPORT_ACTIVE_ENERGY * 2, NO_DEC_UNIT);
30 float export_active_energy = selec_meter_get_float(SELEC_EXPORT_ACTIVE_ENERGY * 2, NO_DEC_UNIT);
31 float total_reactive_energy = selec_meter_get_float(SELEC_TOTAL_REACTIVE_ENERGY * 2, NO_DEC_UNIT);
32 float import_reactive_energy = selec_meter_get_float(SELEC_IMPORT_REACTIVE_ENERGY * 2, NO_DEC_UNIT);
33 float export_reactive_energy = selec_meter_get_float(SELEC_EXPORT_REACTIVE_ENERGY * 2, NO_DEC_UNIT);
34 float apparent_energy = selec_meter_get_float(SELEC_APPARENT_ENERGY * 2, NO_DEC_UNIT);
35 float active_power = selec_meter_get_float(SELEC_ACTIVE_POWER * 2, MULTIPLY_THOUSAND_UNIT);
36 float reactive_power = selec_meter_get_float(SELEC_REACTIVE_POWER * 2, MULTIPLY_THOUSAND_UNIT);
37 float apparent_power = selec_meter_get_float(SELEC_APPARENT_POWER * 2, MULTIPLY_THOUSAND_UNIT);
38 float voltage = selec_meter_get_float(SELEC_VOLTAGE * 2, NO_DEC_UNIT);
39 float current = selec_meter_get_float(SELEC_CURRENT * 2, NO_DEC_UNIT);
40 float power_factor = selec_meter_get_float(SELEC_POWER_FACTOR * 2, NO_DEC_UNIT);
41 float frequency = selec_meter_get_float(SELEC_FREQUENCY * 2, NO_DEC_UNIT);
42 float maximum_demand_active_power =
43 selec_meter_get_float(SELEC_MAXIMUM_DEMAND_ACTIVE_POWER * 2, MULTIPLY_THOUSAND_UNIT);
44 float maximum_demand_reactive_power =
45 selec_meter_get_float(SELEC_MAXIMUM_DEMAND_REACTIVE_POWER * 2, MULTIPLY_THOUSAND_UNIT);
46 float maximum_demand_apparent_power =
47 selec_meter_get_float(SELEC_MAXIMUM_DEMAND_APPARENT_POWER * 2, MULTIPLY_THOUSAND_UNIT);
49 if (this->total_active_energy_sensor_ !=
nullptr)
50 this->total_active_energy_sensor_->publish_state(total_active_energy);
51 if (this->import_active_energy_sensor_ !=
nullptr)
52 this->import_active_energy_sensor_->publish_state(import_active_energy);
53 if (this->export_active_energy_sensor_ !=
nullptr)
54 this->export_active_energy_sensor_->publish_state(export_active_energy);
55 if (this->total_reactive_energy_sensor_ !=
nullptr)
56 this->total_reactive_energy_sensor_->publish_state(total_reactive_energy);
57 if (this->import_reactive_energy_sensor_ !=
nullptr)
58 this->import_reactive_energy_sensor_->publish_state(import_reactive_energy);
59 if (this->export_reactive_energy_sensor_ !=
nullptr)
60 this->export_reactive_energy_sensor_->publish_state(export_reactive_energy);
61 if (this->apparent_energy_sensor_ !=
nullptr)
62 this->apparent_energy_sensor_->publish_state(apparent_energy);
63 if (this->active_power_sensor_ !=
nullptr)
64 this->active_power_sensor_->publish_state(active_power);
65 if (this->reactive_power_sensor_ !=
nullptr)
66 this->reactive_power_sensor_->publish_state(reactive_power);
67 if (this->apparent_power_sensor_ !=
nullptr)
68 this->apparent_power_sensor_->publish_state(apparent_power);
69 if (this->voltage_sensor_ !=
nullptr)
70 this->voltage_sensor_->publish_state(voltage);
71 if (this->current_sensor_ !=
nullptr)
72 this->current_sensor_->publish_state(current);
73 if (this->power_factor_sensor_ !=
nullptr)
74 this->power_factor_sensor_->publish_state(power_factor);
75 if (this->frequency_sensor_ !=
nullptr)
76 this->frequency_sensor_->publish_state(
frequency);
77 if (this->maximum_demand_active_power_sensor_ !=
nullptr)
78 this->maximum_demand_active_power_sensor_->publish_state(maximum_demand_active_power);
79 if (this->maximum_demand_reactive_power_sensor_ !=
nullptr)
80 this->maximum_demand_reactive_power_sensor_->publish_state(maximum_demand_reactive_power);
81 if (this->maximum_demand_apparent_power_sensor_ !=
nullptr)
82 this->maximum_demand_apparent_power_sensor_->publish_state(maximum_demand_apparent_power);
91 LOG_SENSOR(
" ",
"Total Active Energy", this->total_active_energy_sensor_);
92 LOG_SENSOR(
" ",
"Import Active Energy", this->import_active_energy_sensor_);
93 LOG_SENSOR(
" ",
"Export Active Energy", this->export_active_energy_sensor_);
94 LOG_SENSOR(
" ",
"Total Reactive Energy", this->total_reactive_energy_sensor_);
95 LOG_SENSOR(
" ",
"Import Reactive Energy", this->import_reactive_energy_sensor_);
96 LOG_SENSOR(
" ",
"Export Reactive Energy", this->export_reactive_energy_sensor_);
97 LOG_SENSOR(
" ",
"Apparent Energy", this->apparent_energy_sensor_);
98 LOG_SENSOR(
" ",
"Active Power", this->active_power_sensor_);
99 LOG_SENSOR(
" ",
"Reactive Power", this->reactive_power_sensor_);
100 LOG_SENSOR(
" ",
"Apparent Power", this->apparent_power_sensor_);
101 LOG_SENSOR(
" ",
"Voltage", this->voltage_sensor_);
102 LOG_SENSOR(
" ",
"Current", this->current_sensor_);
103 LOG_SENSOR(
" ",
"Power Factor", this->power_factor_sensor_);
104 LOG_SENSOR(
" ",
"Frequency", this->frequency_sensor_);
105 LOG_SENSOR(
" ",
"Maximum Demand Active Power", this->maximum_demand_active_power_sensor_);
106 LOG_SENSOR(
" ",
"Maximum Demand Reactive Power", this->maximum_demand_reactive_power_sensor_);
107 LOG_SENSOR(
" ",
"Maximum Demand Apparent Power", this->maximum_demand_apparent_power_sensor_);