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
483 stars 164 forks source link

One BMS going off after some time. #608

Open LifeofDan-EL opened 1 month ago

LifeofDan-EL commented 1 month ago

So I currently use the multiple BMS configuration. I have two batteries that I use your integration with, and I really find it useful. However, I discovered that lately, the bms0 is fond of going offline which is weird and it has been recurring much more than I expected. There are also times when both of them go offline but it doesn't happen for too long.

Version: JK_B2A20S20P Hardware Version: V11.XA Software Version: V11.47

For both.

image image image

My config

substitutions:
  name: jk-bms
  bms0: "${name} bms0"
  bms1: "${name} bms1"
  device_description: "Monitor and control a JK-BMS via bluetooth"
  external_components_source: github://syssi/esphome-jk-bms@main
  bms0_mac_address: C8:47:80:11:41:7C
  bms1_mac_address: C8:47:80:11:08:1B

  bms0_protocol_version: JK02_32S
  bms1_protocol_version: JK02_32S

esphome:
  name: ${name}
  comment: ${device_description}
  min_version: 2024.6.0
  project:
    name: "syssi.esphome-jk-bms"
    version: 2.1.0

esp32:
  board: wemos_d1_mini32
  framework:
    type: esp-idf

external_components:
  - source: ${external_components_source}
    refresh: 0s

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

ota:
  platform: esphome
  password: "xxxxxxxxxxxxxxxxxx"
  on_begin:
    then:
      - switch.turn_off: ble_client_switch0
      - switch.turn_off: ble_client_switch1
      - logger.log: "BLE connection suspended for OTA update"

# Enable logging
logger:
  level: DEBUG
  logs:
    esp32_ble_tracker: INFO
    esp32_ble_client: INFO

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxxxxxxxxxxxxxxxxx"

esp32_ble_tracker:
  scan_parameters:
    active: false
  on_ble_advertise:
    then:
      - lambda: |-
          if (x.get_name().rfind("JK-", 0) == 0 || x.get_name().rfind("JK_", 0) == 0) {
            ESP_LOGI("ble_adv", "New JK-BMS found");
            ESP_LOGI("ble_adv", "  Name: %s", x.get_name().c_str());
            ESP_LOGI("ble_adv", "  MAC address: %s", x.address_str().c_str());
            ESP_LOGD("ble_adv", "  Advertised service UUIDs:");
            for (auto uuid : x.get_service_uuids()) {
              ESP_LOGD("ble_adv", "    - %s", uuid.to_string().c_str());
            }
          }

ble_client:
  - mac_address: ${bms0_mac_address}
    id: client0
  - mac_address: ${bms1_mac_address}
    id: client1

jk_bms_ble:
  - ble_client_id: client0
    protocol_version: ${bms0_protocol_version}
    throttle: 5s
    id: bms0
  - ble_client_id: client1
    protocol_version: ${bms1_protocol_version}
    throttle: 5s
    id: bms1

binary_sensor:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    balancing:
      name: "${bms0} balancing"
    charging:
      name: "${bms0} charging"
    discharging:
      name: "${bms0} discharging"
    online_status:
      name: "${bms0} online status"

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    balancing:
      name: "${bms1} balancing"
    charging:
      name: "${bms1} charging"
    discharging:
      name: "${bms1} discharging"
    online_status:
      name: "${bms1} online status"

button:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    retrieve_settings:
      name: "${bms0} retrieve settings"
    retrieve_device_info:
      name: "${bms0} retrieve device info"

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    retrieve_settings:
      name: "${bms1} retrieve settings"
    retrieve_device_info:
      name: "${bms1} retrieve device info"

number:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    balance_trigger_voltage:
      name: "${bms0} balance trigger voltage"
    cell_count:
      name: "${bms0} cell count"
    total_battery_capacity:
      name: "${bms0} total battery capacity"
    cell_voltage_overvoltage_protection:
      name: "${bms0} cell voltage overvoltage protection"
    cell_voltage_overvoltage_recovery:
      name: "${bms0} cell voltage overvoltage recovery"
    cell_voltage_undervoltage_protection:
      name: "${bms0} cell voltage undervoltage protection"
    cell_voltage_undervoltage_recovery:
      name: "${bms0} cell voltage undervoltage recovery"
    balance_starting_voltage:
      name: "${bms0} balance starting voltage"
    voltage_calibration:
      name: "${bms0} voltage calibration"
    current_calibration:
      name: "${bms0} current calibration"
    power_off_voltage:
      name: "${bms0} power off voltage"
    max_balance_current:
      name: "${bms0} max balance current"
    max_charge_current:
      name: "${bms0} max charge current"
    max_discharge_current:
      name: "${bms0} max discharge current"
    charge_overcurrent_protection_delay:
      name: "${bms0} charge overcurrent protection delay"
    charge_overcurrent_protection_recovery_time:
      name: "${bms0} charge overcurrent protection recovery time"
    discharge_overcurrent_protection_delay:
      name: "${bms0} discharge overcurrent protection delay"
    discharge_overcurrent_protection_recovery_time:
      name: "${bms0} discharge overcurrent protection recovery time"
    short_circuit_protection_delay:
      name: "${bms0} short circuit protection delay"
    short_circuit_protection_recovery_time:
      name: "${bms0} short circuit protection recovery time"
    charge_overtemperature_protection:
      name: "${bms0} charge overtemperature protection"
    charge_overtemperature_protection_recovery:
      name: "${bms0} charge overtemperature protection recovery"
    discharge_overtemperature_protection:
      name: "${bms0} discharge overtemperature protection"
    discharge_overtemperature_protection_recovery:
      name: "${bms0} discharge overtemperature protection recovery"
    charge_undertemperature_protection:
      name: "${bms0} charge undertemperature protection"
    charge_undertemperature_protection_recovery:
      name: "${bms0} charge undertemperature protection recovery"
    power_tube_overtemperature_protection:
      name: "${bms0} power tube overtemperature protection"
    power_tube_overtemperature_protection_recovery:
      name: "${bms0} power tube overtemperature protection recovery"

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    balance_trigger_voltage:
      name: "${bms1} balance trigger voltage"
    cell_count:
      name: "${bms1} cell count"
    total_battery_capacity:
      name: "${bms1} total battery capacity"
    cell_voltage_overvoltage_protection:
      name: "${bms1} cell voltage overvoltage protection"
    cell_voltage_overvoltage_recovery:
      name: "${bms1} cell voltage overvoltage recovery"
    cell_voltage_undervoltage_protection:
      name: "${bms1} cell voltage undervoltage protection"
    cell_voltage_undervoltage_recovery:
      name: "${bms1} cell voltage undervoltage recovery"
    balance_starting_voltage:
      name: "${bms1} balance starting voltage"
    voltage_calibration:
      name: "${bms1} voltage calibration"
    current_calibration:
      name: "${bms1} current calibration"
    power_off_voltage:
      name: "${bms1} power off voltage"
    max_balance_current:
      name: "${bms1} max balance current"
    max_charge_current:
      name: "${bms1} max charge current"
    max_discharge_current:
      name: "${bms1} max discharge current"
    charge_overcurrent_protection_delay:
      name: "${bms1} charge overcurrent protection delay"
    charge_overcurrent_protection_recovery_time:
      name: "${bms1} charge overcurrent protection recovery time"
    discharge_overcurrent_protection_delay:
      name: "${bms1} discharge overcurrent protection delay"
    discharge_overcurrent_protection_recovery_time:
      name: "${bms1} discharge overcurrent protection recovery time"
    short_circuit_protection_delay:
      name: "${bms1} short circuit protection delay"
    short_circuit_protection_recovery_time:
      name: "${bms1} short circuit protection recovery time"
    charge_overtemperature_protection:
      name: "${bms1} charge overtemperature protection"
    charge_overtemperature_protection_recovery:
      name: "${bms1} charge overtemperature protection recovery"
    discharge_overtemperature_protection:
      name: "${bms1} discharge overtemperature protection"
    discharge_overtemperature_protection_recovery:
      name: "${bms1} discharge overtemperature protection recovery"
    charge_undertemperature_protection:
      name: "${bms1} charge undertemperature protection"
    charge_undertemperature_protection_recovery:
      name: "${bms1} charge undertemperature protection recovery"
    power_tube_overtemperature_protection:
      name: "${bms1} power tube overtemperature protection"
    power_tube_overtemperature_protection_recovery:
      name: "${bms1} power tube overtemperature protection recovery"

sensor:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    min_cell_voltage:
      name: "${bms0} min cell voltage"
    max_cell_voltage:
      name: "${bms0} max cell voltage"
    min_voltage_cell:
      name: "${bms0} min voltage cell"
    max_voltage_cell:
      name: "${bms0} max voltage cell"
    delta_cell_voltage:
      name: "${bms0} delta cell voltage"
    average_cell_voltage:
      name: "${bms0} average cell voltage"
    cell_voltage_1:
      name: "${bms0} cell voltage 1"
    cell_voltage_2:
      name: "${bms0} cell voltage 2"
    cell_voltage_3:
      name: "${bms0} cell voltage 3"
    cell_voltage_4:
      name: "${bms0} cell voltage 4"
    cell_voltage_5:
      name: "${bms0} cell voltage 5"
    cell_voltage_6:
      name: "${bms0} cell voltage 6"
    cell_voltage_7:
      name: "${bms0} cell voltage 7"
    cell_voltage_8:
      name: "${bms0} cell voltage 8"
    cell_voltage_9:
      name: "${bms0} cell voltage 9"
    cell_voltage_10:
      name: "${bms0} cell voltage 10"
    cell_voltage_11:
      name: "${bms0} cell voltage 11"
    cell_voltage_12:
      name: "${bms0} cell voltage 12"
    cell_voltage_13:
      name: "${bms0} cell voltage 13"
    cell_voltage_14:
      name: "${bms0} cell voltage 14"
    cell_voltage_15:
      name: "${bms0} cell voltage 15"
    cell_voltage_16:
      name: "${bms0} cell voltage 16"
    total_voltage:
      name: "${bms0} total voltage"
    current:
      name: "${bms0} current"
    heating_current:
      name: "${bms0} heating current"
    power:
      name: "${bms0} power"
    charging_power:
      name: "${bms0} charging power"
    discharging_power:
      name: "${bms0} discharging power"
    temperature_sensor_1:
      name: "${bms0} temperature sensor 1"
    temperature_sensor_2:
      name: "${bms0} temperature sensor 2"
    temperature_sensor_3:
      name: "${bms0} temperature sensor 3"
    power_tube_temperature:
      name: "${bms0} power tube temperature"
    balancing:
      name: "${bms0} balancing"
    state_of_charge:
      name: "${bms0} state of charge"
    capacity_remaining:
      name: "${bms0} capacity remaining"
    total_battery_capacity_setting:
      name: "${bms0} total battery capacity setting"
    charging_cycles:
      name: "${bms0} charging cycles"
    total_charging_cycle_capacity:
      name: "${bms0} total charging cycle capacity"
    total_runtime:
      name: "${bms0} total runtime"
    balancing_current:
      name: "${bms0} balancing current"
    errors_bitmask:
      name: "${bms0} errors bitmask"

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    min_cell_voltage:
      name: "${bms1} min cell voltage"
    max_cell_voltage:
      name: "${bms1} max cell voltage"
    min_voltage_cell:
      name: "${bms1} min voltage cell"
    max_voltage_cell:
      name: "${bms1} max voltage cell"
    delta_cell_voltage:
      name: "${bms1} delta cell voltage"
    average_cell_voltage:
      name: "${bms1} average cell voltage"
    cell_voltage_1:
      name: "${bms1} cell voltage 1"
    cell_voltage_2:
      name: "${bms1} cell voltage 2"
    cell_voltage_3:
      name: "${bms1} cell voltage 3"
    cell_voltage_4:
      name: "${bms1} cell voltage 4"
    cell_voltage_5:
      name: "${bms1} cell voltage 5"
    cell_voltage_6:
      name: "${bms1} cell voltage 6"
    cell_voltage_7:
      name: "${bms1} cell voltage 7"
    cell_voltage_8:
      name: "${bms1} cell voltage 8"
    cell_voltage_9:
      name: "${bms1} cell voltage 9"
    cell_voltage_10:
      name: "${bms1} cell voltage 10"
    cell_voltage_11:
      name: "${bms1} cell voltage 11"
    cell_voltage_12:
      name: "${bms1} cell voltage 12"
    cell_voltage_13:
      name: "${bms1} cell voltage 13"
    cell_voltage_14:
      name: "${bms1} cell voltage 14"
    cell_voltage_15:
      name: "${bms1} cell voltage 15"
    cell_voltage_16:
      name: "${bms1} cell voltage 16"
    total_voltage:
      name: "${bms1} total voltage"
    current:
      name: "${bms1} current"
    heating_current:
      name: "${bms1} heating current"
    power:
      name: "${bms1} power"
    charging_power:
      name: "${bms1} charging power"
    discharging_power:
      name: "${bms1} discharging power"
    temperature_sensor_1:
      name: "${bms1} temperature sensor 1"
    temperature_sensor_2:
      name: "${bms1} temperature sensor 2"
    temperature_sensor_3:
      name: "${bms1} temperature sensor 3"
    power_tube_temperature:
      name: "${bms1} power tube temperature"
    balancing:
      name: "${bms1} balancing"
    state_of_charge:
      name: "${bms1} state of charge"
    capacity_remaining:
      name: "${bms1} capacity remaining"
    total_battery_capacity_setting:
      name: "${bms1} total battery capacity setting"
    charging_cycles:
      name: "${bms1} charging cycles"
    total_charging_cycle_capacity:
      name: "${bms1} total charging cycle capacity"
    total_runtime:
      name: "${bms1} total runtime"
    balancing_current:
      name: "${bms1} balancing current"
    errors_bitmask:
      name: "${bms1} errors bitmask"

switch:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    charging:
      name: "${bms0} charging"
    discharging:
      name: "${bms0} discharging"
    balancer:
      name: "${bms0} balancer"

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    charging:
      name: "${bms1} charging"
    discharging:
      name: "${bms1} discharging"
    balancer:
      name: "${bms1} balancer"

  - platform: ble_client
    ble_client_id: client0
    id: ble_client_switch0
    name: "${bms0} enable bluetooth connection"
  - platform: ble_client
    ble_client_id: client1
    id: ble_client_switch1
    name: "${bms1} enable bluetooth connection"

text_sensor:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    errors:
      name: "${bms0} errors"
    total_runtime_formatted:
      name: "${bms0} total runtime formatted"

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    errors:
      name: "${bms1} errors"
    total_runtime_formatted:
      name: "${bms1} total runtime formatted"

Thanks so much for the work you do.

syssi commented 1 month ago

Is this reproducible? It's always the second BMS? What happens if you flip the initialization order:

ble_client:
  - mac_address: ${bms1_mac_address}
    id: client1
  - mac_address: ${bms0_mac_address}
    id: client0

jk_bms_ble:
  - ble_client_id: client1
    protocol_version: ${bms1_protocol_version}
    throttle: 5s
    id: bms1
  - ble_client_id: client0
    protocol_version: ${bms0_protocol_version}
    throttle: 5s
    id: bms0

Which BMS connection stops this time?

LifeofDan-EL commented 1 month ago

Actually, it's the first BMS that goes off. The first which is bms0.

I just flipped the initialization order, let me see what happens with time.

image

Same thing, the bms0 doesn't connect.

Config

ble_client:
  - mac_address: ${bms0_mac_address}
    id: client1
  - mac_address: ${bms1_mac_address}
    id: client0

jk_bms_ble:
  - ble_client_id: client1
    protocol_version: ${bms0_protocol_version}
    throttle: 5s
    id: bms0
  - ble_client_id: client0
    protocol_version: ${bms1_protocol_version}
    throttle: 5s
    id: bms1

I saw this from the log. It connects and disconnects immediately. image

vpritulin commented 1 month ago

@LifeofDan-EL Hi, I have the same problem, but I don't use the BLE connection. On average, it takes about 15 minutes offline. When I tested the BLE, it was the same. So far I haven't managed to solve it or understand why it happens.

syssi commented 4 weeks ago

@LifeofDan-EL Sorry for the silence/delay. Is my understanding of your issue correct:

We have proofed it's always the first BLE client connection which fails. It doesn't depend on the connected hardware. The issue is gone if a single BLE connection is used.

Correct?

LifeofDan-EL commented 4 weeks ago

@LifeofDan-EL Hi, I have the same problem, but I don't use the BLE connection. On average, it takes about 15 minutes offline. When I tested the BLE, it was the same. So far I haven't managed to solve it or understand why it happens.

Interesting, that means it's most likely not a Bluetooth connectivity problem.

LifeofDan-EL commented 4 weeks ago

@LifeofDan-EL Sorry for the silence/delay. Is my understanding of your issue correct:

We have proofed it's always the first BLE client connection which fails. It doesn't depend on the connected hardware. The issue is gone if a single BLE connection is used.

Correct?

Yes, if you look at today's data you can see that while bms0 is blanking out, bms1 has been stable. On some days, the bms0 is more sparse on the graph. image

vpritulin commented 4 weeks ago

Interesting, that means it's most likely not a Bluetooth connectivity problem.

For example, here is my graph from one sensor and it is clear that there are interruptions. I would refer to the poor wifi signal and the problem is only with me, but as it turned out, no. At the same time, other esp sensors do not have such a problem. The esp itself shows Signal level -72 dB

Monosnap История – Home Assistant 2024-10-21 13-49-43