diy solar

diy solar

JK-BMS-CAN with new Cut-Off Charging Logic (open-source)

57.4v is a high charge voltage assuming a 16s battery. General guidance is to bulk charge at 3.45v per cell, so 55.2v.
This will give sufficient headroom for balancing without triggering OVP, etc, but also fully charge the battery.
Hi Mr. Pablo,
The following is captured data from the inverter (the 6K)
1712022746546.png
It seemed charging voltage does not update by the the BMS but regulated by the inverter.1712022814553.png
So I can concluded that via CAN bus Luxpower Inverter will not change its charging voltage as requested by the BMS via Pylon protocol. The following image is the one with BMS communicating to the Luxpower via RS485 and charging voltage is changed by BMS request.
I set the charging voltage of 57

1712023047354.png
But the BMS (via Rs485) requested 56 and it charges with 56V
1712023094421.png
That's interesting!
 
Today, I did a final check with inverter dealer (technical guy) and discovered that the voltage sensor (type of voltage divider resistor) on the inverter was not in good condition and cause the reading voltage from battery wrong (Vbat_inv) and often high when charging. as the result the High voltage alarm trigger by the inverter and stop charging.
The charging with revised config worked out well on 104Ah battery and 280ah battery and also 50Ah.
104Ah battery with auto charge current using map(): 4.4kWh was charged
1712039541901.png
And here is the one with 280Ah battery, 13.3kWh charged (using manual charging current control) - the guy does not want to control automatically. He wants to rip the more solar the better. haiza
1712039772099.png
And this is for my case auto charging with 50Ah battery. 2.7 kWh was charged.
1712039855537.png
Please be sorry Mr. Pablo for revising the code too much (I based on the 2 months ago code provided by Sleeper85)
Here is the link for the revised one / messy but sound fun.
With this cutting on code, the bms battery can work almost the same as a lead acid battery but Inverter can check view stuff on battery
I am planning to do more with
+ Control charging current by time: still wonder how to have time entity in home assistant be used in esphome code.
+ Find a way to deal with charge voltage limit control (still not possible to do in Luxpower inverters)
+ There is also problem on calculating charging cycle that Lux does not accept. So I will try finding a way to work this out!
+ Also a bit more revision on current limit recovery should be applied to make the charging curve be smooth (should not back to high current again to avoid some power rush in);
+ Fixing end of charge stage: currently my revision make the charge prolonged, and can only be stoped when charging voltage is high (57.4 for 16S battery on Luxpower inverter).
Many thanks yo Slepper85 for your starting code and Mr.Pablo for your wonderful code on platform: copy (that save me tons of time). And please be sorry for removing a lot of your code in 0x355 and 0x351 section.
Best!
For your information: this is the charging curve for SVE5000 battery (premium) - 4.4Kw charged to day
1712041347163.png
Yesterday charge using @MrPablo pow() function and today using map(): for my 50Ah battery
1712041520974.png
 
Last edited:
Today, I did a final check with inverter dealer (technical guy) and discovered that the voltage sensor (type of voltage divider resistor) on the inverter was not in good condition and cause the reading voltage from battery wrong (Vbat_inv) and often high when charging. as the result the High voltage alarm trigger by the inverter and stop charging.
The charging with revised config worked out well on 104Ah battery and 280ah battery and also 50Ah.
104Ah battery with auto charge current using map(): 4.4kWh was charged
View attachment 206437
And here is the one with 280Ah battery, 13.3kWh charged (using manual charging current control) - the guy does not want to control automatically. He wants to rip the more solar the better. haiza
View attachment 206438
And this is for my case auto charging with 50Ah battery. 2.7 kWh was charged.
View attachment 206439
Please be sorry Mr. Pablo for revising the code too much (I based on the 2 months ago code provided by Sleeper85)
Here is the link for the revised one / messy but sound fun.
With this cutting on code, the bms battery can work almost the same as a lead acid battery but Inverter can check view stuff on battery
I am planning to do more with
+ Control charging current by time: still wonder how to have time entity in home assistant be used in esphome code.
+ Find a way to deal with charge voltage limit control (still not possible to do in Luxpower inverters)
+ There is also problem on calculating charging cycle that Lux does not accept. So I will try finding a way to work this out!
+ Also a bit more revision on current limit recovery should be applied to make the charging curve be smooth (should not back to high current again to avoid some power rush in);
+ Fixing end of charge stage: currently my revision make the charge prolonged, and can only be stoped when charging voltage is high (57.4 for 16S battery on Luxpower inverter).
Many thanks yo Slepper85 for your starting code and Mr.Pablo for your wonderful code on platform: copy (that save me tons of time). And please be sorry for removing a lot of your code in 0x355 and 0x351 section.
Best!
For your information: this is the charging curve for SVE5000 battery (premium) - 4.4Kw charged to day
View attachment 206441
Yesterday charge using @MrPablo pow() function and today using map(): for my 50Ah battery
View attachment 206442
I will test this - however, it's a shame that this revision will only be used on a personal rather than a global level as work that has been done between versions 16.5 and 17.4 has been cut out (which is a lot of work and effort).

We should be moving forward as a community in the project development and thriving to work together so no effort is in vain.
I wish you could have done your revision from the latest 17.4 version...but it is what it is, I am sure you have your technical reasons and explanations (my knowledge of coding is limited so I have no opinion except on a general ground).
 
I will test this - however, it's a shame that this revision will only be used on a personal rather than a global level as work that has been done between versions 16.5 and 17.4 has been cut out (which is a lot of work and effort).

We should be moving forward as a community in the project development and thriving to work together so no effort is in vain.
I wish you could have done your revision from the latest 17.4 version...but it is what it is, I am sure you have your technical reasons and explanations (my knowledge of coding is limited so I have no opinion except on a general ground).
Same feeling here ... Would be better to have an "all-in-one" software or at least a "all-in-one" framework going forward.

But it is what it is. I can also understand people doing their own spinoffs. Their use case is quite specific, integration is different, they might not be able to wait, etc

Plus that's the entire principle of how GitHub works. First you fork a repo, then you do the modifications. But then it's also up to you to either upstream (giving back to the community) and integrating into their newest code. It has to be a pretty big feature you developed on your own side to "justify" the main project to do a "pull" from your fork instead and them doing all the integration work IMHO.
 
Last edited:
Same feeling here ... Would be better to have an "all-in-one" software or at least a "all-in-one" framework going forward.

But it is what it is. I can also understand people doing their own spinoffs. Their use case is quite specific, integration is different, etc

Plus that's the entire principle of how GitHub works. First you fork a repo, then you do the modifications. But then it's also up to you to either upstream (giving back to the community) and integrating into their newest code. It has to be a pretty big feature you developed on your own side to "justify" the main project to do a "pull" from your fork instead and them doing all the integration work IMHO.
Thanks to @silverstone and @chaosnature!
I just tried a test first and then moving on shaping the code back to the main version that Sleeper85 and Mr. Pablo is working! The initial result shown that it can work as expected for at least Luxpower/Deye Inverters (what I have for testing and they are still having minor problems to be solved as stated earlier). From that perspective, the options that @MrPablo and @Sleeper85 provided worked and can be used for wider application. With some modifications on Charging/discharging logics to make the charge/discharging curve be more smooth, I believe it would fit the need for bringing values to make the cheap JK-BMS talk properly to Inverters.
I will do revision anyhow as I have been struggling using this pathway to make the battery be charged as a "Lead acid" pack but it can talk! The only worrying is, There are codes from both Sleeper85 and Mr.Pablo that has been changed massively comparing to the version that I am working on:
1. I did not apply the charging logic set under the 0x351: as I found out that people use different setting for charging: some charge/discharge once a day, the other applies constant charge/discharge to maximize the use of solar. Also, I don't want to rely on alarm from BMS but applying a proactive prevention method to avoide warning on the inverter (often applied by premium BMS). This is the reason why I removed almost all code under this 0x351 section. Furthermore, since JK SOC is not reliable it is impossible for detecting the charging/discharging stage.
2. I learned from Mr.Pablo approach to replace scripting so whenever max/min_cell_voltage and SOC hit a point for checking, the code will do the work so that Inverters will not stop charging or throwing a warning that worries users.
3. There is not much I created but revising Mr.Pablo's code just a bit on charging current limit and SOC check!
with this I believe the puzzle can be solved in a simpler and easier approach and can fit different needs. Anyway I will make a fork from the code repo and rewrite the code.
Best,
 
Last edited:
Thanks to @silverstone and @chaosnature!
I just tried a test first and then moving on shaping the code back to the main version that Sleeper85 and Mr. Pablo is working! The initial result shown that it can work as expected for at least Luxpower/Deye Inverters (what I have for testing and they are still having minor problems to be solved as stated earlier). From that perspective, the options that @MrPablo and @Sleeper85 provided worked and can be used for wider application. With some modifications on Charging/discharging logics to make the charge/discharging curve be more smooth, I believe it would fit the need for bringing values to make the cheap JK-BMS talk properly to Inverters.
I will do revision anyhow as I have been struggling using this pathway to make the battery be charged as a "Lead acid" pack but it can talk! The only worrying is, There are codes from both Sleeper85 and Mr.Pablo that has been changed massively comparing to the version that I am working on:
1. I did not apply the charging logic set under the 0x351: as I found out that people use different setting for charging: some charge/discharge once a day, the other applies constant charge/discharge to maximize the use of solar. Also, I don't want to rely on alarm from BMS but applying a proactive prevention method to avoide warning on the inverter (often applied by premium BMS). This is the reason why I removed almost all code under this 0x351 section. Furthermore, since JK SOC is not reliable it is impossible for detecting the charging/discharging stage.
2. I learned from Mr.Pablo approach to replace scripting so whenever max/min_cell_voltage and SOC hit a point for checking, the code will do the work so that Inverters will not stop charging or throwing a warning that worries users.
3. There is not much I created but revising Mr.Pablo's code just a bit on charging current limit and SOC check!
with this I believe the puzzle can be solved in a simpler and easier approach and can fit different needs. Anyway I will make a fork from the code repo and rewrite the code.
Best,
I am sure a compromise can be reached between yourself and MrPablo to integrate the proposed changes into the latest version; as it does make sense, the case you are putting forward....

again hard to tell with my limited coding knowledge
 
I will do revision anyhow as I have been struggling using this pathway to make the battery be charged as a "Lead acid" pack but it can talk!
LFP work differently/ have different charging behaviour from lead acid.
+ Find a way to deal with charge voltage limit control (still not possible to do in Luxpower inverters)
This works perfectly fine (even the response is within 1 or 2 seconds) on my LXP SNA 5k unit. This has to be an issue on your end.
Furthermore, since JK SOC is not reliable it is impossible for detecting the charging/discharging stage.
When it comes to LFP specifically, we have to rely on voltages to detect the charging/discharging stage and what to do.
That is how this chemistry is. SOC is bound to deviate because it is a derived and furthermore, an integrated over time quantity.

Newer JK's provides an option for setting a voltage corresponding to 100% charge.
With some modifications on Charging/discharging logics to make the charge/discharging curve be more smooth, I believe it would fit the need for bringing values to make the cheap JK-BMS talk properly to Inverters.
You can always turn the switches for AutoCVL/CCL/DCL off and have an unadulterated charging.

Here's mine doing the same.
The graph between cell deviation and current/power is mostly same until a spike at the very end of the bulk phase

1712067914697.png

My pack is balanced that is why I don't require anything. I can fully charge my pack with balancing mostly turned off.
From what I know the JK-BMS+ESP solution is already talking nicely with inverters that we have tested so far.
It is finally I can sleep soundly at night level good!!
 
LFP work differently/ have different charging behaviour from lead acid.
When it comes to LFP specifically, we have to rely on voltages to detect the charging/discharging stage and what to do.
That is how this chemistry is. SOC is bound to deviate because it is a derived and furthermore, an integrated over time quantity.
It was a metaphor to imply the simplicity for users when they apply this method to allow Lux to manage the charging process without worrying once correct limits on voltages are configured on the inverter. I did some changes on the code for bringing voltage control to manipulate charge/discharging behavior. This would be so much similar to the case of Lead Acid.
This is why @Mr.Pablo biding on cell_max/min is very reasonable. and I am using his approach for detecting problems to cells voltage
This works perfectly fine (even the response is within 1 or 2 seconds) on my LXP SNA 5k unit. This has to be an issue on your end.
This is true on SNA5000WM. I used pylon protocol (brand 2) but Lux does not change the charged voltage at all (I tried on all 3 SNA5000 and the 6K version, helpless)! However, I recalled that SNA5000WM did changed the charge voltage when using with SVE battery (connected via RS485) and today a guy from Lux shared that it can also change via CAN bus using protocol 1. So I believe Lux might response on other can_id. (Similarly, 0x70 does not update cell voltage (max/min) on Lux with brand 2 (pylon) but 0x373.
Newer JK's provides an option for setting a voltage corresponding to 100% charge.
This true but JK's SOC still deviates over time and it need a method to reset at both end (0% and 100%) to allow proper work for the inverter (when using Lion mode, Inverter use SOC but not Voltage to regulate its charging/discharging process. I have tried several way to control Lux on voltage but it failed). Therefore SOC fine tuning become important.
Normally to reset that, user will do on JK mobile app but we have another option to do it by keep charging when SOC at 100% or discharging when SOC is 0% (in my case when Bat_v is still 49.5 - 15S pack and min/max cell still over 3.2V)
1712072113616.png
You can always turn the switches for AutoCVL/CCL/DCL off and have an unadulterated charging.
I reckoned the feature and did trying but the charging schemes under 0x356 cause problems to the bulk charge for high current. It's might be a case that I did not use the new version in GitHub. I will try tomorrow to see any problem with that.
Thank you for your detailed shares. All we are heading for is to reach a state that we can plug in and forget for the ESP to manage the process! I do like to end up this and back to Lead acid but the feeling of wanting to make the battery speak does not stop tracing me even in during my sleep.
Best!
 

Attachments

  • 1712072172073.png
    1712072172073.png
    5.3 KB · Views: 3
Sorry to randomly crash in here on page 44, but i cant for the life of me get this Atom S3 lite device to be recognized under the windows platform, and thus cant edit any files.

When power up the atom, all i see is a password protected WIFI network ( no clue what the password is )

Can anyone lend a hand here?
 
Sorry to randomly crash in here on page 44, but i cant for the life of me get this Atom S3 lite device to be recognized under the windows platform, and thus cant edit any files.

When power up the atom, all i see is a password protected WIFI network ( no clue what the password is )

Can anyone lend a hand here?
I gave up on windows so I cannot help you there 😅.

But what exactly do you mean that you cannot get the Atom S3 Lite recognized under windows ?

If you power it up without having uploaded the program (and how could you have done that if it's not even getting recognized), I guess it's just some demo program running from the manufacturer ....

Did you setup the esphome build environment correctly ? If you had Linux or could use a Linux VM (NOT WSL !) or Dual Boot it would be easier IMHO.
 
I gave up on windows so I cannot help you there 😅.

But what exactly do you mean that you cannot get the Atom S3 Lite recognized under windows ?

If you power it up without having uploaded the program (and how could you have done that if it's not even getting recognized), I guess it's just some demo program running from the manufacturer ....

Did you setup the esphome build environment correctly ? If you had Linux or could use a Linux VM (NOT WSL !) or Dual Boot it would be easier IMHO.

I might be totally off track here, but I was under the impression that my windows operating system ( where I installed esphome ) have to be able to communicate with the atom in order to edit or update files necessary for this project.

After installing esphome I got a red error message that read "ERROR resolving IP address of jk-bms-can.local. Is it connected to WIFI?"

But I have no clue what the WIFI password is ( I suppose it came installed with something because a wifi network called AtomS3.xxxxx pops up when i power it up. :unsure:
 
I might be totally off track here, but I was under the impression that my windows operating system ( where I installed esphome ) have to be able to communicate with the atom in order to edit or update files necessary for this project.

After installing esphome I got a red error message that read "ERROR resolving IP address of jk-bms-can.local. Is it connected to WIFI?"

But I have no clue what the WIFI password is ( I suppose it came installed with something because a wifi network called AtomS3.xxxxx pops up when i power it up. :unsure:
Did you flash it using the USB cable ? Did you set the domain name / hostname correctly to the YAML file and do you have a working DNS server ?

Otherwise for OTA to work, either your DNS Server must be able to resolve that FQDN (hostname + domain name), or:
- Linux: add the IP address to /etc/hosts
- Windows: add the IP address to C:\Windows\System32\drivers\etc\hosts

And of course up to you to find the IP address of the device. Look at the Lease Table of your DHCP server for that (or run a fing/nmap scan etc).

Personally OTA has proven quite unreliable to me, so I only use the USB cable to flash ...
 
Did you flash it using the USB cable ? Did you set the domain name / hostname correctly to the YAML file and do you have a working DNS server ?

Otherwise for OTA to work, either your DNS Server must be able to resolve that FQDN (hostname + domain name), or:
- Linux: add the IP address to /etc/hosts
- Windows: add the IP address to C:\Windows\System32\drivers\etc\hosts

And of course up to you to find the IP address of the device. Look at the Lease Table of your DHCP server for that (or run a fing/nmap scan etc).

Personally OTA has proven quite unreliable to me, so I only use the USB cable to flash ...

Not been able to flash anything, when I plugin the atom to my computer using a USB to type-c cable, all I get is the atom powers up, the LED lights up in red, and will turn green / blue / white if I cycle it's button.

I tried to debug the USB port to see any information from the atom could be revealed ( looked for vendor_ID or anything in order to find potential drivers , but nothing.. ).

I visited https://docs.m5stack.com/en/download to look for windows drivers, randomly installed a few, since I dont know what chip / driver is needed for this particular Atom,, but nope, no luck.
 
Not been able to flash anything, when I plugin the atom to my computer using a USB to type-c cable, all I get is the atom powers up, the LED lights up in red, and will turn green / blue / white if I cycle it's button.

I tried to debug the USB port to see any information from the atom could be revealed ( looked for vendor_ID or anything in order to find potential drivers , but nothing.. ).

I visited https://docs.m5stack.com/en/download to look for windows drivers, randomly installed a few, since I dont know what chip / driver is needed for this particular Atom,, but nope, no luck.
But did you try the esphome command at all or ? It should find the adapter automatically after compiling the program, it will ask you whether you want to flash USB device or if you want OTA. If nothing is plugged in, it will just do OTA automatically.

About windows not detecting anything ... Are you sure you are using a Power+Data USB cable ? Some USB cables are meant only for power so if you miss the data pins/wires it's not going to work. Just cross-checking :) .
 
It was a metaphor to imply the simplicity for users when they apply this method to allow Lux to manage the charging process without worrying once correct limits on voltages are configured on the inverter. I did some changes on the code for bringing voltage control to manipulate charge/discharging behavior. This would be so much similar to the case of Lead Acid.
This is why @Mr.Pablo biding on cell_max/min is very reasonable. and I am using his approach for detecting problems to cells voltage

This is true on SNA5000WM. I used pylon protocol (brand 2) but Lux does not change the charged voltage at all (I tried on all 3 SNA5000 and the 6K version, helpless)! However, I recalled that SNA5000WM did changed the charge voltage when using with SVE battery (connected via RS485) and today a guy from Lux shared that it can also change via CAN bus using protocol 1. So I believe Lux might response on other can_id. (Similarly, 0x70 does not update cell voltage (max/min) on Lux with brand 2 (pylon) but 0x373.

This true but JK's SOC still deviates over time and it need a method to reset at both end (0% and 100%) to allow proper work for the inverter (when using Lion mode, Inverter use SOC but not Voltage to regulate its charging/discharging process. I have tried several way to control Lux on voltage but it failed). Therefore SOC fine tuning become important.
Normally to reset that, user will do on JK mobile app but we have another option to do it by keep charging when SOC at 100% or discharging when SOC is 0% (in my case when Bat_v is still 49.5 - 15S pack and min/max cell still over 3.2V)
View attachment 206497

I reckoned the feature and did trying but the charging schemes under 0x356 cause problems to the bulk charge for high current. It's might be a case that I did not use the new version in GitHub. I will try tomorrow to see any problem with that.
Thank you for your detailed shares. All we are heading for is to reach a state that we can plug in and forget for the ESP to manage the process! I do like to end up this and back to Lead acid but the feeling of wanting to make the battery speak does not stop tracing me even in during my sleep.
Best!
This true but JK's SOC still deviates over time and it need a method to reset at both end (0% and 100%) to allow proper work for the inverter .....

the above statement is definitly true in my case .....the both jk seem to align towards the 0% SoC but leave each other when they appraoch 100 % SoC
1712077077412.png

They do not seem to obey the voltage count.....


# Edit
According to the voltage vs percentage screenshot above...my calculations says if 3.704 is = 63 % then 3.734 should = 63.510 %
But it's reading 52%
 
Last edited:
This true but JK's SOC still deviates over time and it need a method to reset at both end (0% and 100%) to allow proper work for the inverter .....

the above statement is definitly true in my case .....the both jk seem to align towards the 0% SoC but leave each other when they appraoch 100 % SoC
View attachment 206526

They do not seem to obey the voltage count.....
As I stated before, are you SURE that you are staying for long enough and high enough in terms of voltage ?

Otherwise of course you could be VERY wrong (coulomb counting).

I know I keep repeating it, but you never clearly stated whether you let enough time for all your cells to absorb / equalize :) .
 
As I stated before, are you SURE that you are staying for long enough and high enough in terms of voltage ?

Otherwise of course you could be VERY wrong (coulomb counting).

I know I keep repeating it, but you never clearly stated whether you let enough time for all your cells to absorb / equalize :) .
@silverstone

i have left it for days untouched like this

it gets to 100% and they settle and meet up then go back together - at some point, they leave each other...not touching it anymore.

i used to temper with the jk-bms-ble-can total battery capacity to adjust it, but i stopped doing this now for many days
 
But did you try the esphome command at all or ? It should find the adapter automatically after compiling the program, it will ask you whether you want to flash USB device or if you want OTA. If nothing is plugged in, it will just do OTA automatically.

About windows not detecting anything ... Are you sure you are using a Power+Data USB cable ? Some USB cables are meant only for power so if you miss the data pins/wires it's not going to work. Just cross-checking :) .
It was the esphome command 'esphome run ESP32_LFP_Wire_jk-bms-can.yaml' that generated the ERROR resolving IP address of jk-bms-can.local. Is it connected to WIFI?

Other then that I have not used any esphome commands.

I tried 5 different type-c to USB cable's, not sure any of them have data support though so I guess heading over to a store and pick up a data specific type-c cable is my next move :)
 
@silverstone

i have left it for days untouched like this

it gets to 100% and they settle and meet up then go back together - at some point, they leave each other...not touching it anymore.

i used to temper with the jk-bms-ble-can total battery capacity to adjust it, but i stopped doing this now for many days
and i believe my maths is right becos the voltage is constant - there should really only be a .510 difference between the 2 BMS's
 
It was the esphome command 'esphome run ESP32_LFP_Wire_jk-bms-can.yaml' that generated the ERROR resolving IP address of jk-bms-can.local. Is it connected to WIFI?

Other then that I have not used any esphome commands.

I tried 5 different type-c to USB cable's, not sure any of them have data support though so I guess heading over to a store and pick up a data specific type-c cable is my next move :)
I don't want to make you lose money for nothing, but it's definitively one possibility.

Have you checked device manager for any Warning symbol etc ? I would guess it should show up there (in GNU/Linux it's /dev/ttyUSB... IIRC). So there should be a serial adapter available (like FTDI etc).
 
Back
Top