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
460 stars 154 forks source link

Add JK-PB bms compatibility. Target: 1 ESP in a "listening mode" connected to RS485 network. #464

Open txubelaxu opened 7 months ago

txubelaxu commented 7 months ago

JK-PB2A16S-20P model jk-bms. Two bms connected to that RS485 internal network. ubuntu connected in a "listening mode" using a USB<->RS485 adaptor.

txubelaxu commented 6 months ago

Hi, I'm trying to install the 1 master 6 slaves yaml file and it always fails. This is what I get from logs:

`INFO ESPHome 2024.3.1

INFO Reading configuration /config/esphome/jk-bms.yaml... INFO Updating https://github.com/txubelaxu/esphome-jk-bms.git@main INFO Generating C++ source... INFO Compiling app... Processing esp-rs485-gw (board: esp32dev; framework: espidf; platform: platformio/espressif32@5.4.0) HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash

  • framework-espidf @ 3.40406.240122 (4.4.6)

  • tool-cmake @ 3.16.4

  • tool-ninja @ 1.7.1

  • toolchain-esp32ulp @ 2.35.0-20220830

  • toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5 Reading CMake configuration... Generating assembly for certificate bundle... Dependency Graph |-- noise-c @ 0.1.4 Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_connection.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_frame_helper.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_pb2.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_pb2_service.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/api_server.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/list_entities.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/proto.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/subscribe_state.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/api/user_services.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/binary_sensor/automation.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/binary_sensor/binary_sensor.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/binary_sensor/filter.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/esp32/core.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/esp32/gpio.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/esp32/preferences.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/jk_rs485_bms/jk_rs485_bms.o Compiling .pioenvs/esp-rs485-gw/src/esphome/components/jk_rs485_bms/switch/jk_switch.o In file included from src/esphome/components/jk_rs485_bms/jk_rs485_bms.h:8, from src/esphome/components/jk_rs485_bms/jk_rs485_bms.cpp:1: src/esphome/components/jk_rs485_sniffer/jk_rs485_sniffer.h:9:10: fatal error: binary_output.h: No such file or directory

  • Looking for binary_output.h dependency? Check our library registry!

  • CLI > platformio lib search "header:binary_output.h"

  • Web > https://registry.platformio.org/search?q=header:binary_output.h

include "binary_output.h" ^~~~~ compilation terminated. *** [.pioenvs/esp-rs485-gw/src/esphome/components/jk_rs485_bms/jk_rs485_bms.o] Error 1 In file included from src/esphome/components/jk_rs485_bms/switch/../jk_rs485_bms.h:8, from src/esphome/components/jk_rs485_bms/switch/jk_switch.h:3, from src/esphome/components/jk_rs485_bms/switch/jk_switch.cpp:1: src/esphome/components/jk_rs485_sniffer/jk_rs485_sniffer.h:9:10: fatal error: binary_output.h: No such file or directory

include "binary_output.h" ^~~~~ compilation terminated. *** [.pioenvs/esp-rs485-gw/src/esphome/components/jk_rs485_bms/switch/jk_switch.o] Error 1 ========================== [FAILED] Took 8.25 seconds ==========================`

I'm installing the yaml file via esphome addon in home assistant. What am I doing wrong here? Help will be much appreciated, thanks!

Hi @dgbiuro, could you try with the last update just uploaded now?

Many thanks!!

jogybaer0815 commented 5 months ago

Latest ESPhome update needs changes:

'talk_pin' is a required option for [0]

Where should talk_pin assigned?

txubelaxu commented 5 months ago

Latest ESPhome update needs changes:

'talk_pin' is a required option for [0]

  • id: sniffer0 protocol_version: JK02_32S rx_timeout: 500ms uart_id: uart_0

Where should talk_pin assigned?

Any pin of your choice. It is not mandatory to connect tx_pin to TTL to RS485 converter. It is not mandatory to connect talk_pin to TTL to RS485 converter. Assign to "talk_pin" any free pin that can act as "output".

I have got the code to act as "master" or "pseudo-master". I am publishing this soon. Today or tomorrow, maybe.

txubelaxu commented 5 months ago

@denveronly, have you tried last version with your 7 BMSs? Did it work?

kommando828 commented 5 months ago

When this is fully merged will it allow the outputs to be used to feed an MQTT broker, looking forward to this one now I have my SMA SI's in closed loop with a JK-PB2A16S20P using canbus.

dgbiuro commented 5 months ago

Hi @txubelaxu, sorry it took me so long to respond. The new code is compiling and running but the esp cannot read any data. Here is a part of the logs:

`[19:41:45][I][jk_rs485_sniffer:244]: SILENCE: 207.000000 ms

[19:41:45][D][jk_rs485_sniffer:264]: Buffer before number 1: FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.7F.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.DF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF.FF [19:41:45][D][jk_rs485_sniffer:266]: Response: 4: [19:41:45][W][component:237]: Component jk_rs485_sniffer took a long time for an operation (104 ms). [19:41:45][W][component:238]: Components should block for at most 30 ms. [19:41:45][D][uart_debug:114]: <<< FF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 display_always_on'

[19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 emergency'

[19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 heating'

[19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 charging float mode'

[19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 disable temperature sensors'

[19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 smart sleep on'

[19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 disable pcl module'

[19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][I][jk_rs485_sniffer:330]: SCANNING NEXT UNAVAILABLE...0x02 [19:41:45][C][jk_rs485_bms.switch:068]: JkBms Switch 'rs485-bms0 timed stored data'

[19:41:45][C][jk_rs485_bms.switch:091]: Restore Mode: always OFF [19:41:45][D][uart_debug:114]: >>> 02:10:16:20:00:01:02:00:00:C2:01

My DIP switches and addresses in yaml file are the same. I have one master jk-bms and two slaves. I have shortened the code to just bms-0, 1 and 2. I didn't connect the talk pin as you said it is not mandatory.

Many thanks for helping

txubelaxu commented 5 months ago

hi @dgbiuro,

that is anormal network data. Is it correctly connected to the network?

Talk pin is not mandatory if you want ESP to acting only in "listening mode". It has been impossible for me to get "frame type 3rd" from master (because it is not possible to ask for that information to 0x00). It has been successed to asking for that information to any of the slaves.

D3R-ST3FAN commented 2 months ago

BTW, what do you think of this board for your project? https://github.com/Xinyuan-LilyGO/T-CAN485

I have it laying around from previous project that i was unable to comply due to CAN issues here and not the best specifications of the board (and obviously my knowledge) For RS-485 it can be pretty clean install without soldering i think.

I configured RX GPIO21/ TX GPIO22 as per their documentation. No luck. Maybe there is a driver that needs to be included. Did you have any luck yet using this board?

txubelaxu commented 2 months ago

With last changes, Balancing, Charge and Discharge switch are now working in read & WRITE mode. There is a new setting inside "sniffer" part in the yaml to enable the "broadcast" to all the BMSs when you change one of those switches.

vpritulin commented 1 month ago

@txubelaxu Hi! I'm trying to understand your project and if I understood correctly, you connect the inverter to the battery via rs485 via CAN bus and simultaneously receive data from the inverter also via rs485 or is it not quite like that?

brycelarge commented 1 month ago

Since the last changes I cannot update:

Compiling .pioenvs/jkbms/src/esphome/components/jk_rs485_bms/jk_rs485_bms.o In file included from src/esphome/components/jk_rs485_bms/jk_rs485_bms.cpp:1: src/esphome/components/jk_rs485_bms/jk_rs485_bms.h:3:10: fatal error: switch/jk_switch.h: No such file or directory

include "switch/jk_switch.h"

      ^~~~~~~~~~~~~~~~~~~~

compilation terminated. Compiling .pioenvs/jkbms/src/esphome/components/logger/logger_esp32.o *** [.pioenvs/jkbms/src/esphome/components/jk_rs485_bms/jk_rs485_bms.o] Error 1 ========================== [FAILED] Took 2.63 seconds ==========================

Please also update your 1 master multiple slave examples, seems those are not working anymore either

syssi commented 1 month ago

@brycelarge Did you try a clean build? esphome clean yourconfig.yaml; esphome run yourconfig.yaml or press the CLEAN build files button at the ESPHome dashboard.

brycelarge commented 1 month ago

@brycelarge Did you try a clean build? esphome clean yourconfig.yaml; esphome run yourconfig.yaml or press the CLEAN build files button at the ESPHome dashboard.

Yes I did but still get that issue.

INFO ESPHome 2024.8.0 INFO Reading configuration /config/esphome/jkbms.yaml... INFO Updating https://github.com/txubelaxu/esphome-jk-bms.git@main INFO Deleting /data/build/jkbms/.pioenvs INFO Deleting /data/build/jkbms/.piolibdeps INFO Done!

Compiling .pioenvs/jkbms/src/esphome/components/esp32/gpio.o Compiling .pioenvs/jkbms/src/esphome/components/esp32/preferences.o Compiling .pioenvs/jkbms/src/esphome/components/esphome/ota/ota_esphome.o Compiling .pioenvs/jkbms/src/esphome/components/jk_rs485_bms/jk_rs485_bms.o In file included from src/esphome/components/jk_rs485_bms/jk_rs485_bms.cpp:1: src/esphome/components/jk_rs485_bms/jk_rs485_bms.h:3:10: fatal error: switch/jk_switch.h: No such file or directory

include "switch/jk_switch.h"

      ^~~~~~~~~~~~~~~~~~~~

compilation terminated. *** [.pioenvs/jkbms/src/esphome/components/jk_rs485_bms/jk_rs485_bms.o] Error 1 ========================= [FAILED] Took 19.11 seconds =========================

jogybaer0815 commented 1 month ago

same here: i added for the last updates "broadcast_to_all_bms: True" and that was fine but after the latest updates of ESPHome it is an invalid option. But commenting this offers more errors :( What is going on and what is the solution? Regards

brycelarge commented 1 week ago

Im still getting this error:

In file included from src/esphome/components/jk_rs485_bms/jk_rs485_bms.cpp:1: src/esphome/components/jk_rs485_bms/jk_rs485_bms.h:4:10: fatal error: number/jk_number.h: No such file or directory

include "number/jk_number.h"

      ^~~~~~~~~~~~~~~~~~~~

compilation terminated. *** [.pioenvs/jkbms/src/esphome/components/jk_rs485_bms/jk_rs485_bms.o] Error 1 ========================= [FAILED] Took 21.01 seconds =========================

I'm using 1 master and multiple slaves. I have cleaned build files, also physically SSH into esphome container and deleted all the files in the components dir but still the same error persists. Any ideas?