|
| 1 | +# esphome gathering info from multiple JK-PB BMSs usign RS485 internal network |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +ESPHome component to monitor a Jikong Battery Management System (JK-PB) via ESP SERIAL (UART-TTL) + SERIAL TO RS485 + ETHERNET CABLE |
| 8 | +In theory 1 ESP can gather information of every BMS in the RS485 network: MAX 16. |
| 9 | + |
| 10 | +The BMS bluetooth remains free to use with your mobile. |
| 11 | + |
| 12 | +## REMINDER |
| 13 | + |
| 14 | +* Use this at your own risk |
| 15 | + |
| 16 | +## Supported devices |
| 17 | + |
| 18 | +JK-PBx models with software version `>=14.0` are using the implemented protocol and should be supported. |
| 19 | + |
| 20 | +* JK-PB2A16S-20P, hw 14.XA, sw 14.20, using `JK02_32S` (reported by [@txubelaxu]) |
| 21 | +* JK-PBx, hw 15.XA, sw 15.11, using `JK02_32S` (reported by [@denveronly]) |
| 22 | + |
| 23 | +## Untested devices |
| 24 | + |
| 25 | +* JK-PB1A16S-20P, hw 15.XA, |
| 26 | + |
| 27 | +## Requirements |
| 28 | + |
| 29 | +* [ESPHome 2022.11.0 or higher] (https://github.com/esphome/esphome/releases). |
| 30 | +* Generic ESP32 or ESP8266 board |
| 31 | +* SERIAL TTL to RS485 converter |
| 32 | +* Ethernet type cable (one side with RJ45, the other side 3 wires: A, B and GND) |
| 33 | + |
| 34 | + |
| 35 | +# IMPORTANT THINGS ABOUT RS485: |
| 36 | + * IN THEORY, IN A RS485 NETWORK ONE (ONLY ONE) DEVICE CAN BE THE MASTER. |
| 37 | + * In a JK-RS485 internal netwok: |
| 38 | + + the MASTER is the one that has 0x00 (address) Use DIP switches to assign this address. |
| 39 | + + other BMSs connected to the JK-RS485 internal network need a different address. So: 0x01 or 0x02 or 0x03... or 0x0F |
| 40 | + + each BMS in the network must have a different address. Use DIP switches to assign these addresses. |
| 41 | + |
| 42 | +The ESP with this code needs NO RS485 address to work.. But it needs a yaml file configured properly. The yaml content must be equal to the real situation of the amount of BMSs and their addresses in the network. How does ESP code work? |
| 43 | + |
| 44 | +MODE 1. If there is a JK-BMS acting as REAL MASTER (i.e. it has set 0x00 address), the code will be sniffing all the traffic in the network. The problem is that there is some information that is NEVER in the sniffed traffic information (device info frame type 03): device-name, hw version, sw version, password, RCV Time, RFV Time... |
| 45 | +So, periodically, ESP code will act as a PSEUDO-MASTER to try to get this information. It works for every slave device, but not for master device. At this moment, master device does NOT broadcast by itself the "frame type 03" info. And it does not answer to a "frame type 03" request sent by PSEUDO MASTER. |
| 46 | + |
| 47 | +MODE 2. If every JK-BMS are set as SLAVES (all of them), the ESP code will act as MASTER. So, if ESP code does not detect any REAL MASTER in the network, it will act as a MASTER. Remember to adapt DIP switches and the YAML (addresses) as well. Changing the addreses of the devices does not affect to the historic data gathered from that device, because the config is based on the NAME of the device and not on the address of the device. So, change the address, but not the name. In this mode, ESP will gather all the information (cell info, device settings and device info). If anytime, a REAL MASTER arrives to the network, ESP will detect it and will stop acting as MASTER. |
| 48 | + |
| 49 | +In any of the two modes ESP needs to SPEAK to the JK-RS485 internal network. That is why it needs a "SPEAKING PIN OUT" to direct a signal to the "TTL to RS485" converter. There are schematics below. It is not mandatory to connect this pin to gather some info. But if it is not connected it could not ask for some information, and it can not act as a MASTER. But the code should work in the same way until this version. Any way, connected or not, it must be a "talk pin" in the config. |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +## Schematics |
| 55 | + |
| 56 | +``` |
| 57 | + CONVERTER UART-TTL |
| 58 | +┌──────────┐ ┌───────────┐ ┌─────────┐ |
| 59 | +│ │<----- A ----->│ SERIAL │<-----------------Vcc--│ │<--Vcc |
| 60 | +│ JK-BMS │<----- B ----->│ TTL TO │ │ ESP32/ │ |
| 61 | +│ │ │ RS485 │--RO---------------RX->│ ESP8266 │ |
| 62 | +│ │ │ │<-DI---------------TX--│ │ |
| 63 | +│ │ │ CONVERTER │<-DE-----+ │ │ |
| 64 | +│ │ │ │<-RE-----└---TALK PIN--│ │ |
| 65 | +│ │ │ │ │ │ |
| 66 | +| |<------GND----->| |<----------GND-------->| |<--GND |
| 67 | +└──────────┘ └───────────┘ └─────────┘ |
| 68 | + |
| 69 | +
|
| 70 | +# ESP32 UART-TTL (PINOUT ASIGNMENT EXAMPLE) |
| 71 | +┌──────────────────────────────┐ |
| 72 | +│ │ |
| 73 | +│ O O O O O │ |
| 74 | +│ GND RX TX talk Vcc │ |
| 75 | +└──────────────────────────────┘ |
| 76 | + ^ ^ ^ ^ ^ |
| 77 | + │ │ │ | └──── Vcc |
| 78 | + │ │ | └────────── GPIO16 |
| 79 | + │ │ └──────────────── GPIO17 |
| 80 | + │ └────────────────────── GPIO4 |
| 81 | + └──────────────────────────── GND |
| 82 | +
|
| 83 | +# HOW TO CONNECT RS485-2 BUS: |
| 84 | +FIRST: CONNECT ALL THE BMSs IN CHAIN |
| 85 | +SECOND: CONNECT THE SNIFFER (ESP32->RS485 CONVERTER->) AT ONE END OF THE CHAIN |
| 86 | +``` |
| 87 | + |
| 88 | + |
| 89 | + Thanks to [TheSmartGerman](https://github.com/TheSmartGerman) for previous picture. The RS485 connectors are the 2 connectors on the right. |
| 90 | + |
| 91 | +pinout: |
| 92 | + |
| 93 | + |
| 94 | +``` |
| 95 | +Usable any of the two connectors: |
| 96 | +┌─────────────────────────┐ ┌─────────────────────────┐ ┌─────────────────────────┐ ┌─────────────────────────┐ |
| 97 | +│ │ │ │ │ │ │ │ |
| 98 | +│ O O O O O O O O │ OR │ O O O O O O O O │ OR │ O O O O O O O O │ OR │ O O O O O O O O │ |
| 99 | +│ 1 2 3 4 5 6 7 8 │ │ 9 10 11 12 13 14 15 16 │ │ 1 2 3 4 5 6 7 8 │ │ 9 10 11 12 13 14 15 16 │ |
| 100 | +└─────────────────────────┘ └─────────────────────────┘ └─────────────────────────┘ └─────────────────────────┘ |
| 101 | + │ │ │ │ │ │ │ │ │ │ │ │ |
| 102 | + │ │ └──── GND │ │ └──── GND GND ───┘ │ │ GND ─┘ │ │ |
| 103 | + │ └─────── A │ └─────── A A ──────┘ │ A ────┘ │ |
| 104 | + └────────── B └────────── B B ─────────┘ B ───────┘ |
| 105 | +``` |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | +## Installation |
| 110 | + |
| 111 | +just use the `esp32-example-jkpb-rs485.yaml` as proof of concept: |
| 112 | + |
| 113 | +``` |
| 114 | +bash |
| 115 | +# Install esphome |
| 116 | +python3 -m pip install esphome |
| 117 | +
|
| 118 | +# Clone this external component |
| 119 | +git clone https://github.com/txubelaxu/esphome-jk-bms.git |
| 120 | +cd esphome-jk-bms |
| 121 | +
|
| 122 | +# Create a secrets.yaml containing some setup specific secrets |
| 123 | +cat > secrets.yaml <<EOF |
| 124 | +wifi_ssid: MY_WIFI_SSID |
| 125 | +wifi_password: MY_WIFI_PASSWORD |
| 126 | +EOF |
| 127 | +
|
| 128 | +There is a example configuration (0 master and 2 slaves) that you can change to your needs: |
| 129 | +- esp32-S3-example-jkpb-rs485_0master_2slaves.yaml <> a config of 0 master and 2 slave (total: 2 JK-PB BMSs) |
| 130 | +
|
| 131 | +
|
| 132 | +# Configure every BMS you have in this yaml, assigning a name and the address of each one. |
| 133 | +
|
| 134 | +
|
| 135 | +
|
| 136 | +## VALIDATE CODE + UPLOAD + LAUNCH + VIEW LOGS: |
| 137 | +
|
| 138 | +# Validate the configuration, create a binary, upload it, and start logs |
| 139 | +esphome run esp32-S3-example-jkpb-rs485_0master_2slaves.yaml |
| 140 | +
|
| 141 | +(previous example has 2 SLAVES at address 0x01 and at address 0x02). |
| 142 | +
|
| 143 | +
|
| 144 | +## Known issues |
| 145 | +
|
| 146 | +* ?? |
| 147 | +
|
| 148 | +## TO DO |
| 149 | +
|
| 150 | +* Communication to INVERTER SYSTEM. |
| 151 | +
|
| 152 | +
|
| 153 | +## Goodies |
| 154 | +
|
| 155 | +A user of this project ([@dr3amr](https://github.com/dr3amr)) shared some [Home Assistant Lovelace UI cards for a beautiful dashboard here](https://github.com/syssi/esphome-jk-bms/discussions/230). |
| 156 | +
|
| 157 | + |
| 158 | +
|
| 159 | +## Debugging |
| 160 | +
|
| 161 | +If this component doesn't work out of the box for your device please update your configuration to enable the debug output of the UART component and increase the log level to the see outgoing and incoming serial traffic: |
| 162 | +
|
| 163 | +logger: |
| 164 | + level: DEBUG |
| 165 | +
|
| 166 | +``` |
| 167 | + |
| 168 | +## MUCH MORE |
| 169 | +Added a <a href="./home_assistant_dashboards/">Home Assistant Dashboard</a> |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | +## References |
| 179 | + |
| 180 | +* https://secondlifestorage.com/index.php?threads/jk-b1a24s-jk-b2a24s-active-balancer.9591/ |
| 181 | +* https://github.com/jblance/jkbms |
| 182 | +* https://github.com/jblance/mpp-solar/issues/112 |
| 183 | +* https://github.com/jblance/mpp-solar/blob/master/mppsolar/protocols/jk232.py |
| 184 | +* https://github.com/jblance/mpp-solar/blob/master/mppsolar/protocols/jk485.py |
| 185 | +* https://github.com/sshoecraft/jktool |
| 186 | +* https://github.com/Louisvdw/dbus-serialbattery/blob/master/etc/dbus-serialbattery/jkbms.py |
| 187 | +* https://blog.ja-ke.tech/2020/02/07/ltt-power-bms-chinese-protocol.html |
0 commit comments