esphome-jk-bms icon indicating copy to clipboard operation
esphome-jk-bms copied to clipboard

Connection to two NEEY balancers breaks down sporadically

Open Elektrofix-OL opened this issue 1 year ago • 7 comments

I have the problem that the ESP32 loses the connection to the two NEEY balancers via BT. Only “nan” is transmitted as measured values.I have the problem with all versions of ESPHome and have already gone back to version 2023.5.4, but after an indefinite period of time (3 hours or 7 days) I no longer receive any data. My Yamel:

substitutions:`
  name: speicher
  device0: akku1
  device1: akku2
  device_description: "Monitor and control a Heltec/NEEY 4A balancer via bluetooth"
  external_components_source: github://syssi/esphome-jk-bms@main
  mac_address: 00:e4:4c:21:d9:cd
  mac_address2: 3c:a5:51:85:e8:4c

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

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

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

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

ota:

logger:
  level: DEBUG
  
# If you don't use Home Assistant please remove this `api` section and uncomment the `mqtt` component!
#api:
#  encryption:
#    key: "q+W4YeOHnu8kOBLz0LYw7uUlWzzRE+NMk6CpfZE856k="

mqtt:
   broker: !secret mqtt_host
   username: !secret mqtt_username
   password: !secret mqtt_password
   id: mqtt_client

esp32_ble_tracker:
  on_ble_advertise:
    then:
      - lambda: |-
          if (x.get_name().rfind("GW-", 0) == 0) {
            ESP_LOGI("ble_adv", "New Heltec/NEEY balancer 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
  - mac_address: ${mac_address2}
    id: client1

heltec_balancer_ble:
  - ble_client_id: client0
    throttle: 30s
    id: bms0
  - ble_client_id: client1
    throttle: 30s
    id: bms1

binary_sensor:
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bms0
    balancing:
      name: "balancing ${device0}"
    online_status:
      name: "online status ${device0}"
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bms1
    balancing:
      name: "balancing ${device1}"
    online_status:
      name: "online status ${device1}"

button:
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bms0
    retrieve_settings:
      name: "retrieve settings ${device0}"
      id: retrieve_settings_button0
    retrieve_device_info:
      name: "retrieve device info ${device0}"
    retrieve_factory_defaults:
      name: "retrieve factory defaults ${device0}"
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bms1
    retrieve_settings:
      name: "retrieve settings ${device1}"
      id: retrieve_settings_button1
    retrieve_device_info:
      name: "retrieve device info ${device1}"
    retrieve_factory_defaults:
      name: "retrieve factory defaults ${device1}"

number:
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bms0
    cell_count:
      name: "cell count ${device0}"
    balance_trigger_voltage:
      name: "balance trigger voltage ${device0}"
    max_balance_current:
      name: "max balance current ${device0}"
    balance_sleep_voltage:
      name: "balance sleep voltage ${device0}"
    balance_start_voltage:
      name: "balance start voltage ${device0}"
    nominal_battery_capacity:
      name: "nominal battery capacity ${device0}"
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bms1
    cell_count:
      name: "cell count ${device1}"
    balance_trigger_voltage:
      name: "balance trigger voltage ${device1}"
    max_balance_current:
      name: "max balance current ${device1}"
    balance_sleep_voltage:
      name: "balance sleep voltage ${device1}"
    balance_start_voltage:
      name: "balance start voltage ${device1}"
    nominal_battery_capacity:
      name: "nominal battery capacity ${device1}"

sensor:
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bms0
    min_cell_voltage:
      name: "min cell voltage ${device0}"
    max_cell_voltage:
      name: "max cell voltage ${device0}"
    min_voltage_cell:
      name: "min voltage cell ${device0}"
    max_voltage_cell:
      name: "max voltage cell ${device0}"
    delta_cell_voltage:
      name: "delta cell voltage ${device0}"
    average_cell_voltage:
      name: "average cell voltage ${device0}"
    cell_voltage_1:
      name: "voltage 01 ${device0}"
    cell_voltage_2:
      name: "voltage 02 ${device0}"
    cell_voltage_3:
      name: "voltage 03 ${device0}"
    cell_voltage_4:
      name: "voltage 04 ${device0}"
    cell_voltage_5:
      name: "voltage 05 ${device0}"
    cell_voltage_6:
      name: "voltage 06 ${device0}"
    cell_voltage_7:
      name: "voltage 07 ${device0}"
    cell_voltage_8:
      name: "voltage 08 ${device0}"
    cell_voltage_9:
      name: "voltage 09 ${device0}"
    cell_voltage_10:
      name: "voltage 10 ${device0}"
    cell_voltage_11:
      name: "voltage 11 ${device0}"
    cell_voltage_12:
      name: "voltage 12 ${device0}"
    cell_voltage_13:
      name: "voltage 13 ${device0}"
    cell_voltage_14:
      name: "voltage 14 ${device0}"
    cell_voltage_15:
      name: "voltage 15 ${device0}"
    cell_voltage_16:
      name: "voltage 16 ${device0}"
    cell_resistance_1:
      name: "resistance 01 ${device0}"
    cell_resistance_2:
      name: "resistance 02 ${device0}"
    cell_resistance_3:
      name: "resistance 03 ${device0}"
    cell_resistance_4:
      name: "resistance 04 ${device0}"
    cell_resistance_5:
      name: "resistance 05 ${device0}"
    cell_resistance_6:
      name: "resistance 06 ${device0}"
    cell_resistance_7:
      name: "resistance 07 ${device0}"
    cell_resistance_8:
      name: "resistance 08 ${device0}"
    cell_resistance_9:
      name: "resistance 09 ${device0}"
    cell_resistance_10:
      name: "resistance 10 ${device0}"
    cell_resistance_11:
      name: "resistance 11 ${device0}"
    cell_resistance_12:
      name: "resistance 12 ${device0}"
    cell_resistance_13:
      name: "resistance 13 ${device0}"
    cell_resistance_14:
      name: "resistance 14 ${device0}"
    cell_resistance_15:
      name: "resistance 15 ${device0}"
    cell_resistance_16:
      name: "resistance 16 ${device0}"
    total_voltage:
      name: "total voltage ${device0}"
    temperature_sensor_1:
      name: "temperature sensor 1 ${device0}"
    temperature_sensor_2:
      name: "temperature sensor 2 ${device0}"
    total_runtime:
      name: "total runtime ${device0}"
    balancing_current:
      name: "balancing current ${device0}"
    # Not implemented
    # errors_bitmask:
    #   name: "errors bitmask ${device0}"
    cell_detection_failed_bitmask:
      name: "cell detection failed bitmask ${device0}"
    cell_overvoltage_bitmask:
      name: "cell overvoltage bitmask ${device0}"
    cell_undervoltage_bitmask:
      name: "cell undervoltage bitmask ${device0}"
    cell_polarity_error_bitmask:
      name: "cell polarity error bitmask ${device0}"
    cell_excessive_line_resistance_bitmask:
      name: "cell excessive line resistance bitmask ${device0}"
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bms1
    min_cell_voltage:
      name: "min cell voltage ${device1}"
    max_cell_voltage:
      name: "max cell voltage ${device1}"
    min_voltage_cell:
      name: "min voltage cell ${device1}"
    max_voltage_cell:
      name: "max voltage cell ${device1}"
    delta_cell_voltage:
      name: "delta cell voltage ${device1}"
    average_cell_voltage:
      name: "average cell voltage ${device1}"
    cell_voltage_1:
      name: "voltage 01 ${device1}"
    cell_voltage_2:
      name: "voltage 02 ${device1}"
    cell_voltage_3:
      name: "voltage 03 ${device1}"
    cell_voltage_4:
      name: "voltage 04 ${device1}"
    cell_voltage_5:
      name: "voltage 05 ${device1}"
    cell_voltage_6:
      name: "voltage 06 ${device1}"
    cell_voltage_7:
      name: "voltage 07 ${device1}"
    cell_voltage_8:
      name: "voltage 08 ${device1}"
    cell_voltage_9:
      name: "voltage 09 ${device1}"
    cell_voltage_10:
      name: "voltage 10 ${device1}"
    cell_voltage_11:
      name: "voltage 11 ${device1}"
    cell_voltage_12:
      name: "voltage 12 ${device1}"
    cell_voltage_13:
      name: "voltage 13 ${device1}"
    cell_voltage_14:
      name: "voltage 14 ${device1}"
    cell_voltage_15:
      name: "voltage 15 ${device1}"
    cell_voltage_16:
      name: "voltage 16 ${device1}"
    cell_resistance_1:
      name: "resistance 01 ${device1}"
    cell_resistance_2:
      name: "resistance 02 ${device1}"
    cell_resistance_3:
      name: "resistance 03 ${device1}"
    cell_resistance_4:
      name: "resistance 04 ${device1}"
    cell_resistance_5:
      name: "resistance 05 ${device1}"
    cell_resistance_6:
      name: "resistance 06 ${device1}"
    cell_resistance_7:
      name: "resistance 07 ${device1}"
    cell_resistance_8:
      name: "resistance 08 ${device1}"
    cell_resistance_9:
      name: "resistance 09 ${device1}"
    cell_resistance_10:
      name: "resistance 10 ${device1}"
    cell_resistance_11:
      name: "resistance 11 ${device1}"
    cell_resistance_12:
      name: "resistance 12 ${device1}"
    cell_resistance_13:
      name: "resistance 13 ${device1}"
    cell_resistance_14:
      name: "resistance 14 ${device1}"
    cell_resistance_15:
      name: "resistance 15 ${device1}"
    cell_resistance_16:
      name: "resistance 16 ${device1}"
    total_voltage:
      name: "total voltage ${device1}"
    temperature_sensor_1:
      name: "temperature sensor 1 ${device1}"
    temperature_sensor_2:
      name: "temperature sensor 2 ${device1}"
    total_runtime:
      name: "total runtime ${device1}"
    balancing_current:
      name: "balancing current ${device1}"
    # Not implemented
    # errors_bitmask:
    #   name: "errors bitmask"
    cell_detection_failed_bitmask:
      name: "cell detection failed bitmask ${device1}"
    cell_overvoltage_bitmask:
      name: "cell overvoltage bitmask ${device1}"
    cell_undervoltage_bitmask:
      name: "cell undervoltage bitmask ${device1}"
    cell_polarity_error_bitmask:
      name: "cell polarity error bitmask ${device1}"
    cell_excessive_line_resistance_bitmask:
      name: "cell excessive line resistance bitmask ${device1}"


switch:
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bms0
    balancer:
      name: "balancer ${device0}"
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bms1
    balancer:
      name: "balancer ${device1}"

text_sensor:
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bms0
    # Not implemented
    # errors:
    #   name: "errors ${device0}"
    operation_status:
      name: "operation status ${device0}"
    total_runtime_formatted:
      name: "total runtime formatted ${device0}"
    buzzer_mode:
      name: "buzzer mode ${device0}"
    battery_type:
      name: "battery type ${device0}"
  - platform: heltec_balancer_ble
    heltec_balancer_ble_id: bms1
    # Not implemented
    # errors:
    #   name: "errors ${device1}"
    operation_status:
      name: "operation status ${device1}"
    total_runtime_formatted:
      name: "total runtime formatted ${device1}"
    buzzer_mode:
      name: "buzzer mode ${device1}"
    battery_type:
      name: "battery type ${device1}"

interval:
  - interval: 30min
    then:
      - button.press: retrieve_settings_button0
      - button.press: retrieve_settings_button1

The displays in the LOG: image Before time to time comes: image If I unplug the ESP32 and restart it, everything is OK. I've already changed the board, no success. What am I doing wrong?

Elektrofix-OL avatar Nov 04 '23 11:11 Elektrofix-OL

Unfortunately I've no idea what's going on here. Could you try to interface a single balancer? I assume there is a timing issue which gets worth if the BLE traffic increases.

syssi avatar Nov 05 '23 15:11 syssi

Did you rename your neey's? That's maybe solve this problem. Use different names

SchwedeGS avatar Nov 15 '23 20:11 SchwedeGS

Exactly the same issue here. There are 2 ESP32s connecting via BT to 2 Neey balancers each. However, I skipped the single-cell datapoints to reduce traffic. Neeys are renamed. I´ll try a single ESP32 for each of the balancers and report back.

stefanK74 avatar Nov 27 '23 07:11 stefanK74

Please make sure you are using the latest ESPHome release (2023.11!). The ble_client implementation was buggy in the past so multiple connections wasn't possible / all traffic was routed to the first BLE client connection and did confuse the remote device probably.

syssi avatar Nov 27 '23 11:11 syssi

It seems as the ESP32s run stable when they have to deal with 1 BT connection only. Using the lastest ESPhome release and multiple BT connections still led to sporadic disconnects. That's why I now use a separate ESP32 for each of the 4 balancers.

stefanK74 avatar Dec 07 '23 08:12 stefanK74

FYI I experienced the same with WEMOS-S3-MINI with these settings:

esphome: name: ${name} platformio_options: platform: https://github.com/platformio/platform-espressif32.git board: lolin_s3_mini framework: espidf board_build.flash_mode: dio build_unflags: -Werror=all

esp32: variant: esp32s3 board: lolin_s3_mini flash_size: 4MB framework: type: esp-idf version: latest sdkconfig_options: CONFIG_ESPTOOLPY_FLASHSIZE_4MB: y

DutchKillerbee avatar Feb 18 '24 20:02 DutchKillerbee

FYI I have had good results with "different throttle time" settings for each ble_client:

heltec_balancer_ble:

  • ble_client_id: client0 throttle: 3s id: bms0
  • ble_client_id: client1 throttle: 5s id: bms1

DutchKillerbee avatar Feb 21 '24 17:02 DutchKillerbee