-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesp32-ble-jbd.yaml
345 lines (307 loc) · 8.96 KB
/
esp32-ble-jbd.yaml
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
# This file is licensed under GNU GPLv2 ONLY
# Original credit:
# https://github.com/syssi/esphome-jbd-bms/blob/main/yaml-snippets/esp32-ble-deepsleep-limit-charging-automation.yaml
# An ESPHome sketch for safe charge terminating JBD BMS batteries for use with DUMB charging solutions.
# 22 July 2024 shvmm
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License v2
# as published by the Free Software Foundation; ONLY version 2 of the License.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License v2 for more details.
substitutions:
name: shvm-jbd
device_description: "Xiaoxiang BMS Charge Cutoff (JBD-BMS) using BLE"
external_components_source: github://syssi/esphome-jbd-bms@main
mac_address: a5:c2:37:05:6f:19
esphome:
name: ${name}
comment: ${device_description}
min_version: 2024.7.1
project:
name: "syssi.esphome-jbd-bms"
version: 1.5.0
# on_boot:
# then:
# - switch.turn_on: cutoff_sw
esp32:
board: esp32doit-devkit-v1
framework:
type: esp-idf
external_components:
- source: ${external_components_source}
refresh: 0s
# api:
# reboot_timeout: 0s
wifi:
# ssid: !secret wifi_ssid
# password: !secret wifi_password
# domain: !secret domain
ap:
ssid: "ESP-JBD BMS"
ap_timeout: 1s
# ota:
# platform: esphome
logger:
level: WARN
# USE DEBUG while using Home Assistant
debug:
update_interval: 20s
web_server:
local: true
version: 3
js_url: "https://deploy-preview-115--esphome-webserver.netlify.app/v3/www.js"
# auth:
# username: !secret web_server_username
# password: !secret web_server_password
# deep_sleep:
# id: deep_sleep0
# run_duration: 2min
# sleep_duration: 10min
esp32_ble_tracker:
ble_client:
- id: client0
mac_address: ${mac_address}
on_connect:
then:
- light.turn_on:
id: blue_led
brightness: 100%
effect: None
- lambda: |-
id(chg_status).publish_state("JBD BMS Connected");
ESP_LOGW("ESP LED", "BLE Connect");
on_disconnect:
then:
- light.turn_off:
id: blue_led
# - light.turn_on:
# id: blue_led
# effect: strobe
- lambda: |-
id(chg_status).publish_state("BMS Disconnected");
ESP_LOGW("ESP LED", "BLE Disconnect");
jbd_bms_ble:
- id: bms0
ble_client_id: client0
update_interval: 2s
output:
- platform: ledc
pin: 2
id: pwm_led
light:
- platform: monochromatic
output: pwm_led
id: blue_led
effects:
- strobe:
name: "Strobe"
- pulse:
name: "Slow Pulse"
transition_length: 500ms
update_interval: 500ms
min_brightness: 20%
max_brightness: 100%
- pulse:
name: "Extraslow Pulse"
transition_length: 1000ms
update_interval: 1000ms
min_brightness: 50%
max_brightness: 100%
- pulse:
name: "Fast Pulse"
transition_length: 100ms
update_interval: 100ms
min_brightness: 0%
max_brightness: 100%
binary_sensor:
- platform: jbd_bms_ble
jbd_bms_ble_id: bms0
balancing:
name: "${name} balancing"
online_status:
name: "${name} online status"
sensor:
- platform: jbd_bms_ble
jbd_bms_ble_id: bms0
battery_strings:
name: "${name} battery strings"
power:
name: "${name} Power"
charging_power:
name: "${name} charging power"
id: chg_power
on_value:
lambda: |-
if ((x > 0) && (id(charging).state)) {
id(chg_status).publish_state("Bulk");
id(blue_led).turn_on().set_effect("Slow Pulse").perform();
}
else if (id(charging).state) {
id(chg_status).publish_state("Idle/Discharging");
id(blue_led).turn_on().set_effect("Extraslow Pulse").perform();
}
# discharging_power:
# name: "${name} discharging power"
nominal_capacity:
name: "${name} nominal capacity"
charging_cycles:
name: "${name} charging cycles"
capacity_remaining:
name: "${name} capacity remaining"
battery_cycle_capacity:
name: "${name} battery cycle capacity"
total_voltage:
name: "${name} total voltage"
average_cell_voltage:
name: "${name} avg cell voltage"
delta_cell_voltage:
name: "${name} Cell ΔV"
accuracy_decimals: 3
min_cell_voltage:
name: "${name} min cell voltage"
max_cell_voltage:
id: max_cell_v
name: "${name} Max cell voltage"
on_value:
then:
# Enable ChargeMOS again if max_cell_v falls below some value.
lambda: |-
if (!(id(charging).state) && (id(max_cell_v).state < id(rebulk_v).state)) {
id(charging).turn_on();
id(chg_status).publish_state("Bulk");
ESP_LOGW("BlueLED", "ChargeMOS ON again");
}
# Suspend deep sleep at the end of a charge cycle to stop on point (optional!)
# - if:
# condition:
# and:
# - switch.is_on: charging
# - sensor.in_range:
# id: max_cell_v
# above: 3.375
# then:
# - deep_sleep.prevent: deep_sleep0
current:
id: current
name: "${name} Current"
min_voltage_cell:
name: "${name} min voltage cell"
max_voltage_cell:
name: "${name} max voltage cell"
temperature_1:
name: "${name} T1"
cell_voltage_1:
name: "${name} cell voltage 1"
cell_voltage_2:
name: "${name} cell voltage 2"
cell_voltage_3:
name: "${name} cell voltage 3"
cell_voltage_4:
name: "${name} cell voltage 4"
operation_status_bitmask:
name: "${name} operation status bitmask"
errors_bitmask:
name: "${name} errors bitmask"
balancer_status_bitmask:
name: "${name} balancer status bitmask"
software_version:
name: "${name} sw ver."
state_of_charge:
name: "${name} SOC"
# - platform: wifi_signal
# name: "${name} wifi Signal"
# update_interval: 120s
- platform: uptime
name: "${name} ESP Uptime"
- platform: debug
free:
name: ${name} Debug Heap Free
block:
name: ${name} Debug Heap Max Block
loop_time:
name: ${name} Debug Loop Time
text_sensor:
- platform: jbd_bms_ble
jbd_bms_ble_id: bms0
errors:
name: "${name} errors"
operation_status:
name: "${name} operation status"
device_model:
name: "${name} device model"
- platform: template
name: "${name} ESP Chg Status"
id: chg_status
switch:
- platform: ble_client
ble_client_id: client0
name: "${name} enable bluetooth connection"
- platform: jbd_bms_ble
jbd_bms_ble_id: bms0
charging:
name: "${name} charging"
id: charging
discharging:
name: "${name} discharging"
# - platform: template
# name: "${name} Cutoff switch"
# id: cutoff_sw
# optimistic: true
number:
# +-------------+
# | Slider |
# +-------------+
- platform: template
name: "${name} Safety voltage"
id: safety_v
step: 0.02
min_value: 3.36
max_value: 3.56
mode: slider
initial_value: 3.48
unit_of_measurement: V
icon: mdi:battery-charging
optimistic: true
- platform: template
name: "${name} Cutoff current"
id: cutoff_amps
step: 1
min_value: 1
max_value: 10
mode: slider
initial_value: 5
unit_of_measurement: A
icon: mdi:current-dc
optimistic: true
- platform: template
name: "${name} Rebulk voltage"
id: rebulk_v
step: 0.01
min_value: 3.28
max_value: 3.36
mode: slider
initial_value: 3.33
unit_of_measurement: V
icon: mdi:battery-charging
optimistic: true
interval:
- interval: 2s
startup_delay: 4s
then:
- lambda: |-
// Max cell voltage cutoff is a safety/protection feature and always enabled just like in BMS
if (id(charging).state && (id(max_cell_v).state > id(safety_v).state)) {
id(charging).turn_off();
id(chg_status).publish_state("High Voltage Cutoff");
id(blue_led).turn_on().set_brightness(1.0).set_effect("Fast Pulse").perform();
ESP_LOGW("BlueLED", "Fast Pulse HV Cutoff");
}
// Charge termination/cutoff
if (id(charging).state & (id(current).state < id(cutoff_amps).state) & (id(max_cell_v).state > 3.45)) {
id(charging).turn_off();
id(chg_status).publish_state("Charging Power/Amp Cutoff");
id(blue_led).turn_on().set_brightness(1.0).set_effect("Strobe").perform();
ESP_LOGW("BlueLED", "Strobe Power/Amp Cutoff");
}