Skip to content
PekawayPekaway
Dual battery setup with JBD BMS/Liontron

Dual battery setup with JBD BMS/Liontron

In the following instructions we will show you how to integrate two BMS into your system.

In principle, we copy the functions that read the BMS via Bluetooth. After the first BMS has been read, we start a second query to read the second BMS, save the values ​​in new variables and then add them together to display combined values ​​in the frontend.

The "BLE Connections" flow for this is actually not that complex, we have adapted the logic a little as to when which query is started, for example that the BMS is only queried via Bluetooth if the corresponding MAC addresses have been set in the frontend.

Don't be surprised, we use a different stylesheet here, so the presentation is a little different than usual.

I took a screenshot of the backend (BLE Connections) and used my paint skills to mark the query for BMS1 (green) and BMS2 (red).

In the function node at the top right in the red box, the values ​​of the second BMS are then written into new variables. For the sake of clarity, the function node was simply copied from the first BMS and a "_2" was appended to all variables:

By the way, the BMSmaxvolt, BMSminvolt and BMSmaxcap values ​​are calculated live as long as the system is running. This means that they are not data that come directly from the BMS, but rather they simply indicate the highest or lowest values ​​that were recorded during the current runtime. If you restart the system, the values ​​are reset.

The second query is executed directly after the first - provided a second BMS was set in the frontend - and sent to the "Sensor Dashboard" flow after a 5 second delay. There they are then prepared for display in the frontend.

The two temperatures are displayed individually, once per BMS.

Currently only a 150 BMS is running here, which is why we only see one temperature in the screenshot. The capacity would also be displayed added together if a second BMS was connected. For the representation here in the picture, we are using node-red-contrib-artless-gauge and node-red-contrib-ui-value-trail . You would need to install this if you want to import the attached flows, or you can replace it with the standard dashboard nodes afterwards.

The calculation to combine the values ​​is as follows:

Ampere, power (watts) and capacities are added together, and an average value is calculated for SoC and volts. Here in the picture using SoC as an example:

The first if query checks whether both SoC variables are set to "wait", which would mean that both BMS are not providing any values ​​and therefore no BMS is connected.

In the second block, we check whether only one of the variables does not return any values. Accordingly, we assume that only one BMS is connected. We then check which of the variables is either set to "wait" or has not received a value, i.e. is "undetermined". To be on the safe side, we also check again whether the value, if it exists, is numeric. The "isNaN" (is not a number) function is used for this. We need numeric values ​​for the calculation, so we set variables that do not exist to 0.

Small JavaScript excursion: Here we see a shortened if query with which we can assign a value to a variable:

bmssoc1 = global.get("BMSsoc") == "wait" ? 0 : global.get("BMSsoc");

bmssoc1 should therefore get a value, to do this we check whether global.get("BMSsoc") is equal to "wait". If this is the case, we set bmssoc1 to the numerical value 0, if this is not the case, we pass the value of global.get("BMSsoc").

At the end of the second block is the calculation: bmssoc1 + bmssoc2 divided by the number of BMS, in this case 1. Now you could say that dividing by 1 makes no sense, which is of course mathematically correct. But the point is that we don't know which of the variables will ultimately be 0 and which will return a value, so by calculating by 1 we simply cover all possibilities. Another possible way would be to check before the calculation where the values ​​are delivered and where they are not. But as we all know, many roads lead to Rome.

If values ​​are returned in both global variables, the third case occurs and the last block is executed. We then simply add both values ​​together and divide them by the number, in this case by two.

Finally, we write the combined value into a new variable. We then pass this in the "copy data" node (just search for the node with CTRL + f, it is located on the left in the Sensor Dashboard Flow) to the global variables MainBattVolt, MainBattSoc and MainBattAmp. This means that we can then see the combined values ​​in the touch display and query them via the APIs.

In the appendix you will find two flows, one for the display and one the complete BLE Connections flow with two battery queries.

SensorDashboardNodes:

https://share.12-s.de/s/yFGGXjQpEdFZM4g

BLE Connections Flow:

https://share.12-s.de/s/LDyaQgPc3DcCTFK

Leave a comment

Your email address will not be published..

more tutorials

Open Source needs support

become Patron now

More projects, more tutorials and more supported devices. Our community is growing and would appreciate your support. So become a patron now to always receive the latest content and support the VAN PI project at the same time.

Become a Patron
Cart 0

Your cart is currently empty.

Start Shopping