5 namespace growatt_solar {
7 static const char *
const TAG =
"growatt_solar";
9 static const uint8_t MODBUS_CMD_READ_IN_REGISTERS = 0x04;
10 static const uint8_t MODBUS_REGISTER_COUNT[] = {33, 95};
49 if (sensor ==
nullptr)
51 float value =
encode_uint16(data[i * 2], data[i * 2 + 1]) * unit;
55 auto publish_2_reg_sensor_state = [&](
sensor::Sensor *
sensor,
size_t reg1,
size_t reg2,
float unit) ->
void {
56 float value = ((
encode_uint16(data[reg1 * 2], data[reg1 * 2 + 1]) << 16) +
59 if (sensor !=
nullptr)
69 publish_1_reg_sensor_state(this->
pvs_[0].voltage_sensor_, 3, ONE_DEC_UNIT);
70 publish_1_reg_sensor_state(this->
pvs_[0].current_sensor_, 4, ONE_DEC_UNIT);
71 publish_2_reg_sensor_state(this->
pvs_[0].active_power_sensor_, 5, 6, ONE_DEC_UNIT);
73 publish_1_reg_sensor_state(this->
pvs_[1].voltage_sensor_, 7, ONE_DEC_UNIT);
74 publish_1_reg_sensor_state(this->
pvs_[1].current_sensor_, 8, ONE_DEC_UNIT);
75 publish_2_reg_sensor_state(this->
pvs_[1].active_power_sensor_, 9, 10, ONE_DEC_UNIT);
80 publish_1_reg_sensor_state(this->
phases_[0].voltage_sensor_, 14, ONE_DEC_UNIT);
81 publish_1_reg_sensor_state(this->
phases_[0].current_sensor_, 15, ONE_DEC_UNIT);
82 publish_2_reg_sensor_state(this->
phases_[0].active_power_sensor_, 16, 17, ONE_DEC_UNIT);
84 publish_1_reg_sensor_state(this->
phases_[1].voltage_sensor_, 18, ONE_DEC_UNIT);
85 publish_1_reg_sensor_state(this->
phases_[1].current_sensor_, 19, ONE_DEC_UNIT);
86 publish_2_reg_sensor_state(this->
phases_[1].active_power_sensor_, 20, 21, ONE_DEC_UNIT);
88 publish_1_reg_sensor_state(this->
phases_[2].voltage_sensor_, 22, ONE_DEC_UNIT);
89 publish_1_reg_sensor_state(this->
phases_[2].current_sensor_, 23, ONE_DEC_UNIT);
90 publish_2_reg_sensor_state(this->
phases_[2].active_power_sensor_, 24, 25, ONE_DEC_UNIT);
103 publish_1_reg_sensor_state(this->
pvs_[0].voltage_sensor_, 3, ONE_DEC_UNIT);
104 publish_1_reg_sensor_state(this->
pvs_[0].current_sensor_, 4, ONE_DEC_UNIT);
105 publish_2_reg_sensor_state(this->
pvs_[0].active_power_sensor_, 5, 6, ONE_DEC_UNIT);
107 publish_1_reg_sensor_state(this->
pvs_[1].voltage_sensor_, 7, ONE_DEC_UNIT);
108 publish_1_reg_sensor_state(this->
pvs_[1].current_sensor_, 8, ONE_DEC_UNIT);
109 publish_2_reg_sensor_state(this->
pvs_[1].active_power_sensor_, 9, 10, ONE_DEC_UNIT);
114 publish_1_reg_sensor_state(this->
phases_[0].voltage_sensor_, 38, ONE_DEC_UNIT);
115 publish_1_reg_sensor_state(this->
phases_[0].current_sensor_, 39, ONE_DEC_UNIT);
116 publish_2_reg_sensor_state(this->
phases_[0].active_power_sensor_, 40, 41, ONE_DEC_UNIT);
118 publish_1_reg_sensor_state(this->
phases_[1].voltage_sensor_, 42, ONE_DEC_UNIT);
119 publish_1_reg_sensor_state(this->
phases_[1].current_sensor_, 43, ONE_DEC_UNIT);
120 publish_2_reg_sensor_state(this->
phases_[1].active_power_sensor_, 44, 45, ONE_DEC_UNIT);
122 publish_1_reg_sensor_state(this->
phases_[2].voltage_sensor_, 46, ONE_DEC_UNIT);
123 publish_1_reg_sensor_state(this->
phases_[2].current_sensor_, 47, ONE_DEC_UNIT);
124 publish_2_reg_sensor_state(this->
phases_[2].active_power_sensor_, 48, 49, ONE_DEC_UNIT);
136 ESP_LOGCONFIG(TAG,
"GROWATT Solar:");
137 ESP_LOGCONFIG(TAG,
" Address: 0x%02X", this->
address_);
struct esphome::growatt_solar::GrowattSolar::GrowattPhase phases_[3]
struct esphome::growatt_solar::GrowattSolar::GrowattPV pvs_[2]
sensor::Sensor * today_production_
uint32_t IRAM_ATTR HOT millis()
bool waiting_for_response()
sensor::Sensor * inverter_status_
void dump_config() override
sensor::Sensor * pv_active_power_sensor_
sensor::Sensor * grid_active_power_sensor_
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * grid_frequency_sensor_
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
virtual uint32_t get_update_interval() const
Get the update interval in ms of this sensor.
GrowattProtocolVersion protocol_version_
void on_modbus_data(const std::vector< uint8_t > &data) override
Implementation of SPI Controller mode.
sensor::Sensor * total_energy_production_
void send(uint8_t function, uint16_t start_address, uint16_t number_of_entities, uint8_t payload_len=0, const uint8_t *payload=nullptr)
Base-class for all sensors.
esphome::sensor::Sensor * sensor
sensor::Sensor * inverter_module_temp_