Improving SoC Calculation using Charge/Discharge Energy

Hi Community,

I am using a custom battery with Kaco bpg 92 inverter to make a generic managed symmetric ess. The bms does not seem to show a stable and correct soc. I want to implement a soc calculator that would take charge/discharge energy from _sum and use that to calculate a more correct soc and map that to the Battery Soc channel.

I need guidance on how can I implement this the best way? Should I create a class in the Battery Implementation or in the GenericManagedSymmetricEss and import _sum/ActiveCharge/Discharge Energy in that and do the calculation? or make a separate sort of api to do this?

Currently I have made this class. It does not work at all though :sweat_smile:
Pardon me Java Gurus for this:

public class BatterySocCalculator extends GenericManagedSymmetricEssImpl {
	private int initialSoc;
	private int batteryCapacity;
	private double cumulativeCharge = 0;
	private double cumulativeDischarge = 0;
	private int soc_new;
    private BatterySocCalculator(int initialSoC, int batteryCapacity) {
        this.initialSoc = initialSoc;
        this.batteryCapacity = batteryCapacity;
    private int updateEnergy(double chargeEnergy, double dischargeEnergy) {
        cumulativeCharge += chargeEnergy;
        cumulativeDischarge += dischargeEnergy;
        return  0;
    private int calculateSoC() {
        double currentEnergy = cumulativeCharge - cumulativeDischarge;
        int soc = (int)((currentEnergy / batteryCapacity) * 100.0);
//        soc = Math.max(0, Math.min(100, soc));
        return soc;
    public static int calSoc() {
//    	int initialSoC = this.getSoc().get(); // Initial state of charge (%)
    	int initialSoC = 85; // Initial state of charge (%)
    	int batteryCapacity = 100; // Example battery capacity (Wh)

        GenericManagedSymmetricEssImpl ess = new GenericManagedSymmetricEssImpl();
        BatterySocCalculator socCalculator = BatterySocCalculator(initialSoC, batteryCapacity);
        double chargeEnergy = 1; // Example charge energy (Wh)
        double dischargeEnergy = 0; // Example discharge energy (Wh)
        socCalculator.updateEnergy(chargeEnergy, dischargeEnergy);
        int soc_new = socCalculator.calculateSoC();
        return soc_new;
	public void calcSoc() {;	

Thanks in advance!


Hi @hafizAbdullahBhutto,

I believe you can more or less copy the implementation from “Simulator.EssSymmetric.Reacting” → openems/io.openems.edge.simulator/src/io/openems/edge/simulator/ess/symmetric/reacting/ at develop · OpenEMS/openems · GitHub

You should not use the data from _sum because this would stop working as soon as you have multiple batteries or ESSs.


1 Like