-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpylontech-8-battery.yaml
More file actions
439 lines (377 loc) · 10.7 KB
/
Copy pathpylontech-8-battery.yaml
File metadata and controls
439 lines (377 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
esphome:
name: "pylontech"
friendly_name: Pylontech
esp8266:
board: esp01_1m
# Enable logging
logger:
baud_rate: 0
# Enable Home Assistant API
api:
encryption:
key: !secret pylontech_api_key
ota:
platform: esphome
password: !secret pylontech_ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Pylontech172 Fallback Hotspot"
password: "password"
captive_portal:
# Example configuration entry
web_server:
port: 80
auth:
username: admin
password: admin
uart:
id: uart_bus
tx_pin: 1
rx_pin: 3
baud_rate: 115200
rx_buffer_size: 2048
debug:
direction: both
dummy_receiver: true
after:
delimiter: "\n"
sequence:
- lambda: |-
UARTDebug::log_string(direction, bytes); // Logs the data line
std::string str(bytes.begin(), bytes.end());
int intValue = 0;
// PWRSYS system SOC
if (sscanf(str.c_str(), " System SOC : %d %%", &intValue) == 1) {
id(pwrsys_soh).publish_state(intValue);
return;
}
// PWRSYS average temperature
if (sscanf(str.c_str(), " Average temperature : %d mC", &intValue) == 1) {
id(pwrsys_average_Temp).publish_state(intValue);
return;
}
// PWRSYS highest temperature
if (sscanf(str.c_str(), " Highest temperature : %d mC", &intValue) == 1) {
id(pwrsys_high_Temp).publish_state(intValue);
return;
}
// PWRSYS lowest temperature
if (sscanf(str.c_str(), " Lowest temperature : %d mC", &intValue) == 1) {
id(pwrsys_low_Temp).publish_state(intValue);
return;
}
// PWRSYS average voltage
if (sscanf(str.c_str(), " Average voltage : %d mV", &intValue) == 1) {
id(pwrsys_average_voltage).publish_state(intValue);
return;
}
// PWRSYS lowest voltage
if (sscanf(str.c_str(), " Lowest voltage : %d mV", &intValue) == 1) {
id(pwrsys_lowest_voltage).publish_state(intValue);
return;
}
// PWRSYS highest voltage
if (sscanf(str.c_str(), " Highest voltage : %d mV", &intValue) == 1) {
id(pwrsys_highest_voltage).publish_state(intValue);
return;
}
// PWRSYS system voltage
if (sscanf(str.c_str(), " System Volt : %d mV", &intValue) == 1) {
id(pwrsys_system_voltage).publish_state(intValue);
return;
}
// STAT SOC (Pwr Percent)
if (sscanf(str.c_str(), "Pwr Percent :%d", &intValue) == 1) {
id(statSOC).publish_state(intValue);
return;
}
// Battery data lines:
// Format:
// 1 50601 11458 18200 14500 15400 3369 3376 Charge Normal Normal Normal 71% ...
// Pattern to extract battery_num (1), Tempr(4th col), and SOC(13th col):
int battery_num, temp_mC, soc;
if (sscanf(
str.c_str(),
"%d %*d %*d %d %*d %*d %*d %*d %*s %*s %*s %*s %d%%",
&battery_num, &temp_mC, &soc
) == 3) {
if (battery_num >= 1 && battery_num <= 8) {
switch (battery_num) {
case 1:
id(battery_1_soc).publish_state(soc);
id(battery_1_temp).publish_state(temp_mC);
break;
case 2:
id(battery_2_soc).publish_state(soc);
id(battery_2_temp).publish_state(temp_mC);
break;
case 3:
id(battery_3_soc).publish_state(soc);
id(battery_3_temp).publish_state(temp_mC);
break;
case 4:
id(battery_4_soc).publish_state(soc);
id(battery_4_temp).publish_state(temp_mC);
break;
case 5:
id(battery_5_soc).publish_state(soc);
id(battery_5_temp).publish_state(temp_mC);
break;
case 6:
id(battery_6_soc).publish_state(soc);
id(battery_6_temp).publish_state(temp_mC);
break;
case 7:
id(battery_7_soc).publish_state(soc);
id(battery_7_temp).publish_state(temp_mC);
break;
case 8:
id(battery_8_soc).publish_state(soc);
id(battery_8_temp).publish_state(temp_mC);
break;
}
}
return;
}
sensor:
# Existing pwrsys and stat sensors
- platform: template
name: "STAT-SOC"
id: statSOC
unit_of_measurement: "%"
accuracy_decimals: 1
- platform: template
name: "PWRSYS-SOC"
id: pwrsys_soh
unit_of_measurement: "%"
accuracy_decimals: 1
- platform: template
name: "PWRSYS-Temperature Adverage"
unit_of_measurement: "°C"
id: pwrsys_average_Temp
filters:
- multiply: 0.001
- platform: template
name: "PWRSYS-Temperature High"
id: pwrsys_high_Temp
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- multiply: 0.001
- platform: template
name: "PWRSYS-Temperature Low"
id: pwrsys_low_Temp
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- multiply: 0.001
- platform: template
name: "PWRSYS-Voltage Average"
id: pwrsys_average_voltage
unit_of_measurement: "V"
accuracy_decimals: 3
device_class: voltage
filters:
- multiply: 0.001
- platform: template
name: "PWRSYS-Voltage Lowest"
id: pwrsys_lowest_voltage
unit_of_measurement: "V"
accuracy_decimals: 3
device_class: voltage
filters:
- multiply: 0.001
- platform: template
name: "PWRSYS-Voltage Highest"
id: pwrsys_highest_voltage
unit_of_measurement: "V"
accuracy_decimals: 3
device_class: voltage
filters:
- multiply: 0.001
- platform: template
name: "PWRSYS-System Voltage"
id: pwrsys_system_voltage
unit_of_measurement: "V"
accuracy_decimals: 3
device_class: voltage
filters:
- multiply: 0.001
# Battery SOC and Temperature for 8 batteries
- platform: template
name: "Battery 1 SOC"
id: battery_1_soc
unit_of_measurement: "%"
accuracy_decimals: 0
- platform: template
name: "Battery 1 Temperature"
id: battery_1_temp
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- multiply: 0.001
- platform: template
name: "Battery 2 SOC"
id: battery_2_soc
unit_of_measurement: "%"
accuracy_decimals: 0
- platform: template
name: "Battery 2 Temperature"
id: battery_2_temp
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- multiply: 0.001
- platform: template
name: "Battery 3 SOC"
id: battery_3_soc
unit_of_measurement: "%"
accuracy_decimals: 0
- platform: template
name: "Battery 3 Temperature"
id: battery_3_temp
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- multiply: 0.001
- platform: template
name: "Battery 4 SOC"
id: battery_4_soc
unit_of_measurement: "%"
accuracy_decimals: 0
- platform: template
name: "Battery 4 Temperature"
id: battery_4_temp
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- multiply: 0.001
- platform: template
name: "Battery 5 SOC"
id: battery_5_soc
unit_of_measurement: "%"
accuracy_decimals: 0
- platform: template
name: "Battery 5 Temperature"
id: battery_5_temp
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- multiply: 0.001
- platform: template
name: "Battery 6 SOC"
id: battery_6_soc
unit_of_measurement: "%"
accuracy_decimals: 0
- platform: template
name: "Battery 6 Temperature"
id: battery_6_temp
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- multiply: 0.001
- platform: template
name: "Battery 7 SOC"
id: battery_7_soc
unit_of_measurement: "%"
accuracy_decimals: 0
- platform: template
name: "Battery 7 Temperature"
id: battery_7_temp
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- multiply: 0.001
- platform: template
name: "Battery 8 SOC"
id: battery_8_soc
unit_of_measurement: "%"
accuracy_decimals: 0
- platform: template
name: "Battery 8 Temperature"
id: battery_8_temp
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- multiply: 0.001
button:
- platform: template
name: "BUTTON-info"
on_press:
- uart.write: "info\r\n"
- platform: template
name: "BUTTON-power"
on_press:
- uart.write: "pwr\r\n"
- platform: template
name: "BUTTON-data"
on_press:
- uart.write: "data\r\n"
- platform: template
name: "BUTTON-stat"
on_press:
- uart.write: "stat\r\n"
- platform: template
name: "BUTTON-bat"
on_press:
- uart.write: "bat\r\n"
- platform: template
name: "BUTTON-Login Debug"
on_press:
- uart.write: "login debug\r\n"
- platform: template
name: "BUTTON-Power System Information (pwrsys)"
on_press:
- uart.write: "pwrsys\r\n"
- platform: template
name: "BUTTON-Logout"
on_press:
- uart.write: "logout\r\n"
- platform: template
name: "BUTTON-unit"
on_press:
- uart.write: "unit\r\n"
interval:
- interval: 1200s
then:
- logger.log:
level: INFO
format: "Sending info command to the system"
- logger.log:
level: INFO
format: "this has sent the info command"
- uart.write: "info\r\n"
- delay: 2s
- interval: 12000s
then:
- logger.log:
level: INFO
format: "Testing pwr commands"
- logger.log:
level: INFO
format: "This has send the pwr command"
- uart.write: "pwr\r\n"
- delay: 2s
- interval: 300s
then:
- logger.log:
level: INFO
format: "Testing pwrsys commands"
- logger.log:
level: INFO
format: "This has send the pwrsys command"
- uart.write: "pwrsys\r\n"
- delay: 5s
- interval: 120000s
then:
- logger.log:
level: INFO
format: "Testing stat commands"
- logger.log:
level: INFO
format: "This has send the stat command"
- uart.write: "stat\r\n"
- delay: 5s