syssi / esphome-jk-bms

ESPHome component to monitor and control a Jikong Battery Management System (JK-BMS) via UART-TTL or BLE
Apache License 2.0
484 stars 164 forks source link

Frame version 3 (JK02_32S) not detected properly anymore (JK-B2A8S20P, hw 11.xw, sw 11.17h) #275

Closed bassmaster187 closed 1 year ago

bassmaster187 commented 1 year ago

For any reason some values are 0 after 6th March.

Still working:

Only 0 Values:

Wrong Values:

within seconds it reports 50 additional charging cycles image

Debug

shows only Wire resistance warning & Enable cells, but i turned off verbose logging

Here is my yaml file: JKBMS - Kopie.txt

App seams to work fine: Screenshot_20230313_110231

Screenshot_20230313_110306

syssi commented 1 year ago

Could you increase the log level to:

logger:
  level: VERY_VERBOSE
  logs:
    esp32_ble_tracker: VERY_VERBOSE
    jk_bms_ble: VERY_VERBOSE
    scheduler: DEBUG
    component: DEBUG
    sensor: DEBUG
    mqtt: INFO
    mqtt.idf: INFO
    mqtt.component: INFO
    mqtt.sensor: INFO
    mqtt.switch: INFO
    api.service: INFO
    api: INFO

and provide some logs containing raw frames of the BMS?

bassmaster187 commented 1 year ago

I hope that helps: logfile.zip

syssi commented 1 year ago

This is a bug. I tried to guess the new protocol version by some bytes here:

https://github.com/syssi/esphome-jk-bms/blob/main/components/jk_bms_ble/jk_bms_ble.cpp#L444-L445

At the moment your cell info frames are decoded using protocol version 2.

Cell info frame (version 2, 300 bytes):
  ...

If I force the implementation to use protocol version 3 again the decoded data looks good again:

[14:49:10][D][sensor:127]: 'jk-bms min cell voltage': Sending state 3.39800 V with 3 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms max cell voltage': Sending state 3.41200 V with 3 decimals of accuracy
[14:49:10][V][jk_bms_ble:422]: Enabled cells bitmask: FF 00 00 00
[14:49:10][D][sensor:127]: 'jk-bms average cell voltage': Sending state 3.40500 V with 3 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms delta cell voltage': Sending state 0.01400 V with 3 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms max voltage cell': Sending state 5.00000  with 0 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms min voltage cell': Sending state 6.00000  with 0 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms power tube temperature': Sending state 35.50000 °C with 0 decimals of accuracy
[14:49:10][D][jk_bms_ble:451]: Wire resistance warning bitmask: 00 00 00 00
[14:49:10][D][sensor:127]: 'jk-bms total voltage': Sending state 27.24100 V with 2 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms current': Sending state 80.71900 A with 2 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms power': Sending state 2198.86646 W with 2 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms charging power': Sending state 2198.86646 W with 2 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms discharging power': Sending state 0.00000 W with 2 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms temperature sensor 1': Sending state 28.00000 °C with 0 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms temperature sensor 2': Sending state 29.60000 °C with 0 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms errors bitmask': Sending state 0.00000  with 0 decimals of accuracy
[14:49:10][V][text_sensor:016]: 'jk-bms errors': Received new state 
[14:49:10][D][text_sensor:067]: 'jk-bms errors': Sending state ''
[14:49:10][D][sensor:127]: 'jk-bms balancing current': Sending state -1.94100 A with 2 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms state of charge': Sending state 75.00000 % with 0 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms capacity remaining': Sending state 368.92102 Ah with 0 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms total battery capacity setting': Sending state 486.00003 Ah with 0 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms charging cycles': Sending state 37.00000  with 0 decimals of accuracy
[14:49:10][D][sensor:127]: 'jk-bms total charging cycle capacity': Sending state 18153.32031 Ah with 3 decimals of accuracy
[14:49:10][D][jk_bms_ble:536]: Unknown158: 64 00 (always 0x64 0x00?)
[14:49:10][D][jk_bms_ble:539]: Unknown160: 00 00 (always 0xC5 0x09?)
[14:49:10][D][sensor:127]: 'jk-bms total runtime': Sending state 12230031.00000 s with 0 decimals of accuracy
[14:49:10][V][text_sensor:016]: 'jk-bms total runtime formatted': Received new state 141d 13h
[14:49:10][D][text_sensor:067]: 'jk-bms total runtime formatted': Sending state '141d 13h'

I will prepare a fix and will think about it how to identify the proper protocol version in future.

syssi commented 1 year ago

Test frame:

0x55, 0xAA, 0xEB, 0x90, 0x02, 0xBA, 0x48, 0x0D, 0x4F, 0x0D, 0x4F, 0x0D, 0x53, 0x0D, 0x54, 0x0D, 0x46, 0x0D,
0x4B, 0x0D, 0x4A, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00,
0x00, 0x00, 0x4D, 0x0D, 0x0E, 0x00, 0x04, 0x05, 0x34, 0x00, 0x34, 0x00, 0x34, 0x00, 0x34, 0x00, 0x33, 0x00,
0x33, 0x00, 0x32, 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x63, 0x01, 0x00, 0x00, 0x00, 0x00, 0x69, 0x6A, 0x00, 0x00, 0x47, 0x8D, 0x21, 0x00, 0x4F, 0x3B, 0x01, 0x00,
0x18, 0x01, 0x28, 0x01, 0x00, 0x00, 0x00, 0x00, 0x6B, 0xF8, 0x02, 0x4B, 0x19, 0xA1, 0x05, 0x00, 0x70, 0x6A,
0x07, 0x00, 0x25, 0x00, 0x00, 0x00, 0x69, 0xFF, 0x14, 0x01, 0x64, 0x00, 0x00, 0x00, 0x8F, 0x9D, 0xBA, 0x00,
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00,
0x01, 0x00, 0x00, 0x00, 0x8D, 0x03, 0xBC, 0x01, 0x00, 0x00, 0xE9, 0x10, 0x40, 0x40, 0xAC, 0x00, 0x00, 0x00,
0xA4, 0x0A, 0x0E, 0xE2, 0x00, 0x01, 0x00, 0x01, 0x00, 0x05, 0x00, 0x00, 0x9A, 0x24, 0x36, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE,
0xFF, 0x7F, 0xDC, 0x3F, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0xF6
syssi commented 1 year ago

Could you tell me the hardware and software version of your BMS?

bassmaster187 commented 1 year ago

image

If I force the implementation to use protocol version 3 again the decoded data looks good again:

Is this something I can do as well or do I have to wait for an update?

syssi commented 1 year ago

I've prepared a workaround in a feature. Please update your YAML configuration to:

substitutions:
  external_components_source: github://syssi/esphome-jk-bms@force-frame-version-3

and update your ESP32. To fix this issue / auto-detect the frame version properly I need some more time. I will ask you about some more cell info frame examples probably. Let's see! :-)

bassmaster187 commented 1 year ago

It seems like it works. Thank you very much. Please let me know how I can help to solve this problem.

syssi commented 1 year ago

Please update your configuration YAML to:

substitutions:
  name: jk-bms
  device_description: "Monitor and control a JK-BMS via bluetooth"
  external_components_source: github://syssi/esphome-jk-bms@main
  protocol_version: JK02_32S
bassmaster187 commented 1 year ago

Works perfekt

syssi commented 1 year ago

@bassmaster187 Do you know the meaning of "Heat current" at your screenshot above? Do you make use of the heating function?

bassmaster187 commented 1 year ago

I think it's for a heat pad used for outdoor batteries. Below 5°C you should preheat your cells to avoid degradation. But I'm not sure.

https://diysolarforum.com/threads/jk-bms-heating-port.44994/

bassmaster187 commented 1 year ago

BTW: I made a HTML / Javascript viewer for your project. It connects to a MQTT Broker via websockets and display all values. Should I upload it to github and you can link it in the readme file? It is working just with 8 cells, but I can update it to works with 15 & 16 cells.

image

syssi commented 1 year ago

Awesome! I would like to add the solution to the "Goodies section".

syssi commented 1 year ago

@bassmaster187 Friendly reminder to share your BMS dashboard. :-)