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
403 stars 134 forks source link

JK-B2A20S20P, hw 11.XW, sw 11.284 #458

Open martinSezman opened 4 months ago

martinSezman commented 4 months ago

I'd like to raport that JK-B2A20S20P BMS works fine using JK02_32S, running on an ESP32 C3 board, connected via both BLE and UART.

BMS details: JK-B2A20S20P HW version: V11.XW SW version: V11.284

Regards, martinSezman

betmensk commented 4 months ago

hi, can you please post your code? I try to connect to this bms via esp32 wroom ble, via wemos d1 rs485 (original converter from jikong) and everything fails. bms sends data 1x and then communication is lost. well thank you.

RFDarter commented 4 months ago

Hi, is it JK-B2A20S20P or JK-B2A20S20P-HC ?

martinSezman commented 4 months ago

My code:

substitutions:
  name: "jkbms"
  device_description: "Monitor a JK-BMS via BLE/UART"
  external_components_source: github://syssi/esphome-jk-bms@main
  tx_pin: GPIO21
  rx_pin: GPIO20
  mac_address: xx:xx:xx:xx:xx:xx
  protocol_version: JK02_32S

esphome:
  name: ${name}
  friendly_name: JKBMS
  area: Garaż
  comment: ${device_description}
  project:
    name: "syssi.esphome-jk-bms"
    version: 2.0.0

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: arduino

# Enable logging
logger:
  baud_rate: 0
  level: DEBUG
  logs:
    esp32_ble_tracker: INFO
    jk_bms_ble: INFO
    scheduler: DEBUG
    component: DEBUG
    sensor: INFO
    api.service: INFO
    api: INFO
    number: INFO

debug:
  update_interval: 10s

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

ota:
  password: "xxxxxxxxxxxxxxxxxxxxxxxxxx"
  on_begin:
    then:
      - switch.turn_off: ble_client_switch0
      - logger.log: "BLE connection suspended for OTA update"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  output_power: 8.5dB

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Jkbms Fallback Hotspot"
    password: "xxxxxxxxxxxxxxxx"

captive_portal:

web_server:
  port: 80

status_led:
  pin:
    number: GPIO7
    inverted: yes

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

### BLE

esp32_ble_tracker:
  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: ${mac_address}
    id: client0

jk_bms_ble:
  - ble_client_id: client0
    protocol_version: ${protocol_version}
    throttle: 5s
    id: bmsble0

### UART
uart:
  id: uart_0
  baud_rate: 115200
  rx_buffer_size: 512
  tx_pin: ${tx_pin}
  rx_pin: ${rx_pin}
  debug:
    direction: BOTH
jk_modbus:
  - id: modbus0
    uart_id: uart_0
    rx_timeout: 50ms
jk_bms:
  - id: bms0
    jk_modbus_id: modbus0
    update_interval: 5s

################ BINARY sensors ######################
binary_sensor:
  - platform: jk_bms_ble
    balancing:
      name: "${name} balancing"
    charging:
      name: "${name} charging"
    discharging:
      name: "${name} discharging"
#    heating:
#      name: "${name} heating"
    online_status:
      name: "${name} online status"

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

################ NUMBERS ###############################
number:
  - platform: jk_bms_ble
    jk_bms_ble_id: bmsble0
    balance_trigger_voltage:
      name: "${name} balance trigger voltage"
    cell_count:
      name: "${name} cell count"
    total_battery_capacity:
      name: "${name} total battery capacity"
    cell_voltage_overvoltage_protection:
      name: "${name} cell voltage overvoltage protection"
    cell_voltage_overvoltage_recovery:
      name: "${name} cell voltage overvoltage recovery"
    cell_voltage_undervoltage_protection:
      name: "${name} cell voltage undervoltage protection"
    cell_voltage_undervoltage_recovery:
      name: "${name} cell voltage undervoltage recovery"
    balance_starting_voltage:
      name: "${name} balance starting voltage"
    voltage_calibration:
      name: "${name} voltage calibration"
    current_calibration:
      name: "${name} current calibration"
    power_off_voltage:
      name: "${name} power off voltage"
    max_balance_current:
      name: "${name} max balance current"
    max_charge_current:
      name: "${name} max charge current"
    max_discharge_current:
      name: "${name} max discharge current"

################ TEXT sensors #######################
text_sensor:
  - platform: debug
    device:
      name: "Device Info"
    reset_reason:
      name: "Reset Reason"
  - platform: wifi_info
    ip_address:
      name: ESP IP Address
    ssid:
      name: ESP Connected SSID
    bssid:
      name: ESP Connected BSSID
    mac_address:
      name: ESP Mac Wifi Address
    scan_results:
      name: ESP Latest Scan Results
    dns_address:
      name: ESP DNS Address
####################################################
  - platform: jk_bms_ble
    errors:
      name: "${name} errors"
    total_runtime_formatted:
      name: "${name} total runtime formatted"
  - platform: jk_bms
    jk_bms_id: bms0
    operation_mode:
      name: "${name} operation mode"

############### SWITCHES ###########################
switch:
  - platform: jk_bms_ble
    charging:
      name: "${name} charging"
    discharging:
      name: "${name} discharging"
    balancer:
      name: "${name} balancer"
  - platform: ble_client
    ble_client_id: client0
    id: ble_client_switch0
    name: "${name} enable bluetooth connection"

############### SENSORS  ###########################
sensor:
  - platform: wifi_signal
    name: "${name} WiFi Signal"
    update_interval: 60s
  - platform: uptime
    name: "${name} uptime"
    update_interval: 1s
  - platform: debug
    free:
      name: "Heap Free"
############## JK BMS SENSORS ######################
  - platform: jk_bms_ble
    jk_bms_ble_id: bmsble0
    min_cell_voltage:
      name: "${name} min cell voltage"
    max_cell_voltage:
      name: "${name} max cell voltage"
    min_voltage_cell:
      name: "${name} min voltage cell"
    max_voltage_cell:
      name: "${name} max voltage cell"
    delta_cell_voltage:
      name: "${name} delta cell voltage"
    average_cell_voltage:
      name: "${name} average cell voltage"
    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"
    cell_voltage_5:
      name: "${name} cell voltage 5"
    cell_voltage_6:
      name: "${name} cell voltage 6"
    cell_voltage_7:
      name: "${name} cell voltage 7"
    cell_voltage_8:
      name: "${name} cell voltage 8"
    cell_voltage_9:
      name: "${name} cell voltage 9"
    cell_voltage_10:
      name: "${name} cell voltage 10"
    cell_voltage_11:
      name: "${name} cell voltage 11"
    cell_voltage_12:
      name: "${name} cell voltage 12"
    cell_voltage_13:
      name: "${name} cell voltage 13"
    cell_voltage_14:
      name: "${name} cell voltage 14"
    cell_voltage_15:
      name: "${name} cell voltage 15"
    cell_voltage_16:
      name: "${name} cell voltage 16"
    cell_resistance_1:
      name: "${name} cell resistance 1"
    cell_resistance_2:
      name: "${name} cell resistance 2"
    cell_resistance_3:
      name: "${name} cell resistance 3"
    cell_resistance_4:
      name: "${name} cell resistance 4"
    cell_resistance_5:
      name: "${name} cell resistance 5"
    cell_resistance_6:
      name: "${name} cell resistance 6"
    cell_resistance_7:
      name: "${name} cell resistance 7"
    cell_resistance_8:
      name: "${name} cell resistance 8"
    cell_resistance_9:
      name: "${name} cell resistance 9"
    cell_resistance_10:
      name: "${name} cell resistance 10"
    cell_resistance_11:
      name: "${name} cell resistance 11"
    cell_resistance_12:
      name: "${name} cell resistance 12"
    cell_resistance_13:
      name: "${name} cell resistance 13"
    cell_resistance_14:
      name: "${name} cell resistance 14"
    cell_resistance_15:
      name: "${name} cell resistance 15"
    cell_resistance_16:
      name: "${name} cell resistance 16"
    total_voltage:
      name: "${name} total voltage"
    current:
      name: "${name} current"
    heating_current:
      name: "${name} heating current"
    power:
      name: "${name} power"
    charging_power:
      name: "${name} charging power"
    discharging_power:
      name: "${name} discharging power"
    temperature_sensor_1:
      name: "${name} temperature sensor 1"
    temperature_sensor_2:
      name: "${name} temperature sensor 2"
    power_tube_temperature:
      name: "${name} power tube temperature"
    state_of_charge:
      name: "${name} state of charge"
    capacity_remaining:
      name: "${name} capacity remaining"
    total_battery_capacity_setting:
      name: "${name} total battery capacity setting"
    charging_cycles:
      name: "${name} charging cycles"
    total_charging_cycle_capacity:
      name: "${name} total charging cycle capacity"
    total_runtime:
      name: "${name} total runtime"
    balancing_current:
      name: "${name} balancing current"
    errors_bitmask:
      name: "${name} errors bitmask"
martinSezman commented 4 months ago

Hi, is it JK-B2A20S20P or JK-B2A20S20P-HC ? JK-B2A20S20P

betmensk commented 4 months ago

martin, thank you, it didn't help me, because esp32dev has a lack of memory.

denveronly commented 4 months ago

My code:


      name: "${name} errors bitmask"

Hello, You are connecting it to UART port of JK (BMS expansion board the two right RJ45 ports, one of them) correct? Is it possible to receive data about Multiple BMS from a single port the same way as JK Windows Software does Using Device adress list?

Here is a sketch of what i am trying to achieve

image

martinSezman commented 4 months ago

My code:


      name: "${name} errors bitmask"

Hello, You are connecting it to UART port of JK (BMS expansion board the two right RJ45 ports, one of them) correct? Is it possible to receive data about Multiple BMS from a single port the same way as JK Windows Software does Using Device adress list?

Here is a sketch of what i am trying to achieve

image

This topic is for JK-B2A20S20P BMS which is not stackable I suspect.

denveronly commented 4 months ago

My code:


      name: "${name} errors bitmask"

Hello, You are connecting it to UART port of JK (BMS expansion board the two right RJ45 ports, one of them) correct? Is it possible to receive data about Multiple BMS from a single port the same way as JK Windows Software does Using Device adress list? Here is a sketch of what i am trying to achieve image

This topic is for JK-B2A20S20P BMS which is not stackable I suspect.

Oh, sorry missed that I have PB2A Sorry