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 163 forks source link

Protocol version `JK02_32S` results in no error text coming through #380

Closed JohnGalt1717 closed 1 year ago

JohnGalt1717 commented 1 year ago

The

errors:
      name: "${name} errors"

Isn't coming through nor is total_runtime_formatted as soon as I moved to JK02_32S because the logs showed I was supposed to be using it for version.

It pulled the latest version of the source code if that matters.

syssi commented 1 year ago

Could you provide some more details? Which BMS hardware and software version do you own? Are you sure JK02_32S is the correct choice for your revision?

syssi commented 1 year ago

Could you increase the log level to VERY_VERBOSE and provide some RAW traffic? I'm interested in these log messages to reproduce the issue locally:

ESP_LOGI(TAG, "Cell info frame (version %d, %d bytes) received", frame_version, data.size());
ESP_LOGVV(TAG, "  %s", format_hex_pretty(&data.front(), 150).c_str());
ESP_LOGVV(TAG, "  %s", format_hex_pretty(&data.front() + 150, data.size() - 150).c_str());

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

JohnGalt1717 commented 1 year ago

logs_bmses3_logs.txt Here you got. Took a while because it crashes Edge with that much data ;)

I'm pretty sure it's JK02_32S because it literally told me that the default isn't right in the logs and it's a newer unit with the push button, heater, and Canbus option.

syssi commented 1 year ago

This value isn't correct?

[16:10:07][V][sensor:043]: 'BMS 5 total runtime': Received new state 18297532.000000
[16:10:07][D][sensor:094]: 'BMS 5 total runtime': Sending state 18297532.00000 s with 0 decimals of accuracy
...
[16:10:02][V][text_sensor:013]: 'Balancer 5 total runtime formatted': Received new state 211d 18h
[16:10:02][D][text_sensor:064]: 'Balancer 5 total runtime formatted': Sending state '211d 18h'

And this value isn't available via MQTT too?

[16:10:02][V][sensor:043]: 'BMS 5 errors bitmask': Received new state 4096.000000
[16:10:02][D][sensor:094]: 'BMS 5 errors bitmask': Sending state 4096.00000  with 0 decimals of accuracy
...
[16:10:02][V][text_sensor:013]: 'Balancer 5 errors': Received new state Cell Overvoltage
[16:10:02][D][text_sensor:064]: 'Balancer 5 errors': Sending state 'Cell Overvoltage'

I'm asking because the log looks good in general. So may be I didn't got the point / understand the issue?

JohnGalt1717 commented 1 year ago

That’s the heltec balancer that’s also attached. It’s bms 5 that doesn’t report errors properly. It does report error mask.

syssi commented 1 year ago

@JohnGalt1717 Could you provide your YAML configuration? I would like to try to replicate your setup.

JohnGalt1717 commented 1 year ago
substitutions:
  device_name: bmses3
  battery_name: "Battery 5"
  battery_id: battery5  
  name: "BMS 5"
  bms1_id: bms5  
  mac_address1: xxxxx 
  bal1_id: bal5
  bal1_name: "Balancer 5"
  mac_address_bal:xxxx
  protocol_version1: JK02_32S
  external_components_source: github://syssi/esphome-jk-bms@main

esphome:
  name: bmses3
  friendly_name: BMS Host 3

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: esp-idf    
    sdkconfig_options:
      CONFIG_COMPILER_OPTIMIZATION_SIZE: y
      CONFIG_BT_BLE_42_FEATURES_SUPPORTED: y
      CONFIG_BT_BLE_50_FEATURES_SUPPORTED: y
      CONFIG_ESP_TASK_WDT_TIMEOUT_S: "10" 

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

api:

ota:
  password: !secret esphome_ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: ${device_name}.hancocks.email

logger:
  level: INFO

web_server:
  port: 80

preferences:
  flash_write_interval: 0.5h

time:
  - platform: homeassistant
    id: homeassistant_time

esp32_ble_tracker:
  scan_parameters:
    interval: 500ms
    window: 150ms    
  on_ble_advertise:
    then:
      - lambda: |-
            ESP_LOGI("ble_adv", "  Name: %s", x.get_name().c_str());
            ESP_LOGI("ble_adv", "  MAC address: %s", x.address_str().c_str());

ble_client:
  - mac_address: ${mac_address1}
    id: ${bms1_id}
  - mac_address: ${mac_address_bal}
    id: ${bal1_id}

jk_bms_ble:  
  - ble_client_id: ${bms1_id}
    throttle: 5s
    id: bms0
    protocol_version: ${protocol_version1}

heltec_balancer_ble:
  - ble_client_id: ${bal1_id}
    throttle: 5s
    id: bal0

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

button:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    retrieve_settings:
      name: "${name} retrieve settings"
    retrieve_device_info:
      name: "${name} retrieve device info"
  - platform: restart
    name: "Restart ${name} ESP32"
  - platform: shutdown
    name: "Shutdown ${name} ESP32"
  - platform: heltec_balancer_ble
    retrieve_settings:
      name: "${bal1_name} retrieve settings"
      id: retrieve_settings_button
    retrieve_device_info:
      name: "${bal1_name} retrieve device info"
    retrieve_factory_defaults:
      name: "${bal1_name} retrieve factory defaults"    

number:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    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"
  - platform: heltec_balancer_ble
    cell_count:
      name: "${bal1_name} cell count"
    balance_trigger_voltage:
      name: "${bal1_name} balance trigger voltage"
    max_balance_current:
      name: "${bal1_name} max balance current"
    balance_sleep_voltage:
      name: "${bal1_name} balance sleep voltage"
    balance_start_voltage:
      name: "${bal1_name} balance start voltage"
    nominal_battery_capacity:
      name: "${bal1_name} nominal battery capacity"      

sensor:
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 60s

  - platform: total_daily_energy
    name: "${name} Total Charging Energy Today"
    power_id: bms_charging_power
    unit_of_measurement: kWh
    device_class: energy
    icon: mdi:counter
    accuracy_decimals: 3
    restore: true
    filters:
      - multiply: 0.001    

  - platform: total_daily_energy
    name: "${name} Total Discharging Energy Today"
    power_id: bms_discharging_power
    unit_of_measurement: kWh
    device_class: energy
    icon: mdi:counter
    accuracy_decimals: 3
    restore: true
    filters:
      - multiply: 0.001 

  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    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"
    power:
      name: "${name} power"
    charging_power:
      name: "${name} charging power"
      id: bms_charging_power
    discharging_power:
      name: "${name} discharging power"
      id: bms_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"
  - platform: heltec_balancer_ble
    min_cell_voltage:
      name: "${bal1_name} min cell voltage"
    max_cell_voltage:
      name: "${bal1_name} max cell voltage"
    min_voltage_cell:
      name: "${bal1_name} min voltage cell"
    max_voltage_cell:
      name: "${bal1_name} max voltage cell"
    delta_cell_voltage:
      name: "${bal1_name} delta cell voltage"
    average_cell_voltage:
      name: "${bal1_name} average cell voltage"
    cell_voltage_1:
      name: "${bal1_name} cell voltage 1"
    cell_voltage_2:
      name: "${bal1_name} cell voltage 2"
    cell_voltage_3:
      name: "${bal1_name} cell voltage 3"
    cell_voltage_4:
      name: "${bal1_name} cell voltage 4"
    cell_voltage_5:
      name: "${bal1_name} cell voltage 5"
    cell_voltage_6:
      name: "${bal1_name} cell voltage 6"
    cell_voltage_7:
      name: "${bal1_name} cell voltage 7"
    cell_voltage_8:
      name: "${bal1_name} cell voltage 8"
    cell_voltage_9:
      name: "${bal1_name} cell voltage 9"
    cell_voltage_10:
      name: "${bal1_name} cell voltage 10"
    cell_voltage_11:
      name: "${bal1_name} cell voltage 11"
    cell_voltage_12:
      name: "${bal1_name} cell voltage 12"
    cell_voltage_13:
      name: "${bal1_name} cell voltage 13"
    cell_voltage_14:
      name: "${bal1_name} cell voltage 14"
    cell_voltage_15:
      name: "${bal1_name} cell voltage 15"
    cell_voltage_16:
      name: "${bal1_name} cell voltage 16"
    cell_resistance_1:
      name: "${bal1_name} cell resistance 1"
    cell_resistance_2:
      name: "${bal1_name} cell resistance 2"
    cell_resistance_3:
      name: "${bal1_name} cell resistance 3"
    cell_resistance_4:
      name: "${bal1_name} cell resistance 4"
    cell_resistance_5:
      name: "${bal1_name} cell resistance 5"
    cell_resistance_6:
      name: "${bal1_name} cell resistance 6"
    cell_resistance_7:
      name: "${bal1_name} cell resistance 7"
    cell_resistance_8:
      name: "${bal1_name} cell resistance 8"
    cell_resistance_9:
      name: "${bal1_name} cell resistance 9"
    cell_resistance_10:
      name: "${bal1_name} cell resistance 10"
    cell_resistance_11:
      name: "${bal1_name} cell resistance 11"
    cell_resistance_12:
      name: "${bal1_name} cell resistance 12"
    cell_resistance_13:
      name: "${bal1_name} cell resistance 13"
    cell_resistance_14:
      name: "${bal1_name} cell resistance 14"
    cell_resistance_15:
      name: "${bal1_name} cell resistance 15"
    cell_resistance_16:
      name: "${bal1_name} cell resistance 16"
    total_voltage:
      name: "${bal1_name} total voltage"
    temperature_sensor_1:
      name: "${bal1_name} temperature sensor 1"
    temperature_sensor_2:
      name: "${bal1_name} temperature sensor 2"
    total_runtime:
      name: "${bal1_name} total runtime"
    balancing_current:
      name: "${bal1_name} balancing current"
    cell_detection_failed_bitmask:
      name: "${bal1_name} cell detection failed bitmask"
    cell_overvoltage_bitmask:
      name: "${bal1_name} cell overvoltage bitmask"
    cell_undervoltage_bitmask:
      name: "${bal1_name} cell undervoltage bitmask"
    cell_polarity_error_bitmask:
      name: "${bal1_name} cell polarity error bitmask"
    cell_excessive_line_resistance_bitmask:
      name: "${bal1_name} cell excessive line resistance bitmask"      

switch:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    charging:
      name: "${name} charge"
    discharging:
      name: "${name} discharge"
    balancer:
      name: "${name} balance"
    emergency:
      name: "${name} emergency"
  - platform: heltec_balancer_ble
    balancer:
      name: "${bal1_name} balancer"

text_sensor:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    errors:
      name: "${bal1_name} errors"
    total_runtime_formatted:
      name: "${bal1_name} total runtime formatted"
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bal0
    operation_status:
      name: "${bal1_name} operation status"
    total_runtime_formatted:
      name: "${bal1_name} total runtime formatted"
    buzzer_mode:
      name: "${bal1_name} buzzer mode"
    battery_type:
      name: "${bal1_name} battery type"      

interval:
  - interval: 30min
    then:
      - button.press: retrieve_settings_button
syssi commented 1 year ago

Okay, issue identified:

  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    errors:
      name: "${bal1_name} errors"
    total_runtime_formatted:
      name: "${bal1_name} total runtime formatted"
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bal0
    operation_status:
      name: "${bal1_name} operation status"
    total_runtime_formatted:
      name: "${bal1_name} total runtime formatted"

Both sensors (Heltec vs JK) using the same (entity) name:

      name: "${bal1_name} total runtime formatted"
      name: "${bal1_name} total runtime formatted"

Please use something like

  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    errors:
      name: "${name} errors"
    total_runtime_formatted:
      name: "${name} total runtime formatted"
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bal0
    operation_status:
      name: "${bal1_name} operation status"
    total_runtime_formatted:
      name: "${bal1_name} total runtime formatted"

instead.

JohnGalt1717 commented 1 year ago

That fixed it. I feel stupid now. Find and Replace struck.

syssi commented 1 year ago

No problem. You are welcome! :-)