-
Notifications
You must be signed in to change notification settings - Fork 0
/
jkbms-voltronic.simple.yaml
244 lines (223 loc) · 8.05 KB
/
jkbms-voltronic.simple.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
substitutions:
device_name: "jkbms-voltronic"
friendly_name: JK BMS to Voltronic
name: ${device_name}
device_id: jkbms_voltronic
esphome:
name: ${device_name}
comment: "Send BMS values to inverter Voltronic using modbus protocol LIB"
platformio_options:
upload_speed: 115200
esp32:
board: m5stack-atom
external_components:
- source: my_components
- source: github://epiclabs-io/esphome-modbus-server@master
refresh: 60s
components:
- modbus_server
logger:
syslog:
ip_address: "192.168.2.32"
port: 514
strip_colors: true
#api:
# reboot_timeout: 15min
ota:
wifi:
networks:
- ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.4.55
gateway: 192.168.2.1
subnet: 255.255.240.0
dns1: 192.168.2.1
dns2: 8.8.8.8
domain: .firtzbox
reboot_timeout: 15min
ap:
ssid: "${device_name}"
password: !secret ap_password
web_server:
port: 80
globals:
- id: bms_capacity
type: float
restore_value: no
initial_value: '0.0'
- id: bms_soc
type: float
restore_value: no
initial_value: '0.0'
- id: bms_cell_num
type: int
restore_value: no
initial_value: '0.0'
- id: bms_max_volt
type: float
restore_value: no
initial_value: '0.0'
- id: bms_min_volt
type: float
restore_value: no
initial_value: '0.0'
- id: bms_max_charge_current
type: float
restore_value: no
initial_value: '0.0'
- id: bms_max_discharge_current
type: float
restore_value: no
initial_value: '0.0'
- id: bms_charging
type: int
restore_value: no
initial_value: '0'
- id: bms_discharging
type: int
restore_value: no
initial_value: '0'
mqtt:
broker: 192.168.2.32
client_id: ${device_id}
discovery_retain: false
discovery_object_id_generator: device_name
on_message:
- topic: homeassistant/number/jk_bms_cell_count/state
then:
- globals.set:
id: bms_cell_num
value: !lambda 'return atoi(x.c_str());'
- topic: homeassistant/number/jk_bms_total_battery_capacity
then:
- globals.set:
id: bms_capacity
value: !lambda 'return atof(x.c_str());'
- topic: homeassistant/number/jk_bms_cell_voltage_overvoltage_protection/state
then:
- globals.set:
id: bms_max_volt
value: !lambda 'return atof(x.c_str());'
- topic: homeassistant/number/jk_bms_cell_voltage_undervoltage_protection/state
then:
- globals.set:
id: bms_min_volt
value: !lambda 'return atof(x.c_str());'
- topic: homeassistant/number/jk_bms_max_charge_current/state
then:
- globals.set:
id: bms_max_charge_current
value: !lambda 'return atof(x.c_str());'
- topic: homeassistant/number/jk_bms_max_discharge_current/state
then:
- globals.set:
id: bms_max_discharge_current
value: !lambda 'return atof(x.c_str());'
- topic: homeassistant/sensor/jk_bms_state_of_charge/state
then:
- globals.set:
id: bms_soc
value: !lambda 'return atof(x.c_str());'
- topic: homeassistant/switch/jk_bms_charging/state
then:
- globals.set:
id: bms_charging
value: !lambda 'return esphome::parse_on_off(x.c_str());'
- topic: homeassistant/switch/jk_bms_discharging/state
then:
- globals.set:
id: bms_discharging
value: !lambda 'return esphome::parse_on_off(x.c_str());'
time:
- platform: sntp
id: sntp_time
servers: 192.168.2.1
timezone: Europe/Rome
button:
- platform: restart
id: ${device_id}_restart_button
name: "Restart"
uart:
- id: intmodbus
rx_pin: GPIO22
tx_pin: GPIO19
baud_rate: 9600
stop_bits: 1
data_bits: 8
parity: NONE
rx_buffer_size: 384
debug:
direction: BOTH
modbus_server:
- id: modbuserver
uart_id: intmodbus
address: 1 # slave address
holding_registers:
- start_address: 0x33 # 0x0033 | 2 | SOC | %
default: 50 # 50% default value
number: 1
on_read: | # called whenever a register in the range is read
ESP_LOGI("ON_READ", "address=0x%x, value=%.0f", address, id(bms_soc));
return int(id(bms_soc));
- start_address: 0x35 # 0x0034 | 4 | Module total capacity | mAH
default: 0x45C0 # 280 Ah default value | 280000 = 0x4 0x45C0 = 4 17856
number: 1
on_read: |
auto decoded_value = decode_value<uint16_t>(int(id(bms_capacity)*1000));
ESP_LOGI("ON_READ", "address=0x%x, capacity:%.0f, value=%d", address, id(bms_capacity), decoded_value[1]);
return (id(bms_capacity) == 0 ? value : decoded_value[1]);
- start_address: 0x34 # 0x0034 | 4 | Module total capacity | mAH
default: 0x4 # 280 Ah default value
number: 1
on_read: |
auto decoded_value = decode_value<uint16_t>(int(id(bms_capacity)*1000));
ESP_LOGI("ON_READ", "address=0x%x, capacity:%.0f, value=%d", address, id(bms_capacity), decoded_value[0]);
return (id(bms_capacity) == 0 ? value : decoded_value[0]);
- start_address: 0x70 # 0x0070 | 2 | Charge voltage limit | 0.1V
default: 580 # 58.0V
number: 1
on_read: | #
float max_charge_v = id(bms_cell_num)*id(bms_max_volt);
ESP_LOGI("ON_READ", "address=0x%x, value=%.1f", address, max_charge_v);
return int(max_charge_v*10);
- start_address: 0x71 # 0x0071 | 2 | Discharge voltage limit | 0.1V
default: 480 # 48.0V
number: 1
on_read: |
float min_charge_v = id(bms_cell_num)*id(bms_min_volt);
ESP_LOGI("ON_READ", "address=0x%x, value=%.1f", address, min_charge_v);
return int(min_charge_v*10);
- start_address: 0x72 # 0x0072 | 2 | Charge current limit | 0.1A
default: 500 # 50.0A
number: 1
on_read: |
ESP_LOGI("ON_READ", "address=0x%x, value=%.0f", address, id(bms_max_charge_current));
return int(id(bms_max_charge_current)*10);
- start_address: 0x73 # 0x0073 | 2 | Discharge current limit | 0.1A
default: 1000 # 100.0A
number: 1
on_read: |
ESP_LOGI("ON_READ", "address=0x%x, value=%.0f", address, id(bms_max_charge_current));
return int(id(bms_max_charge_current)*10);
- start_address: 0x74 # 0x0074 | 2 | Charge, discharge status
# Bit: 7 | 1 | Charge enable | 1: yes 0: request stop charge
# Bit: 6 | 1 | Discharge enable | 1: yes 0: request stop discharge
# Bit: 5 | 1 | Charge immediately | 1: yes 0: no (SOC <= 9%)
# Bit: 4 | 1 | Charge immediately2 | 1: yes 0: no (9<SOC<=14%)
# Bit: 3 | 1 | Full charge request | 1: yes 0: no
# Bit: 2 | 1 | Small current charge request | small current charge request, allways 0
# Bit: 1 | 1 | |
# Bit: 0 | 1 | |
default: 192 # 0xC0 1100 0000
number: 1 # number of registers in the range
on_read: | # called whenever a register in the range is read
int number = 0;
ESP_LOGD("ON_READ", "Charge enable: %d, Discharge enable: %d, SoC: %.0f, Full charge request: 0", id(bms_charging), id(bms_discharging), id(bms_soc));
number ^= (-id(bms_charging) ^ number) & (1 << 7);
number ^= (-id(bms_discharging) ^ number) & (1 << 6);
number ^= (-(id(bms_soc) <= 9 ? 1 : 0) ^ number) & (1 << 5);
number ^= (-(9 < id(bms_soc) && id(bms_soc) <= 14 ? 1 : 0) ^ number) & (1 << 4);
number ^= (0 ^ number) & (1 << 3);
ESP_LOGI("ON_READ", "address=0x%x, value=%X", address, number);
return number;