ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
pipsolar.h
Go to the documentation of this file.
1#pragma once
2
11
12namespace esphome::pipsolar {
13
30
32 esphome::optional<bool> silence_buzzer_open_buzzer;
33 esphome::optional<bool> overload_bypass_function;
34 esphome::optional<bool> lcd_escape_to_default;
35 esphome::optional<bool> overload_restart_function;
36 esphome::optional<bool> over_temperature_restart_function;
37 esphome::optional<bool> backlight_on;
39 esphome::optional<bool> fault_code_record;
40 esphome::optional<bool> power_saving;
41};
42
43#define PIPSOLAR_ENTITY_(type, name, polling_command) \
44 protected: \
45 type *name##_{}; /* NOLINT */ \
46\
47 public: \
48 void set_##name(type *name) { /* NOLINT */ \
49 this->name##_ = name; \
50 this->add_polling_command_(#polling_command, POLLING_##polling_command); \
51 }
52
53#define PIPSOLAR_SENSOR(name, polling_command) PIPSOLAR_ENTITY_(sensor::Sensor, name, polling_command)
54#define PIPSOLAR_SWITCH(name, polling_command) PIPSOLAR_ENTITY_(switch_::Switch, name, polling_command)
55#define PIPSOLAR_BINARY_SENSOR(name, polling_command) \
56 PIPSOLAR_ENTITY_(binary_sensor::BinarySensor, name, polling_command)
57#define PIPSOLAR_TEXT_SENSOR(name, polling_command) PIPSOLAR_ENTITY_(text_sensor::TextSensor, name, polling_command)
58
60 // QPIGS values
61 PIPSOLAR_SENSOR(grid_voltage, QPIGS)
62 PIPSOLAR_SENSOR(grid_frequency, QPIGS)
63 PIPSOLAR_SENSOR(ac_output_voltage, QPIGS)
64 PIPSOLAR_SENSOR(ac_output_frequency, QPIGS)
65 PIPSOLAR_SENSOR(ac_output_apparent_power, QPIGS)
66 PIPSOLAR_SENSOR(ac_output_active_power, QPIGS)
67 PIPSOLAR_SENSOR(output_load_percent, QPIGS)
68 PIPSOLAR_SENSOR(bus_voltage, QPIGS)
69 PIPSOLAR_SENSOR(battery_voltage, QPIGS)
70 PIPSOLAR_SENSOR(battery_charging_current, QPIGS)
71 PIPSOLAR_SENSOR(battery_capacity_percent, QPIGS)
72 PIPSOLAR_SENSOR(inverter_heat_sink_temperature, QPIGS)
73 PIPSOLAR_SENSOR(pv_input_current_for_battery, QPIGS)
74 PIPSOLAR_SENSOR(pv_input_voltage, QPIGS)
75 PIPSOLAR_SENSOR(battery_voltage_scc, QPIGS)
76 PIPSOLAR_SENSOR(battery_discharge_current, QPIGS)
77 PIPSOLAR_BINARY_SENSOR(add_sbu_priority_version, QPIGS)
78 PIPSOLAR_BINARY_SENSOR(configuration_status, QPIGS)
79 PIPSOLAR_BINARY_SENSOR(scc_firmware_version, QPIGS)
80 PIPSOLAR_BINARY_SENSOR(load_status, QPIGS)
81 PIPSOLAR_BINARY_SENSOR(battery_voltage_to_steady_while_charging, QPIGS)
82 PIPSOLAR_BINARY_SENSOR(charging_status, QPIGS)
83 PIPSOLAR_BINARY_SENSOR(scc_charging_status, QPIGS)
84 PIPSOLAR_BINARY_SENSOR(ac_charging_status, QPIGS)
85 PIPSOLAR_SENSOR(battery_voltage_offset_for_fans_on, QPIGS) //.1 scale
86 PIPSOLAR_SENSOR(eeprom_version, QPIGS)
87 PIPSOLAR_SENSOR(pv_charging_power, QPIGS)
88 PIPSOLAR_BINARY_SENSOR(charging_to_floating_mode, QPIGS)
89 PIPSOLAR_BINARY_SENSOR(switch_on, QPIGS)
90 PIPSOLAR_BINARY_SENSOR(dustproof_installed, QPIGS)
91
92 // QPIRI values
93 PIPSOLAR_SENSOR(grid_rating_voltage, QPIRI)
94 PIPSOLAR_SENSOR(grid_rating_current, QPIRI)
95 PIPSOLAR_SENSOR(ac_output_rating_voltage, QPIRI)
96 PIPSOLAR_SENSOR(ac_output_rating_frequency, QPIRI)
97 PIPSOLAR_SENSOR(ac_output_rating_current, QPIRI)
98 PIPSOLAR_SENSOR(ac_output_rating_apparent_power, QPIRI)
99 PIPSOLAR_SENSOR(ac_output_rating_active_power, QPIRI)
100 PIPSOLAR_SENSOR(battery_rating_voltage, QPIRI)
101 PIPSOLAR_SENSOR(battery_recharge_voltage, QPIRI)
102 PIPSOLAR_SENSOR(battery_under_voltage, QPIRI)
103 PIPSOLAR_SENSOR(battery_bulk_voltage, QPIRI)
104 PIPSOLAR_SENSOR(battery_float_voltage, QPIRI)
105 PIPSOLAR_SENSOR(battery_type, QPIRI)
106 PIPSOLAR_SENSOR(current_max_ac_charging_current, QPIRI)
107 PIPSOLAR_SENSOR(current_max_charging_current, QPIRI)
108 PIPSOLAR_SENSOR(input_voltage_range, QPIRI)
109 PIPSOLAR_SENSOR(output_source_priority, QPIRI)
110 PIPSOLAR_SENSOR(charger_source_priority, QPIRI)
111 PIPSOLAR_SENSOR(parallel_max_num, QPIRI)
112 PIPSOLAR_SENSOR(machine_type, QPIRI)
113 PIPSOLAR_SENSOR(topology, QPIRI)
114 PIPSOLAR_SENSOR(output_mode, QPIRI)
115 PIPSOLAR_SENSOR(battery_redischarge_voltage, QPIRI)
116 PIPSOLAR_SENSOR(pv_ok_condition_for_parallel, QPIRI)
117 PIPSOLAR_SENSOR(pv_power_balance, QPIRI)
118
119 // QMOD values
120 PIPSOLAR_TEXT_SENSOR(device_mode, QMOD)
121
122 // QFLAG values
123 PIPSOLAR_BINARY_SENSOR(silence_buzzer_open_buzzer, QFLAG)
124 PIPSOLAR_BINARY_SENSOR(overload_bypass_function, QFLAG)
125 PIPSOLAR_BINARY_SENSOR(lcd_escape_to_default, QFLAG)
126 PIPSOLAR_BINARY_SENSOR(overload_restart_function, QFLAG)
127 PIPSOLAR_BINARY_SENSOR(over_temperature_restart_function, QFLAG)
128 PIPSOLAR_BINARY_SENSOR(backlight_on, QFLAG)
129 PIPSOLAR_BINARY_SENSOR(alarm_on_when_primary_source_interrupt, QFLAG)
130 PIPSOLAR_BINARY_SENSOR(fault_code_record, QFLAG)
131 PIPSOLAR_BINARY_SENSOR(power_saving, QFLAG)
132
133 // QPIWS values
134 PIPSOLAR_BINARY_SENSOR(warnings_present, QPIWS)
135 PIPSOLAR_BINARY_SENSOR(faults_present, QPIWS)
136 PIPSOLAR_BINARY_SENSOR(warning_power_loss, QPIWS)
137 PIPSOLAR_BINARY_SENSOR(fault_inverter_fault, QPIWS)
138 PIPSOLAR_BINARY_SENSOR(fault_bus_over, QPIWS)
139 PIPSOLAR_BINARY_SENSOR(fault_bus_under, QPIWS)
140 PIPSOLAR_BINARY_SENSOR(fault_bus_soft_fail, QPIWS)
141 PIPSOLAR_BINARY_SENSOR(warning_line_fail, QPIWS)
142 PIPSOLAR_BINARY_SENSOR(fault_opvshort, QPIWS)
143 PIPSOLAR_BINARY_SENSOR(fault_inverter_voltage_too_low, QPIWS)
144 PIPSOLAR_BINARY_SENSOR(fault_inverter_voltage_too_high, QPIWS)
145 PIPSOLAR_BINARY_SENSOR(warning_over_temperature, QPIWS)
146 PIPSOLAR_BINARY_SENSOR(warning_fan_lock, QPIWS)
147 PIPSOLAR_BINARY_SENSOR(warning_battery_voltage_high, QPIWS)
148 PIPSOLAR_BINARY_SENSOR(warning_battery_low_alarm, QPIWS)
149 PIPSOLAR_BINARY_SENSOR(warning_battery_under_shutdown, QPIWS)
150 PIPSOLAR_BINARY_SENSOR(warning_battery_derating, QPIWS)
151 PIPSOLAR_BINARY_SENSOR(warning_over_load, QPIWS)
152 PIPSOLAR_BINARY_SENSOR(warning_eeprom_failed, QPIWS)
153 PIPSOLAR_BINARY_SENSOR(fault_inverter_over_current, QPIWS)
154 PIPSOLAR_BINARY_SENSOR(fault_inverter_soft_failed, QPIWS)
155 PIPSOLAR_BINARY_SENSOR(fault_self_test_failed, QPIWS)
156 PIPSOLAR_BINARY_SENSOR(fault_op_dc_voltage_over, QPIWS)
157 PIPSOLAR_BINARY_SENSOR(fault_battery_open, QPIWS)
158 PIPSOLAR_BINARY_SENSOR(fault_current_sensor_failed, QPIWS)
159 PIPSOLAR_BINARY_SENSOR(fault_battery_short, QPIWS)
160 PIPSOLAR_BINARY_SENSOR(warning_power_limit, QPIWS)
161 PIPSOLAR_BINARY_SENSOR(warning_pv_voltage_high, QPIWS)
162 PIPSOLAR_BINARY_SENSOR(fault_mppt_overload, QPIWS)
163 PIPSOLAR_BINARY_SENSOR(warning_mppt_overload, QPIWS)
164 PIPSOLAR_BINARY_SENSOR(warning_battery_too_low_to_charge, QPIWS)
165 PIPSOLAR_BINARY_SENSOR(fault_dc_dc_over_current, QPIWS)
166 PIPSOLAR_BINARY_SENSOR(fault_code, QPIWS)
167 PIPSOLAR_BINARY_SENSOR(warning_low_pv_energy, QPIWS)
168 PIPSOLAR_BINARY_SENSOR(warning_high_ac_input_during_bus_soft_start, QPIWS)
169 PIPSOLAR_BINARY_SENSOR(warning_battery_equalization, QPIWS)
170
171 PIPSOLAR_TEXT_SENSOR(last_qpigs, QPIGS)
172 PIPSOLAR_TEXT_SENSOR(last_qpiri, QPIRI)
173 PIPSOLAR_TEXT_SENSOR(last_qmod, QMOD)
174 PIPSOLAR_TEXT_SENSOR(last_qflag, QFLAG)
175 PIPSOLAR_TEXT_SENSOR(last_qpiws, QPIWS)
176 PIPSOLAR_TEXT_SENSOR(last_qt, QT)
177 PIPSOLAR_TEXT_SENSOR(last_qmn, QMN)
178
179 PIPSOLAR_SWITCH(output_source_priority_utility_switch, QPIRI)
180 PIPSOLAR_SWITCH(output_source_priority_solar_switch, QPIRI)
181 PIPSOLAR_SWITCH(output_source_priority_battery_switch, QPIRI)
182 PIPSOLAR_SWITCH(output_source_priority_hybrid_switch, QPIRI)
183 PIPSOLAR_SWITCH(input_voltage_range_switch, QPIRI)
184 PIPSOLAR_SWITCH(pv_ok_condition_for_parallel_switch, QPIRI)
185 PIPSOLAR_SWITCH(pv_power_balance_switch, QPIRI)
186
187 void queue_command(const std::string &command);
188 void setup() override;
189 void loop() override;
190 void dump_config() override;
191 void update() override;
192
193 protected:
194 static const size_t PIPSOLAR_READ_BUFFER_LENGTH = 128; // maximum supported answer length
195 static const size_t COMMAND_QUEUE_LENGTH = 10;
196 static const size_t COMMAND_TIMEOUT = 5000;
197 static const size_t POLLING_COMMANDS_MAX = 15;
198 void add_polling_command_(const char *command, ENUMPollingCommand polling_command);
199 void empty_uart_buffer_();
200 uint8_t check_incoming_crc_();
201 uint8_t check_incoming_length_(uint8_t length);
202 uint16_t pipsolar_crc_(uint8_t *msg, uint8_t len);
203 bool send_next_command_();
204 bool send_next_poll_();
205
206 void handle_poll_response_(ENUMPollingCommand polling_command, const char *message);
207 void handle_poll_error_(ENUMPollingCommand polling_command);
208 // these handlers are designed in a way that an empty message sets all sensors to unknown
209 void handle_qpiri_(const char *message);
210 void handle_qpigs_(const char *message);
211 void handle_qmod_(const char *message);
212 void handle_qflag_(const char *message);
213 void handle_qpiws_(const char *message);
214 void handle_qt_(const char *message);
215 void handle_qmn_(const char *message);
216
217 void skip_start_(const char *message, size_t *pos);
218 void skip_field_(const char *message, size_t *pos);
219 std::string read_field_(const char *message, size_t *pos);
220
221 void read_float_sensor_(const char *message, size_t *pos, sensor::Sensor *sensor);
222 void read_int_sensor_(const char *message, size_t *pos, sensor::Sensor *sensor);
223
224 void publish_binary_sensor_(esphome::optional<bool> b, binary_sensor::BinarySensor *sensor);
225
226 esphome::optional<bool> get_bit_(std::string bits, uint8_t bit_pos);
227
231 size_t read_pos_{0};
232
234 uint8_t state_;
243
246};
247
248} // namespace esphome::pipsolar
This class simplifies creating components that periodically check a state.
Definition component.h:602
Base class for all binary_sensor-type classes.
static const size_t COMMAND_QUEUE_LENGTH
Definition pipsolar.h:195
void handle_qmod_(const char *message)
Definition pipsolar.cpp:434
uint8_t read_buffer_[PIPSOLAR_READ_BUFFER_LENGTH]
Definition pipsolar.h:230
uint16_t pipsolar_crc_(uint8_t *msg, uint8_t len)
Definition pipsolar.cpp:801
void handle_poll_error_(ENUMPollingCommand polling_command)
Definition pipsolar.cpp:293
void handle_qpiws_(const char *message)
Definition pipsolar.cpp:509
esphome::optional< bool > get_bit_(std::string bits, uint8_t bit_pos)
Definition pipsolar.cpp:754
void handle_qt_(const char *message)
Definition pipsolar.cpp:679
uint8_t check_incoming_length_(uint8_t length)
Definition pipsolar.cpp:163
void handle_qpigs_(const char *message)
Definition pipsolar.cpp:381
void handle_poll_response_(ENUMPollingCommand polling_command, const char *message)
Definition pipsolar.cpp:266
static const size_t PIPSOLAR_READ_BUFFER_LENGTH
Definition pipsolar.h:194
std::string read_field_(const char *message, size_t *pos)
Definition pipsolar.cpp:706
std::string command_queue_[COMMAND_QUEUE_LENGTH]
Definition pipsolar.h:228
void read_int_sensor_(const char *message, size_t *pos, sensor::Sensor *sensor)
Definition pipsolar.cpp:734
void read_float_sensor_(const char *message, size_t *pos, sensor::Sensor *sensor)
Definition pipsolar.cpp:726
void handle_qflag_(const char *message)
Definition pipsolar.cpp:450
void skip_field_(const char *message, size_t *pos)
Definition pipsolar.cpp:696
void handle_qpiri_(const char *message)
Definition pipsolar.cpp:298
PollingCommand enabled_polling_commands_[POLLING_COMMANDS_MAX]
Definition pipsolar.h:245
void publish_binary_sensor_(esphome::optional< bool > b, binary_sensor::BinarySensor *sensor)
Definition pipsolar.cpp:744
static const size_t POLLING_COMMANDS_MAX
Definition pipsolar.h:197
void skip_start_(const char *message, size_t *pos)
Definition pipsolar.cpp:691
static const size_t COMMAND_TIMEOUT
Definition pipsolar.h:196
void add_polling_command_(const char *command, ENUMPollingCommand polling_command)
Definition pipsolar.cpp:777
void handle_qmn_(const char *message)
Definition pipsolar.cpp:685
Base-class for all sensors.
Definition sensor.h:47
const char * message
Definition component.cpp:35
std::string size_t len
size_t size_t pos
Definition helpers.h:1038
static void uint32_t
ENUMPollingCommand identifier
Definition pipsolar.h:27
esphome::optional< bool > overload_bypass_function
Definition pipsolar.h:33
esphome::optional< bool > alarm_on_when_primary_source_interrupt
Definition pipsolar.h:38
esphome::optional< bool > backlight_on
Definition pipsolar.h:37
esphome::optional< bool > lcd_escape_to_default
Definition pipsolar.h:34
esphome::optional< bool > fault_code_record
Definition pipsolar.h:39
esphome::optional< bool > over_temperature_restart_function
Definition pipsolar.h:36
esphome::optional< bool > silence_buzzer_open_buzzer
Definition pipsolar.h:32
esphome::optional< bool > overload_restart_function
Definition pipsolar.h:35
esphome::optional< bool > power_saving
Definition pipsolar.h:40
uint16_t length
Definition tt21100.cpp:0