Skip to content

Commit 66c5afe

Browse files
committed
* BLE:
+ uart1 & uart2 protocol numbers + device_info settings * RS485: + Network Nodes available (text sensor). Automatically detects nodes in the network. + status heating binary sensor bug corrected + temperature 5 + more params + developing talk pin for rs485 request or settings (not ready yet)
1 parent eb53d9b commit 66c5afe

21 files changed

+736
-373
lines changed

.vscode/settings.json

+59-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,62 @@
11
{
22
"files.associations": {
3-
"*.yaml": "home-assistant"
4-
}
3+
"*.yaml": "home-assistant",
4+
"array": "cpp",
5+
"atomic": "cpp",
6+
"bit": "cpp",
7+
"*.tcc": "cpp",
8+
"bitset": "cpp",
9+
"cctype": "cpp",
10+
"chrono": "cpp",
11+
"cinttypes": "cpp",
12+
"clocale": "cpp",
13+
"cmath": "cpp",
14+
"compare": "cpp",
15+
"concepts": "cpp",
16+
"condition_variable": "cpp",
17+
"cstdarg": "cpp",
18+
"cstddef": "cpp",
19+
"cstdint": "cpp",
20+
"cstdio": "cpp",
21+
"cstdlib": "cpp",
22+
"cstring": "cpp",
23+
"ctime": "cpp",
24+
"cwchar": "cpp",
25+
"cwctype": "cpp",
26+
"deque": "cpp",
27+
"map": "cpp",
28+
"set": "cpp",
29+
"string": "cpp",
30+
"unordered_map": "cpp",
31+
"vector": "cpp",
32+
"exception": "cpp",
33+
"algorithm": "cpp",
34+
"functional": "cpp",
35+
"iterator": "cpp",
36+
"memory": "cpp",
37+
"memory_resource": "cpp",
38+
"numeric": "cpp",
39+
"random": "cpp",
40+
"ratio": "cpp",
41+
"string_view": "cpp",
42+
"system_error": "cpp",
43+
"tuple": "cpp",
44+
"type_traits": "cpp",
45+
"utility": "cpp",
46+
"initializer_list": "cpp",
47+
"iosfwd": "cpp",
48+
"istream": "cpp",
49+
"limits": "cpp",
50+
"mutex": "cpp",
51+
"new": "cpp",
52+
"numbers": "cpp",
53+
"ostream": "cpp",
54+
"semaphore": "cpp",
55+
"stdexcept": "cpp",
56+
"stop_token": "cpp",
57+
"streambuf": "cpp",
58+
"thread": "cpp",
59+
"typeinfo": "cpp"
60+
},
61+
"C_Cpp.errorSquiggles": "enabled"
562
}

components/jk_bms_ble/jk_bms_ble.cpp

+29-12
Original file line numberDiff line numberDiff line change
@@ -591,17 +591,17 @@ void JkBmsBle::decode_jk02_cell_info_(const std::vector<uint8_t> &data) {
591591
// 138 2 0x00 0x00 Balance current 0.001 A
592592
this->publish_state_(this->balancing_current_sensor_, (float) ((int16_t) jk_get_16bit(138 + offset)) * 0.001f);
593593

594-
// 140 1 0x00 Balancing action 0x00: Off
595-
// 0x01: Charging balancer
596-
// 0x02: Discharging balancer
597-
//this->publish_state_(this->balancing_binary_sensor_, (data[140 + offset] != 0x00));
594+
// 140 [166=140+26] 1 0x00 Balancing action 0x00: Off
595+
// 0x01: Charging balancer
596+
// 0x02: Discharging balancer
597+
// this->publish_state_(this->balancing_binary_sensor_, (data[140 + offset] != 0x00));
598598
this->publish_state_(this->balancing_direction_sensor_, (data[140 + offset]));
599-
if (data[140+offset]==1 or data[140+offset]==2){
600-
this->publish_state_(this->status_balancing_binary_sensor_, (bool) 1);
599+
if (data[140 + offset] == 1 or data[140 + offset] == 2) {
600+
this->publish_state_(this->status_balancing_binary_sensor_, (bool) 1);
601601
} else {
602602
this->publish_state_(this->status_balancing_binary_sensor_, (bool) 0);
603603
}
604-
ESP_LOGI(TAG, "BALANCER WORKING STATUS 140: 0x%02X", data[140 + offset]);
604+
// ESP_LOGI(TAG, "BALANCER WORKING STATUS 140: 0x%02X", data[140 + offset]);
605605

606606
// 141 1 0x54 State of charge in 1.0 %
607607
this->publish_state_(this->state_of_charge_sensor_, (float) data[141 + offset]);
@@ -639,11 +639,11 @@ void JkBmsBle::decode_jk02_cell_info_(const std::vector<uint8_t> &data) {
639639
// 167 1 0x01 Discharging mosfet enabled 0x00: off, 0x01: on
640640
this->publish_state_(this->status_discharging_binary_sensor_, (bool) data[167 + offset]);
641641
ESP_LOGI(TAG, "DISCHARGE WORKING STATUS: 0x%02X", data[167 + offset]);
642-
// 168 1 0x01 PRE Discharging 0x00: off, 0x01: on
642+
// 168 1 0x01 PRE Discharging 0x00: off, 0x01: on ????????? --> UserAlarm2
643643
//this->publish_state_(this->status_precharging_binary_sensor_, (bool) data[168 + offset]);
644-
//ESP_LOGI(TAG, "PRECHARGE WORKING STATUS: 0x%02X", data[168 + offset]);
645644

646-
// 169 1 0x01 Balancer working 0x00: off, 0x01: on
645+
//ESP_LOGI(TAG, "PRECHARGE WORKING STATUS: 0x%02X", data[168 + offset]);
646+
// 169 1 0x01 Balancer working 0x00: off, 0x01: on ????????? --> TimeDcOCPR
647647
//this->publish_state_(this->status_balancing_binary_sensor_, (bool) data[169 + offset]);
648648
ESP_LOGI(TAG, "BALANCER WORKING STATUS 169: 0x%02X", data[169 + offset]);
649649

@@ -676,18 +676,23 @@ void JkBmsBle::decode_jk02_cell_info_(const std::vector<uint8_t> &data) {
676676
ESP_LOGI(TAG, "BATTempSensor3Absent: %d", (bool) check_bit_(data[182], 8));
677677
ESP_LOGI(TAG, "BATTempSensor4Absent: %d", (bool) check_bit_(data[182], 16));
678678
ESP_LOGI(TAG, "BATTempSensor5Absent: %d", (bool) check_bit_(data[182], 32));*/
679+
680+
// 183 [209=183+26] 1 0x01 Status heating 0x00: off, 0x01: on
681+
this->publish_state_(this->status_heating_binary_sensor_, (bool) check_bit_(data[183 + offset], 1));
682+
ESP_LOGD(TAG, "HEATING BINARY SENSOR STATUS: 0x%02X", data[183 + offset]);
679683
}
680684

681685
// 183 2 0x00 0x01 Unknown183 Heating working???
682686
//this->publish_state_(this->status_heating_binary_sensor_, (bool) data[183 + offset]);
687+
688+
683689
// 185 2 0x00 0x00 Unknown185
684690
// 187 2 0x00 0xD5 Unknown187
685691
// 189 2 0x02 0x00 Unknown189
686692
ESP_LOGD(TAG, "Unknown189: 0x%02X 0x%02X", data[189], data[190]);
687693
// 190 1 0x00 Unknown190
688694
// 191 1 0x00 Balancer status (working: 0x01, idle: 0x00)
689-
this->publish_state_(this->status_heating_binary_sensor_, (bool) data[192 + offset]);
690-
ESP_LOGI(TAG, "HEATING BINARY SENSOR STATUS: 0x%02X", data[192 + offset]);
695+
691696

692697
// 193 2 0x00 0xAE Unknown193
693698
ESP_LOGD(TAG, "Unknown193: 0x%02X 0x%02X (0x00 0x8D)", data[193 + offset], data[194 + offset]);
@@ -1312,14 +1317,26 @@ void JkBmsBle::decode_device_info_(const std::vector<uint8_t> &data) {
13121317
ESP_LOGI(TAG, " User data: %s", std::string(data.begin() + 102, data.begin() + 102 + 16).c_str());
13131318
ESP_LOGI(TAG, " Setup passcode: %s", std::string(data.begin() + 118, data.begin() + 118 + 16).c_str());
13141319

1320+
ESP_LOGI(TAG, " UART1 Protocol Number: 0x%02X", ((uint8_t) data[178]));
1321+
ESP_LOGI(TAG, " CAN Protocol Number: 0x%02X", ((uint8_t) data[179]));
1322+
ESP_LOGI(TAG, " UART2 Protocol Number: 0x%02X", ((uint8_t) data[212]));
1323+
ESP_LOGI(TAG, " UART2 Protocol Enabled[0]: 0x%02X", ((uint8_t) data[213]));
1324+
13151325
ESP_LOGI(TAG, " RCV Time: %f h", (float) ((uint8_t) data[266]) * 0.1f);
13161326
ESP_LOGI(TAG, " RFV Time: %f h", (float) ((uint8_t) data[267]) * 0.1f);
1327+
ESP_LOGI(TAG, " CAN Protocol Library Version: %f", (float) ((uint8_t) data[268]));
1328+
ESP_LOGI(TAG, " RVD: %f", (float) ((uint8_t) data[269]));
1329+
ESP_LOGI(TAG, " ---------------------------------------");
13171330

13181331
this->publish_state_(this->info_vendorid_text_sensor_, std::string(data.begin() + 6, data.begin() + 6 + 16).c_str());
13191332
this->publish_state_(this->info_hardware_version_text_sensor_, std::string(data.begin() + 22, data.begin() + 22 + 8).c_str());
13201333
this->publish_state_(this->info_software_version_text_sensor_, std::string(data.begin() + 30, data.begin() + 30 + 8).c_str());
13211334
this->publish_state_(this->info_device_name_text_sensor_, std::string(data.begin() + 46, data.begin() + 46 + 16).c_str());
13221335
this->publish_state_(this->info_device_password_text_sensor_, std::string(data.begin() + 62, data.begin() + 62 + 16).c_str());
1336+
1337+
this->publish_state_(this->uart1_protocol_number_number_, (uint8_t) data[178]);
1338+
this->publish_state_(this->uart2_protocol_number_number_, (uint8_t) data[212]);
1339+
13231340
this->publish_state_(this->cell_request_charge_voltage_time_number_, (float) data[266]*0.1f);
13241341
this->publish_state_(this->cell_request_float_voltage_time_number_, (float) data[267]*0.1f);
13251342

components/jk_bms_ble/jk_bms_ble.h

+10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ class JkBmsBle : public esphome::ble_client::BLEClientNode, public PollingCompon
3636
void set_smart_sleep_time_number(number::Number *smart_sleep_time_number) {
3737
smart_sleep_time_number_ = smart_sleep_time_number;
3838
}
39+
40+
void set_uart1_protocol_number_number(number::Number *uart1_protocol_number_number) {
41+
uart1_protocol_number_number_ = uart1_protocol_number_number;
42+
}
43+
void set_uart2_protocol_number_number(number::Number *uart2_protocol_number_number) {
44+
uart2_protocol_number_number_ = uart2_protocol_number_number;
45+
}
46+
3947
void set_cell_smart_sleep_voltage_number(number::Number *cell_smart_sleep_voltage_number) {
4048
cell_smart_sleep_voltage_number_ = cell_smart_sleep_voltage_number;
4149
}
@@ -411,6 +419,8 @@ void set_alarm_battempsensor5absent_binary_sensor(binary_sensor::BinarySensor *a
411419
number::Number *max_charge_current_number_;
412420
number::Number *max_discharge_current_number_;
413421
number::Number *smart_sleep_time_number_;
422+
number::Number *uart1_protocol_number_number_;
423+
number::Number *uart2_protocol_number_number_;
414424

415425
sensor::Sensor *balancing_direction_sensor_;
416426
sensor::Sensor *cell_voltage_min_sensor_;

components/jk_bms_ble/number/__init__.py

+27-3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
CONF_CELL_REQUEST_FLOAT_VOLTAGE= "cell_request_float_voltage"
6666
CONF_CELL_REQUEST_CHARGE_VOLTAGE_TIME= "cell_request_charge_voltage_time"
6767
CONF_CELL_REQUEST_FLOAT_VOLTAGE_TIME= "cell_request_float_voltage_time"
68+
CONF_UART1_PROTOCOL_NUMBER = "uart1_protocol_number"
69+
CONF_UART2_PROTOCOL_NUMBER = "uart2_protocol_number"
6870

6971
CONF_CELL_COUNT = "cell_count"
7072
CONF_TOTAL_BATTERY_CAPACITY = "total_battery_capacity"
@@ -162,7 +164,8 @@
162164
CONF_SMART_SLEEP_TIME : [0x00, 0x00, 0x00, 1.0], # What register number for address 0x0118?
163165
CONF_CELL_REQUEST_CHARGE_VOLTAGE_TIME: [0x00, 0x00, 0x00, 1.0], # What register number for address 0x0104? (0x1400 TYPE REGISTER)
164166
CONF_CELL_REQUEST_FLOAT_VOLTAGE_TIME: [0x00, 0x0a, 0x00, 1.0], # What register number for address 0x0105? (0x1400 TYPE REGISTER)
165-
167+
CONF_UART1_PROTOCOL_NUMBER: [0x00, 0x0a, 0x00, 1.0], # What register number for address ??????? (0x1400 TYPE REGISTER)
168+
CONF_UART2_PROTOCOL_NUMBER: [0x00, 0x0a, 0x00, 1.0], # What register number for address ??????? (0x1400 TYPE REGISTER)
166169
}
167170

168171
JkNumber = jk_bms_ble_ns.class_("JkNumber", number.Number, cg.Component)
@@ -364,12 +367,33 @@
364367
cv.Optional(CONF_MIN_VALUE, default=0.0): cv.int_,
365368
cv.Optional(CONF_MAX_VALUE, default=255.0): cv.int_,
366369
cv.Optional(CONF_STEP, default=1.0): cv.int_,
367-
cv.Optional(CONF_ICON, default=ICON_CLOCK): cv.icon,
368370
cv.Optional(
369371
CONF_UNIT_OF_MEASUREMENT, default=UNIT_HOURS
370372
): cv.string_strict,
371373
}
372-
),
374+
),
375+
cv.Optional(CONF_UART1_PROTOCOL_NUMBER): JK_NUMBER_SCHEMA.extend(
376+
{
377+
cv.Optional(CONF_MIN_VALUE, default=0.0): cv.int_,
378+
cv.Optional(CONF_MAX_VALUE, default=255.0): cv.int_,
379+
cv.Optional(CONF_STEP, default=1.0): cv.int_,
380+
cv.Optional(CONF_ICON, default=ICON_CLOCK): cv.icon,
381+
cv.Optional(
382+
CONF_UNIT_OF_MEASUREMENT, default=UNIT_EMPTY
383+
): cv.string_strict,
384+
}
385+
),
386+
cv.Optional(CONF_UART2_PROTOCOL_NUMBER): JK_NUMBER_SCHEMA.extend(
387+
{
388+
cv.Optional(CONF_MIN_VALUE, default=0.0): cv.int_,
389+
cv.Optional(CONF_MAX_VALUE, default=255.0): cv.int_,
390+
cv.Optional(CONF_STEP, default=1.0): cv.int_,
391+
cv.Optional(CONF_ICON, default=ICON_CLOCK): cv.icon,
392+
cv.Optional(
393+
CONF_UNIT_OF_MEASUREMENT, default=UNIT_EMPTY
394+
): cv.string_strict,
395+
}
396+
),
373397
}
374398
)
375399

0 commit comments

Comments
 (0)