Jump to content

BMS Pace addon for Home Assistant


tertiuscpt

Recommended Posts

(Updated info further down in the post)

I create a very simple Python script to interrogate the Pace BMS as used in some popular lithium battery brands. I've also packed this as a Home Assistant add-on, but can just as well be used as either a standalone script / within a docker container.

It reports the voltage of cells, temperatures, the pack's current, voltage, SOC, SOH, and a few other metrics.

Use at own risk. 

Either a serial link to the RS232 port or via IP (using some port server over TCP) will work.

Repository: https://github.com/Tertiush/bmspace

The script serves by needs atm, so any further developments can be done by the community.

Screenshot BMS.png

UPDATE:

I've rewritten most of this script using the official PACE RS232 Protocol definition. The script now supports multiple packs!

I've only implemented informational messages / retrieving data, no commands.

Use at own risk!

Many new fields are now retrieved such as warnings, balancing data, status indications, etc.

Edited by tertiuscpt
Updated info
Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 2 months later...

Quick update, I've rewritten most of this script using the official PACE RS232 Protocol definition. The script now supports multiple packs!

I've only implemented informational messages / retrieving data, no commands.

Use at own risk!

Many new fields are now retrieved such as warnings, balancing data, status indications, etc.

Link to comment
Share on other sites

  • 2 months later...

Hi Tertius,

I'm getting the following error in the log after starting the addon. I've cut out the voltage info of my two AM-2 packs from the log to shorten it.

After I get the error below, the addon halts, and I have to start it again.

"
Hello BMS Pace
Starting up
...
-all the voltage info of the two packs-
...
Pack 2, SOH: 100.0 %
Script running....
Pack Remaining Capacity: 124870 mAh
Pack Full Capacity: 125000 mAh
Pack Design Capacity: 125000 mAh
Pack SOC: 99.9 %
Pack SOH: 100.0 %
Packs for warnings: 2
Pack 1, warnings: Protection State 2: Fully
Pack 1, balancing1: 00000000
Pack 1, balancing2: 00000000
Error parsing BMS warning data:  b'0D'
Error retrieving BMS warning info: Error parsing BMS warning data: b'0D'
Publishing HA Discovery topic...
"

I also turned on debugging 2, here's an extract of the bottom part of the log:

"

Pack SOC: 99.89 %
Pack SOH: 100.0 %
SOI:  0x7e
VER:  b'25'
ADR:  b'01'
CID1 (Type):  b'46'
RTN:  b'00'
LENGTH:  b'C08C'
 - LCHKSUM:  67
 - LENID:  b'08C'
 - LENID (int):  140
INFO:  b'00020D0000000000000000000000000006000000000000000000008006000000000000010D000000000000000000000000000600000000000000000000800600000000000000'
CHKSUM:  b'E2ED'
Calc CHKSUM:  E2ED
Packs for warnings: 2
Pack 1, warnings: Protection State 2: Fully
Pack 1, balancing1: 00000000
Pack 1, balancing2: 00000000
Error parsing BMS warning data:  b'0D'
Error retrieving BMS warning info: Error parsing BMS warning data: b'0D'

"

 

Am I missing something?

Link to comment
Share on other sites

The script is reading the warnings as ASCII data, not expecting the hex 0xD character representing a carriage-return.

There's small variances between some BMS' causing this, I've compensated once before for it. Please drop a full debug log at Github in the Issues for me to look at.

Link to comment
Share on other sites

  • 2 weeks later...

I have a Revov R9 with what looks like a PACE BMS and tried to use the pacebms code but RS232 and RS485 is not responding when sending out serial commans.  I'm not sure which port to use for USB to RS485. 

 

 

Revov R9-backplane-COMS.jpeg

Link to comment
Share on other sites

I'm thinking it is either a PACE BMS or CAN BMS.  Revov's earlier model the R100 looks very very similar.  The biggest difference is the BMS is built into the battery on the R100.  @tertiuscpt, I want to confirm, the BAUD is 9600 by default on bmspace software?    How would I set the BAUD to say 2400

@reapster mentioned earlier in this thread the RJ11 jack of the R100 pinout, so I'm hopfull the R9 with its 6S6C type, would most propably have the middle two conductors be TXD, and RXD.  Will be finding a RJ11 with 6 conductors and experimenting with it.

Attached a picture of the front of a R100.

 

R100-front-1.jpg

Edited by lcj
Link to comment
Share on other sites

The PACE documentation requires a baud rate of 9600, as such this is hard-coded in my script. If you are using a networked serial device then you can change the baud rate on it, which the script accesses with its socket IP:Port. If you're connecting directly with serial then its not currently an optional setting. Your photo is an exact layout of the PACE BMS.

Link to comment
Share on other sites

  • 1 month later...

HI, 

I have LifePO4 Batery system called "Yechuang" from China. This system is equiped with Pace BMS..I have tried to connect this BMS to home assistant,

and In log i have found this:

 


Connection Type: IP
MQTT connected with result code 0
Connecting to BMS...
trying to connect 10.0.0.221:8234
BMS socket connected
-> Outgoing Data:  b'~250146C10000FD9A\r'
<- Incoming data:  b'~250146C10000FD9A\r'
SOI:  0x7e
VER:  b'25'
ADR:  b'01'
CID1 (Type):  b'46'
RTN:  b'C1'
LENGTH:  b'0000'
 - LCHKSUM:  48
 - LENID:  b'000'
 - LENID (int):  0
INFO:  b''
CHKSUM:  b'FD9A'
Calc CHKSUM:  FD9A
BMS Version: 
-> Outgoing Data:  b'~250146C20000FD99\r'
<- Incoming data:  b'~250146C20000FD99\r'
SOI:  0x7e
VER:  b'25'
ADR:  b'01'
CID1 (Type):  b'46'
RTN:  b'C2'
LENGTH:  b'0000'
 - LCHKSUM:  48
 - LENID:  b'000'
 - LENID (int):  0
INFO:  b''
CHKSUM:  b'FD99'
Calc CHKSUM:  FD99
BMS Serial Number: 
Pack Serial Number: 
-> Outgoing Data:  b'~25014642E002FFFD05\r'
<- Incoming data:  b'~25014642E002FFFD05\r'
SOI:  0x7e
VER:  b'25'
ADR:  b'01'
CID1 (Type):  b'46'
RTN:  b'42'
LENGTH:  b'E002'
 - LCHKSUM:  69
 - LENID:  b'002'
 - LENID (int):  2
INFO:  b'FF'
CHKSUM:  b'FD05'
Calc CHKSUM:  FD05
Error parsing BMS analog data:  invalid literal for int() with base 16: b''
Error retrieving BMS analog data: Error parsing BMS analog data: invalid literal for int() with base 16: b''

Any idea what I sholuld do ??

Thanks

Link to comment
Share on other sites

On 2023/07/12 at 8:24 PM, IrcI said:

HI, 

I have LifePO4 Batery system called "Yechuang" from China. This system is equiped with Pace BMS..I have tried to connect this BMS to home assistant,

and In log i have found this:

 


Connection Type: IP
MQTT connected with result code 0
Connecting to BMS...
trying to connect 10.0.0.221:8234
BMS socket connected
-> Outgoing Data:  b'~250146C10000FD9A\r'
<- Incoming data:  b'~250146C10000FD9A\r'
SOI:  0x7e
VER:  b'25'
ADR:  b'01'
CID1 (Type):  b'46'
RTN:  b'C1'
LENGTH:  b'0000'
 - LCHKSUM:  48
 - LENID:  b'000'
 - LENID (int):  0
INFO:  b''
CHKSUM:  b'FD9A'
Calc CHKSUM:  FD9A
BMS Version: 
-> Outgoing Data:  b'~250146C20000FD99\r'
<- Incoming data:  b'~250146C20000FD99\r'
SOI:  0x7e
VER:  b'25'
ADR:  b'01'
CID1 (Type):  b'46'
RTN:  b'C2'
LENGTH:  b'0000'
 - LCHKSUM:  48
 - LENID:  b'000'
 - LENID (int):  0
INFO:  b''
CHKSUM:  b'FD99'
Calc CHKSUM:  FD99
BMS Serial Number: 
Pack Serial Number: 
-> Outgoing Data:  b'~25014642E002FFFD05\r'
<- Incoming data:  b'~25014642E002FFFD05\r'
SOI:  0x7e
VER:  b'25'
ADR:  b'01'
CID1 (Type):  b'46'
RTN:  b'42'
LENGTH:  b'E002'
 - LCHKSUM:  69
 - LENID:  b'002'
 - LENID (int):  2
INFO:  b'FF'
CHKSUM:  b'FD05'
Calc CHKSUM:  FD05
Error parsing BMS analog data:  invalid literal for int() with base 16: b''
Error retrieving BMS analog data: Error parsing BMS analog data: invalid literal for int() with base 16: b''

Any idea what I sholuld do ??

Thanks

Seems like your Rx and Tx lines are either shorted somewhere or for some other reason you are reading back the exact commands being sent out. What does your setup look like, and how is your IP to serial converter configured? Should be in TCP Server mode

Link to comment
Share on other sites

Hi,

You have right...I have had bad wiring...After fixing seems to work well. 

I can confirm that now i it work well with BMS PACE ver: P16S100A-21265-1.03. 

Batteries producer: Yechuang

I have 3 Pack 15KWh each.

 

Thank you for great work and support.

 

Link to comment
Share on other sites

  • tertiuscpt changed the title to BMS Pace addon for Home Assistant
  • 2 months later...

Hi
 

I have 3x Leoch lfeli-48200tb.
When paraller install, maximum charge current 20A/batterypack,
This is not enought my install (3x5kw inverter). 

Therefore i change my batterypack dip switch standalone mod.

My question is, is there any way to start the program 3 times or add 3 serial ports somehow?

Thanks!

Link to comment
Share on other sites

  • 2 months later...

Sorry but I am struggeling with the basics.

I do have a System from Tewaycell Tewaycell 48V 200Ah 10Kwh All-in-one Mobile ESS Built-in Hybrid Invert and they provided a RS232 to USB Cable with it.

They also sent the PACEexTool but its completely in Chinese.

Now i found your Home Assistant integration. 😀

Can you explain a bit more how i do get the basic connection?
I think i need to install the USB driver for Linux first on the Homeassistant Raspberry. Is that possible?
Then i have questions for the requirements:
paho_mqtt==1.6.1
PyYAML==6.0.1
pyserial==3.5

I dont know how to get the reuirements.

I have Mosquito MQTT and use it already for my OpenDTU and ESP32 

 

Link to comment
Share on other sites

  • 1 month later...

Hi,

@XBoxBro Did you already fix your probs? I am strandet at same point as you

 I also have home assistant running with mosquito as mqtt server. I manged to add "BMS Pace Interface" but do not know who to get on.

The protokoll shows up with this:

Hello BMS Pace
Starting up...
Loading options.json
Config: {"mqtt_host": "10.0.0.132", "mqtt_port": 1883, "mqtt_user": "mqtt-users", "mqtt_password": "mqtt", "mqtt_ha_discovery": true, "mqtt_ha_discovery_topic": "homeassistant", "mqtt_base_topic": "bmspace", "connection_type": "Serial", "bms_ip": "10.0.0.161", "bms_port": 5000, "bms_serial": "/dev/ttyUSB0", "scan_interval": 5, "debug_output": 0}
Connection Type: Serial
Traceback (most recent call last):
  File "/workdir/./bms.py", line 75, in <module>
    client.connect(config['mqtt_host'], config['mqtt_port'], 60)
  File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 914, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 1044, in reconnect
    sock = self._create_socket_connection()
  File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection
    return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
  File "/usr/local/lib/python3.9/socket.py", line 844, in create_connection
    raise err
  File "/usr/local/lib/python3.9/socket.py", line 832, in create_connection
    sock.connect(sa)
socket.timeout: timed out

 

 

I don´t even know how to get "paho_mqtt" (if I can not use mosquito)

M

Link to comment
Share on other sites

  • 1 month later...

Hi @DocFog

Yes i did it! TODAY :)

My setup:

  1. Batterysystem: https://tewaycell.com/products/tewaycell-48v-200ah-10kwh-all-in-one-mobile-ess-built-in-hybrid-inverter?variant=41313098858553
  2. Rs232to Eth: https://www.waveshare.com/wiki/RS485_TO_WIFI/ETH

Installed bmspace Addon- its really JUST install the addon. NO prerequisits needed!

Configured:

image.thumb.png.31fcb71a6376aa59c9abdb15918e76ed.png

Configured the Waveshare (with VirCom_en.exe) as follows:

image.png.397da45d01cc24c60740c46f8d672945.png
Afterwards the Addon could connect and i directly retrieved:

Quote

Pack Serial Number:xxxxxxxxxxxxxxxxx
Packs: 1
Pack 1, Total cells: 16
Pack 1, V Cell1: 3281 mV
Pack 1, V Cell2: 3280 mV
Pack 1, V Cell3: 3281 mV
Pack 1, V Cell4: 3281 mV
Pack 1, V Cell5: 3281 mV
Pack 1, V Cell6: 3280 mV
Pack 1, V Cell7: 3280 mV
Pack 1, V Cell8: 3280 mV
Pack 1, V Cell9: 3280 mV
Pack 1, V Cell10: 3280 mV
Pack 1, V Cell11: 3279 mV
Pack 1, V Cell12: 3279 mV
Pack 1, V Cell13: 3279 mV
Pack 1, V Cell14: 3279 mV
Pack 1, V Cell15: 3279 mV
Pack 1, V Cell16: 3278 mV
Pack 1, Cell Max Diff Volt Calc: 3 mV
Pack 1, Total temperature sensors: 6
Pack 1, Temp1: 23.7 ℃
Pack 1, Temp2: 22.0 ℃
Pack 1, Temp3: 20.3 ℃
Pack 1, Temp4: 19.5 ℃
Pack 1, Temp5: 29.8 ℃
Pack 1, Temp6: 26.4 ℃
Pack 1, I Pack: -1.17 A
Pack 1, V Pack: 52.477 V
Pack 1, I Remaining Capacity: 73750 mAh
Pack 1, I Full Capacity: 200000 mAh
Pack 1, SOC: 36.88 %
Pack 1, Cycles: 15
Pack 1, Design Capacity: 190000 mAh
Pack 1, SOH: 105.26 %
Script running....
Pack Remaining Capacity: 73750 mAh
Pack Full Capacity: 200000 mAh
Pack Design Capacity: 190000 mAh
Pack SOC: 36.88 %
Pack SOH: 105.26 %
Packs for warnings: 1
Pack 1, warnings:
Pack 1, balancing1: 00000000
Pack 1, balancing2: 00000000
Publishing HA Discovery topic...

Many thanks for this Addon !!!!!!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...