Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for JK BMS #19

Closed
4 tasks done
downset opened this issue May 30, 2024 · 60 comments · Fixed by #21
Closed
4 tasks done

Support for JK BMS #19

downset opened this issue May 30, 2024 · 60 comments · Fixed by #21
Assignees
Labels
enhancement New feature or request

Comments

@downset
Copy link

downset commented May 30, 2024

Checklist

  • I have filled out the template to the best of my ability.
  • I have understood that this integration is only about battery management systems with Bluetooth Low Energy support.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

I would love to see support for the new JK Inverter BMS.

Describe the solution you'd like

Found your project through the Offgrid Garage video and have the same problem as Andy with the Batmon addon, because i would like to use the ESPHome BLE proxy.
So your project would be a perfekt solution.
Are you planing to add the JK Inverter BMS to your solution?
I opened this Feature Request to track the progress (if integration is planed) and maybe can help Beta testing
Best Regards

Additional context

No response

@patman15
Copy link
Owner

Hi @downset, as I do not own such a BMS, I would need more information in order to be able to add it to the supported BMS as I need to be able to test the implementation to assure some quality. Can you specify in more detail, which BMS you are looking at? JK seems to have a number of different ones ...
Do you have any documentation regarding the protocol? Is there other software supporting this BMS? Last resort would be that (with your extensive support) we could try to reverse engineer the most important communication parts.

@downset
Copy link
Author

downset commented May 30, 2024

Thanks for the reply.
For me I'm speaking about the JK-PB2A16S-20P but i think all JK-PB'X'A16S-'XX'P have same protocol
offgrid garage is using this BMS with the Batmon HA Addon in his Video und seams as it work with the from him called "JK" protocol, but not with Bluetooth proxy caused this is an Addon and no Integation in HA as yours, thought maybe it would be easy to Integrate this code as well... but maybe its not so simple...
Please tell me if i can help in any way
The Data to the BMS:
https://www.jkbms.com/product/jk-pb2a16s20p-jk-pb2a16s-20p/

@patman15
Copy link
Owner

Thanks a lot, that is already good information for me. If it works with the Batmon HA and the protocol "JK" it should be doable. I tried to build a fake battery to be able to test the setup but failed so far. The BMS seems to have some very strange/specific properties regarding BT. Can you confirm that your BMS works with this app https://play.google.com/store/apps/details?id=com.jktech.bms ? I might need some more info to properly detect the BMS later. 🤔

@downset
Copy link
Author

downset commented May 31, 2024

Sorry I can not confirm this app cause I don't own an Android Phone - but it is the app JK QR code in the Manual links for this BMS
I am using this app:
https://apps.apple.com/de/app/%E6%9E%81%E7%A9%BAbms/id1425725691
But I think it is the Same just for Apple

@patman15
Copy link
Owner

patman15 commented Jun 1, 2024

Hi! I spent yesterday quite some time to try to get a fake battery that I can test with the app but it didn't work out for unknown reason. So testing against a known good seems to be out of reach. 😞 Anyhow, if you like, I can port the implementation from batmon, do some dry runs with samples I found and you test it real life? Do you have a new firmware (>=11)?
(There is a list of unknowns as it seems that all the other implementations have been reverse engineered, thus are inconsistent or weakly documented.)

@downset
Copy link
Author

downset commented Jun 1, 2024

Thank you very much for your efforts.
Yes i have the newest firmware V15.17 where V15 is the HW revision.
Of cause i would like to test if you can port the batmon implementation untested :)

Greets downset

@patman15
Copy link
Owner

patman15 commented Jun 3, 2024

Ok, great thanks. I already started working on it, device detection works, shouldn't take too long till I have an alpha version for testing. Allow me some time, I can only work some evenings or weekend. I'll give you a ping when I have something ready to be checked.
Greetings!

@patman15
Copy link
Owner

patman15 commented Jun 6, 2024

Hi @downset, I have a test implementation you could try on the jikong_bms branch. You can install it manually. If you do not succeed, I could also generate a draft release. Let me know the outcome, a debug log would be great, independent of the actual result. That would help me to verify some assumptions.
Thanks!

@downset
Copy link
Author

downset commented Jun 7, 2024

The Integration now finds both BMS but no data in the Entitäten. Hope This is the logfile you need
home-assistant_bms_ble_2024-06-07T07-18-29.574Z.log
Tell me if i can do anything to address the problem
Greets
Downset

@patman15
Copy link
Owner

patman15 commented Jun 7, 2024

Hi!

For me I'm speaking about the JK-PB2A16S-20P but i think all JK-PB'X'A16S-'XX'P have same protocol

I actually doubt that. Had a look at the log and it looks like you have a totally different BMS (protocol). Did you ever try it with BatMON? Basically, BatMON supports a subset of the BMS listed here https://github.com/syssi/esphome-jk-bms and yours is not listed at all.

@downset
Copy link
Author

downset commented Jun 7, 2024

mhh thats strange,
I haven`t tried Batmon by my self cause my Homeassistant VM has no Bluetooth i have to use bluetooth Proxy.
I just watched the Videos from Andy on Youtube the "off-grid-garage" and he uses Batmon with many variations of this BMS HW version 14 and 15 and also different max current models and a github post on Batmon Repository in conversation wit Andy pointed me to your implementation

https://youtu.be/Iq0vvR-mQUs?si=i9ikFvMm_VU6aYL4

PS: no it is not listed on the Batmon site but also refering to the video, also the newer models work with Batmon

@patman15
Copy link
Owner

patman15 commented Jun 8, 2024

Hi! I had a look at the video and I think we are talking two different BMS types here. Andy is always talking about is "battery#2" and "battery#3" he is testing with BatMON. In the video, timecode 11:38 I can see his Bluetooth scan where those batteries are mentioned and there is another JK_PB2A16S20P-06 he is never talking about. Unfortunately, he doesn't mention the type of BMS is actually using/testing and I'm quite sure he did not try that as his configuration does not contain the MAC address of the JK_PB2A16S20P-06.

Your BMS seems to have a separate UART BT module that needs to be configured. A hint is here syssi/esphome-jk-bms#412 (reply in thread). I assume that this is the issue as I can see the BMS sending "AT" messages.
I totally lack some documentation or more information to do put this BMS into the integration. We could start reverse engineering the system, but this will take a while and several (failing) iterations. Easier would be to have someone who can give information about the protocol required. Andy?

@patman15
Copy link
Owner

patman15 commented Jun 9, 2024

@downset I added some more debugging to the implementation, could you please update your installation from the branch and try again so I can get more info?
Also could you please add to your configuration.yaml the logging configuration:

logger:
  default: info
  logs:
    custom_components.bms_ble: debug

@downset
Copy link
Author

downset commented Jun 9, 2024

Ill try tomorrow, I am not at home at the moment. Thanks again for your effort Ill attach the log afterwords

@downset
Copy link
Author

downset commented Jun 10, 2024

Here is the new log file

home-assistant_bms_ble_2024-06-10T09-51-35.086Z.log

greets Downset

@patman15
Copy link
Owner

@downset thanks again for your patience. I think I found a (stupid) mistake. Can you please try again with the recent update on the branch and send me the logs? If I'm really lucky then you should see at least some values. Thanks!

@downset
Copy link
Author

downset commented Jun 10, 2024

Here it is :)
but no data visible until now
home-assistant_bms_ble_2024-06-10T19-30-40.230Z.log

@patman15
Copy link
Owner

but no data visible until now

I can see some, so the fix did bring us significantly forward. Do the values look plausible to you?

2024-06-10 21:30:35.915 DEBUG (MainThread) [custom_components.bms_ble] BMS data sample {'temperature': 18.4, 'voltage': 52.235, 'current': 0.0, 'battery_level': 42, 'cycle_charge': 117.212, 'cycles': 2, 'cycle_capacity': 6122.56882, 'power': 0.0, 'battery_charging': False, 'rssi': -83}
2024-06-10 21:30:35.915 DEBUG (MainThread) [custom_components.bms_ble] Finished fetching BatteryOben-00 data in 0.917 seconds (success: True)

The protocol is still messed up so readout is not stable. I'll have detailed look soon, but at least values are arriving now. 😃

@downset
Copy link
Author

downset commented Jun 11, 2024

That sounds good.
Values are looking plausible out of current and power. Can`t beleve that at this moment i created the Log file the current was realy zero.

Greets
downset

@patman15
Copy link
Owner

Hey @downset, I again did an update to fix the current and the general protocol handling. Could you give it another test, same procedure as before and provide me with logs? Thanks a lot!

@downset
Copy link
Author

downset commented Jun 12, 2024

and here it is:
home-assistant_bms_ble_2024-06-12T10-01-36.116Z.log
Charging state looks correct
SOC is correct
Cycles is a bit low but the same as the BMS iphone app tells me :)
Stored Energie is correct
Load is correct
Voltage is correct
Current is correct
Temp is correct,
Runtime is completly jumping and I do not have any such Value also in the IPhone BMS APP

everything looks very nice... looking forwoard what you say about the Log
Would love to see also Cell Volt Diff and all Cell voltages but this is an other request i Think :D

Many Thanks
Downset

@downset
Copy link
Author

downset commented Jun 12, 2024

ok this was to early :)
while I am discharging the battery i see strange high numbers and all Positiv. No negativ values an it shows charging.
At the Time of the Screenshot i was discharging with around 5-10A for more than 5 Minutes - very cloudy here at the moment
Discharge

@downset
Copy link
Author

downset commented Jun 12, 2024

and here a log in this situation at 13:09 MEZ i startet 3kw car charger and so i discharged both batterys with around 30a
home-assistant_bms_ble_2024-06-12T11-10-00.822Z.log

Edit:
I missunderstud the runtime value... i thougt it is the time the BMS is active but now after realizing my misstake also this is working, At least while i am charging

@patman15
Copy link
Owner

patman15 commented Jun 12, 2024

Hey! Sorry, had to fix the current again, now it should work. The runtime is the expected remaining time the battery has till 0% SoC. It's calculated so cannot be found in the app. If you can confirm the values now to be correct, I would be mainly interested in the stability, i.e. are the values always available. Would be cool if you can again send me a log, I'd like to do some more optimizations to reduce the BT load so likelihood of interference is lower. Thanks so much for taking the effort.

Would love to see also Cell Volt Diff and all Cell voltages but this is an other request i Think :D

That is a general task I put onto my agenda (see outlook) and I would add it for all models at the same time. If you are ok, I'd like to do that after the main values are stable, because then I need to annoy you less with testing. ;-)

@downset
Copy link
Author

downset commented Jun 12, 2024

Now also negativ values are correct
Perfect
Thanks again and of cause let us make it first stable with the main values :)
I will tell you if i have stability issius but until now it seems that the values ar always there
home-assistant_bms_ble_2024-06-12T15-41-23.256Z.log

Feel free to contact me if you need any testing support

@downset
Copy link
Author

downset commented Jun 12, 2024

Found one thing,

at negativ values the remaining Time is unknown
Bildschirmfoto 2024-06-12 um 18 47 47

@patman15
Copy link
Owner

at negative values the remaining Time is unknown

Signed values do not seem to be my strength. 😆 Fixed.

I now cleaned the code and the tests and significantly reduced the BT traffic (and logging). Let me know if it still works as expected. If so, I would do further cleaning over the next days and then merge it to master for a release. Also if you could have a look at graphs to see if the values are continuously reported that would be great.

@downset
Copy link
Author

downset commented Jun 13, 2024

New Version in not working anymore
Here is the log, at the start i pressed once reload integration:
home-assistant_bms_ble_2024-06-13T16-20-55.659Z.log

Old version seams quite stable one or to times i have seen value unavalable but never for long time Graph is complete
At the end of the screenshot i tested the new version, roled back, there is the dot again and reinstalled the new to make sure i havent made a mistake but again not working... now i roll back again :)
Bildschirmfoto 2024-06-13 um 18 23 28

@patman15
Copy link
Owner

patman15 commented Jun 13, 2024

Hey @downset! Ok, the behavior is really strange, there is no way I can replicate this on my side. I tested the old and modified version and all my tests (artificial, emulated battery) passed. Due to your feedback, I decided to revert the BT optimization and just kept the fixes for the remaining time. Hope it works this time again and we can conclude here and move over to the cell voltage values as a new feature. 😄
If you give your "OK" I'll merge to the main branch, thanks!

@downset
Copy link
Author

downset commented Jun 13, 2024

This is working again, but still no negativ Runtime value :)
home-assistant_bms_ble_2024-06-13T20-21-27.668Z.log

It is up to you how to move foreword if you are willing to make more optimation tries of cause i will test it :)
Thanks again for your Work
greets
downset

@downset
Copy link
Author

downset commented Jun 15, 2024

I have to thank yo for your efforts :)
just updated to 1.3.0 and everything seams fine
Thanks for the hint to disable debug log again

if you have anything to test also unreleated to the jk just in general for the integration, feel free to contact me

@patman15 patman15 added the enhancement New feature or request label Jun 17, 2024
@patman15
Copy link
Owner

Hi @downset, I'm thinking again about a small BT optimization for your BMS. I have seen in the offgrid garage video that the BMS beeps on the first connection (when the integration starts). Can you confirm? I'd like to avoid that happening every 30 seconds ...

@downset
Copy link
Author

downset commented Jun 23, 2024

Yes this is correct it beeps every 30 sec :)
And after longer testing i can see from time to time that the Values are unknowen, but only a short time... not long enough to see it in the graf

@patman15
Copy link
Owner

Yes this is correct it beeps every 30 sec :)
And after longer testing i can see from time to time that the Values are unknown

Do you prefer to

  • get rid of the beeps and fix the unknown values, or
  • keep the beeps and reduce the traffic via Bluetooth (saves a bit of energy and reduces disturbances with other BT devices).

Any preferences? Then I would give it a try again.

@downset
Copy link
Author

downset commented Jun 23, 2024

for me the beep is in the Basement so no problem
I absolutely would prefer less traffic on the Bluetooth proxy :)

@patman15
Copy link
Owner

Hey! Can you give this branch a try? Note, it's based on 1.4.1, so either upgrade and replace one file, or replace all ...
It's sufficient if you enable logging via the GUI and leave it for a few minutes, send me the log and let me know how it behaves. Thanks!

@downset
Copy link
Author

downset commented Jun 23, 2024

just updated to 1.4.1 everything working, than updated just the jkbms file correct?
seems only one of the two batteries are there, the one with address 00
here is the log:
home-assistant_bms_ble_2024-06-23T17-33-40.708Z.log
switching back to the 1.4.1 jkbms file also second batt there

@downset
Copy link
Author

downset commented Jun 23, 2024

did an other try to dubble check...
now both are not connecting
home-assistant_bms_ble_2024-06-23T17-53-50.694Z.log
on 1.4.1 again both working

@patman15
Copy link
Owner

did an other try to dubble check... now both are not connecting

After updating the files, did you restart HA? Otherwise, reloading of the new functionality is not guaranteed.

@downset
Copy link
Author

downset commented Jun 24, 2024

yes i did both times
and the switching back to 1.4.1 both times worked :(

@patman15
Copy link
Owner

This BMS behaves so strange. Since I cannot find a clear documentation, I will need to rely on the BT traces that are available, meaning that I cannot stop the BMS from permanently sending data (although not necessary). But the good news is, I can fix the missing values (I think). 😄

@patman15
Copy link
Owner

Could you try this branch? It should now basically never show you "unknown" data and probably it removes the regular beeps (just a wild guess).

@downset
Copy link
Author

downset commented Jun 24, 2024

It is working and no more Beeping :)

home-assistant_bms_ble_2024-06-24T17-07-46.873Z.log

I will monitor and update this post if I get "unknown" values again

Thank you

@patman15
Copy link
Owner

Hey @downset! In case you are bored 😎, could you test what happens if you just comment (deactivate) this part of the code?

# query device info
await self._client.write_gatt_char(
self._char_write_handle or 0, data=self._cmd(b"\x97")
)

I'm wondering if this is necessary to be sent or if it is just optional. Totally not urgent or important.

@downset
Copy link
Author

downset commented Jun 25, 2024

it happens that it don`t work anymore :)
Bildschirmfoto 2024-06-25 um 17 44 08
do you need a log?

@patman15
Copy link
Owner

do you need a log?

No thanks. I think we have reached quite the optimum of what is doable with the BMS. I'm currently working on cell voltage readout to give you something useful for all your efforts.

@downset
Copy link
Author

downset commented Jun 25, 2024

if its easy to do in this step all Temp sensors and the direct from the bms calculated cell differenze would also be nice :)

@patman15
Copy link
Owner

Plan is to have it like this:
grafik
It shows the maximum difference (highest cell voltage - lowest cell voltage) and if you need something else, there is an array of cell voltage you can use with a template sensor.

@downset
Copy link
Author

downset commented Jun 25, 2024

Looks Perfect
Not to much info for all time but if I like to inspect I can use the array
Better than I as a front end noob could thought of :)

@patman15
Copy link
Owner

Not fully happy with my code yet, but I think it should be working for you and show you cell voltages using this branch. I want to add the feature for all BMS types before releasing, so it might still take a while till it comes to a release.

@downset
Copy link
Author

downset commented Jun 26, 2024

It`s working fine

Thanky you very much

just one thing:
2024-06-26 09_18_28-Übersicht – Home Assistant - Brave
The atributes only have one decimal so can`t see much there
is it somting i can configure or is it hard coded

ok next edit :)
seems all were at 3.30xV now i see some with two decimal 3.31 :)

@patman15
Copy link
Owner

patman15 commented Jun 26, 2024

Hi! Ok, looks like it works. 👍 The user presentation is a bit strange but defined by HA. If you take a look at the developer tools the presentation is with 3 digits as the readout from the BMS is.
What I noticed is that the delta voltage was reported in one of your logs as 0.002V by the BMS while all cell voltages were actually the same. (By that fact you can see that it is a readout and not calculated from the cell voltages. 😄)

@downset
Copy link
Author

downset commented Jun 26, 2024

Again i would like to thank you for all your efforts to make the JK work.
I like it very much how it turned out
how can I give you a donation
Do you have an idea how you can give me a paypal link in Private? :)
not so firm with github can you send me a private message?
greets Downset

@patman15
Copy link
Owner

patman15 commented Jun 27, 2024

@downset thanks a million for that nice motivating feedback. Highly appreciated! If you want to contact me personally, I have a discord link in my profile and I now added a buymeacoffee button to the project. Actually, I was thinking that there are people who are in much more need of money than me so I would appreciate if you could donate the amount you were thinking of to an organization of your choice helping people in need. 😊

not so firm with github can you send me a private message?

Didn't figure that out myself yet, no idea unfortunately.

@patman15 patman15 self-assigned this Jun 27, 2024
@patman15
Copy link
Owner

I now released v1.5.0 which should have all requested features. Thanks for your support, if there is anything more, let me know by contacting me or opening a new issue!

@downset
Copy link
Author

downset commented Jul 1, 2024

Just updated to this Version, All working fine

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants