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
474 stars 161 forks source link

Multiple BLE connections not possible anymore since ESPHome 2022.9.3 #189

Closed Manu0171discord closed 1 year ago

Manu0171discord commented 2 years ago

Hi, I tried the example yaml file to manage 2 jkbms with 1 esp32 jkbms is compliant as described into the yaml file

https://github.com/syssi/esphome-jk-bms/blob/main/esp32-ble-example-multiple-devices.yaml

The first jkbms which is kept by the BT connection of the esp32 is the only one no connection with the second jkbms (different mac address from the 1st one)

In summary, only can have data into HA/esphome for 1 jkbms (bms0 and bms1 values are the same)

NB : if you modify this script for 1 jkbms / 1 esp32 it works but you will have 2 esp32 and not 1 esp32

syssi commented 2 years ago

Please check your ESPHome version. There was a bug in the past which leads to the described behavior. Please update ESPHome to the latest release + compile & flash the node again.

Bandit-17 commented 2 years ago

Hello Sebastian, we are using the dev version of esphome with anaconda (version: 2022.10.0-dev)

here is the file we are working on teste2bmsble.txt

unfortunately we have the values ​​of the 1st BMS which is grafted onto the 2nd (see capture) unknown

Bandit-17 commented 2 years ago

we try to integrate the BLE part of the JKBMS in the Pvbrain, to recover the information not available with the RS485.

syssi commented 2 years ago

This is strange. Could you try the IDF framework instead if Arduino?

syssi commented 2 years ago

Another idea: May be multiple BLE clients are broken (again) at ESPHome 2022.10.0. Please downgrade to 2022.8.3 by:

pip3 install esphome==2022.8.3

And use the ESPHome 2022.8.3 compatible release of this external component:

substitutions:
  external_components_source: github://syssi/esphome-jk-bms@1.3.0

Are you able to monitor two JK-BMS simultaneously now?

Bandit-17 commented 2 years ago

We try on a 2nd Esp32 to validate before integrating on the Pvbrain, I will let you know, thank you for your incredible work

Manu0171discord commented 2 years ago

We, bandit17 and I tried following your instructions but it does not work neither this way. The Root cause might be elsewhere.

syssi commented 2 years ago

Alright. I'm back home in a few days and will try to reproduce the issue on my testbench.

Manu0171discord commented 2 years ago

We thank you very much for your time and work you've done there is no emergency for sure but if you can reproduce the case, it is very nice.

syssi commented 2 years ago

@proasnet May be this issue is relevant for you too or you are able to verify multiple BLE client connections are still working.

Long story short: @Bandit-17 and @Manu0171discord are trying to talk to 2 BMS using one ESP32. If I remember correctly you are doing the same successfully(?).

proasnet commented 2 years ago

Yes, right.

proasnet commented 2 years ago

But, one month before some ESPHome update, both BMS worked via BT on the one ESP32. Now not. If you remember, here is my first ask, and you help me. After this time, all worked fine. https://github.com/syssi/esphome-jk-bms/issues/160

syssi commented 2 years ago
[12:49:57][I][app:102]: ESPHome version 2022.9.1 compiled on Sep 22 2022, 12:47:24
# https://github.com/syssi/esphome-jk-bms/issues/160#issuecomment-1254943112
proasnet commented 2 years ago

Yes, we have addressed this. This seems to be the problem, not in the wifi, but as described in this post @Bandit-17 and @Manu0171discord are trying to talk to 2 BMS using one ESP32.

proasnet commented 2 years ago

As I read, is needed downgrade ESPHome?

syssi commented 2 years ago

Could you try to compare the behavior of the most recent ESPHome version:

pip3 install esphome==2022.9.4 -U

plus

substitutions:
  external_components_source: github://syssi/esphome-jk-bms@main

Versus the ESPHome version you did use successfully in the past:

pip3 install esphome==2022.9.1 -U
substitutions:
  external_components_source: github://syssi/esphome-jk-bms@1.3.0

Do you see a difference?

proasnet commented 2 years ago

I am sorry, where I use this command? In the terminal, not working... bash: command not found pip3 install esphome==2022.9.1 -U I am lama :D

syssi commented 2 years ago

If you use the Home Assistant Addon are you able to up-/downgrade the ESPHome version? If not I will explain how to install esphome manually and use it (for testing) at the terminal.

proasnet commented 2 years ago

I can not downgrade ESPHome. In addons, I can get only latest version.

syssi commented 2 years ago

Alright. Do you have access to a linux host? You could try to follow this tutorial:

Screen recording

proasnet commented 2 years ago

You mean another PC with linux? Not now, I am in work with win PC, but at home I have PC with ubuntu

syssi commented 2 years ago

Let's install esphome on your ubuntu machine as soon you are back at home.

proasnet commented 2 years ago

I have the option to install ESPHome in docker in the synology server, but then I don't know how to get to his files, I don't understand these Linux things that much.

Bez názvu

proasnet commented 2 years ago

I am sorry, my ubuntu pc not working. I cant test it for you. Now I am trying update ESPHome to 2022.10.0 with backup previous.

Update device and compiling has theese warnings:

src/esphome/components/esp32_ble_client/ble_client_base.cpp: In member function 'float esphome::esp32_ble_client::BLEClientBase::parse_char_value(uint8_t*, uint16_t)':
src/esphome/components/esp32_ble_client/ble_client_base.cpp:220:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
       if (length > 2) {
       ^~
src/esphome/components/esp32_ble_client/ble_client_base.cpp:223:5: note: here
     case 0x7:  // uint24.
     ^~~~
src/esphome/components/esp32_ble_client/ble_client_base.cpp:224:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
       if (length > 3) {
       ^~
src/esphome/components/esp32_ble_client/ble_client_base.cpp:227:5: note: here
     case 0x8:  // uint32.
     ^~~~
src/esphome/components/esp32_ble_client/ble_client_base.cpp:228:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
       if (length > 4) {
       ^~
src/esphome/components/esp32_ble_client/ble_client_base.cpp:231:5: note: here
     case 0xC:  // int8.
     ^~~~
src/esphome/components/esp32_ble_client/ble_client_base.cpp:235:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
       if (length > 2) {
       ^~
src/esphome/components/esp32_ble_client/ble_client_base.cpp:238:5: note: here
     case 0xF:  // int24.
     ^~~~
src/esphome/components/esp32_ble_client/ble_client_base.cpp:239:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
       if (length > 3) {
       ^~
src/esphome/components/esp32_ble_client/ble_client_base.cpp:242:5: note: here
     case 0x10:  // int32.
     ^~~~
proasnet commented 2 years ago

So done. Now, after update, entities from the second bms not exist. Before update, entities of the second bms was in HA, but static with zeroes or other last values.

proasnet commented 2 years ago

New status: The second BMS has after some time the same values as the first BMS. The real values of the second BMS is not readed. The second BMS is not really connected. LED on device flashing. ha_2bat

syssi commented 2 years ago

You are using the most recent ESPHome release now because you are unable to downgrade to a previous version. Correct?

proasnet commented 2 years ago

Yes, as you write. Your project is super, I will wait for your update. I don't want another solution, I like using one ESP with BLE for 2 BMS.

syssi commented 2 years ago

It looks like the BLE client component of ESPHome 2022.10.1 is broken. Please be careful: https://github.com/esphome/issues/issues/3729

syssi commented 2 years ago

I did start my second JK-BMS today. First findings:

The simultaneous communication with multiple devices is working fine:

Broken versions:

proasnet commented 2 years ago

that's a good find. Will it be fixed in the new version? Or is it necessary to downgrade? Very thanks.

syssi commented 2 years ago

The root cause is identified and fixed here: https://github.com/esphome/esphome/commit/0e66c899ce57b304a7697bf4859806e78a07325c

It should work (again) as soon ESPHome dev gets released in a few days!

Softface commented 2 years ago

gooood ! ᐧ

On Sun, Nov 6, 2022 at 8:05 PM Sebastian Muszynski @.***> wrote:

The root cause is identified and fixed here: @.*** https://github.com/esphome/esphome/commit/0e66c899ce57b304a7697bf4859806e78a07325c

It should work (again) as soon ESPHome dev gets released in a few days!

— Reply to this email directly, view it on GitHub https://github.com/syssi/esphome-jk-bms/issues/189#issuecomment-1304871020, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADVZ5NMLBNOQMMQT5YGVYVLWG76OXANCNFSM6AAAAAARCERW2A . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Fierofiend commented 1 year ago

I just updated to 2022.11.0 and it seems to be fixed. I am running 10.X-W (10.03) and 8.X (8.20G).

proasnet commented 1 year ago

Hi @Fierofiend , I am updated HA CORE, ESPHOME and jk-bms node today to last versions, but values of both bms is returned as the same from one bms, no change from previous versions. I see log from jk-bms and see the same values from both. bms0 and bms1 has the same values, but physicaly has not the same values.

proasnet commented 1 year ago

obrazek


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:8C:E4:51:FA
  bms1_mac_address: C8:47:8C:E4:52:9D
  bms0_protocol_version: JK02
  bms1_protocol_version: JK02

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

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

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

wifi:
  ssid: !secret wifi_ssid_0
  password: !secret wifi_password

ota:

logger:

api:

esp32_ble_tracker:

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: 10s
    id: bms0
  - ble_client_id: client1
    protocol_version: ${bms1_protocol_version}
    throttle: 10s
    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"

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

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"
    balance_starting_voltage:
      name: "${bms0} balance starting voltage"
    power_off_voltage:
      name: "${bms0} power off voltage"
    # ...

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    balance_trigger_voltage:
      name: "${bms1} balance trigger voltage"
    balance_starting_voltage:
      name: "${bms1} balance starting voltage"
    power_off_voltage:
      name: "${bms1} power off voltage"
    # ...

sensor:
  - platform: jk_bms_ble
    jk_bms_ble_id: bms0
    delta_cell_voltage:
      name: "${bms0} delta cell voltage"
    average_cell_voltage:
      name: "${bms0} average cell voltage"
    total_voltage:
      name: "${bms0} total voltage"
    current:
      name: "${bms0} current"
    power:
      name: "${bms0} power"
    temperature_sensor_1:
      name: "${bms0} temperature sensor 1"
    temperature_sensor_2:
      name: "${bms0} temperature sensor 2"
    power_tube_temperature:
      name: "${bms0} power tube temperature"
    state_of_charge:
      name: "${bms0} state of charge"
    capacity_remaining:
      name: "${bms0} capacity remaining"
    charging_cycles:
      name: "${bms0} charging cycles"
    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"
    # ...

  - platform: jk_bms_ble
    jk_bms_ble_id: bms1
    delta_cell_voltage:
      name: "${bms1} delta cell voltage"
    average_cell_voltage:
      name: "${bms1} average cell voltage"
    total_voltage:
      name: "${bms1} total voltage"
    current:
      name: "${bms1} current"
    power:
      name: "${bms1} power"
    temperature_sensor_1:
      name: "${bms1} temperature sensor 1"
    temperature_sensor_2:
      name: "${bms1} temperature sensor 2"
    power_tube_temperature:
      name: "${bms1} power tube temperature"
    state_of_charge:
      name: "${bms1} state of charge"
    capacity_remaining:
      name: "${bms1} capacity remaining"
    charging_cycles:
      name: "${bms1} charging cycles"
    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"
    # ...

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
    name: "${bms0} enable bluetooth connection"
  - platform: ble_client
    ble_client_id: client1
    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"
syssi commented 1 year ago

@proasnet On boot-up the ESPHome node reports the used ESPHome version at the log. Could you make sure you are using a 2022.11 build? I don't think so.

proasnet commented 1 year ago

You think this?

INFO Reading configuration /config/esphome/jk_bms.yaml...
INFO Updating https://github.com/syssi/esphome-jk-bms.git@main
INFO Starting log output from jk-bms.local using esphome API
INFO Successfully connected to jk-bms.local
[06:21:39][I][app:102]: ESPHome version 2022.10.2 compiled on Nov  4 2022, 09:16:55
[06:21:39][I][app:104]: Project syssi.esphome-jk-bms version 1.2.0

So, I see it. Probably I must clean build files and try install again.

syssi commented 1 year ago

Yes! This 2022.10.2 indicates you are not using ESPHome 2022.11 and you did not reflash the ESP recently (Nov 4 2022, 09:16:55). Please give it another try! :-)

proasnet commented 1 year ago

Is interesting, that if I update ESPHome, I will see "UPDATE" on each node, I use it, but is not updated new version of ESPHome. Now, I know it :) So, cleaned build files, installed to node again, and result is: Working !!! Thank you very much !