From 81a2fc7ef7df0b64981c5e4d436264d169d30a2b Mon Sep 17 00:00:00 2001
From: Oleg Gurevich <oleg@gurevich.de>
Date: Mon, 26 Jun 2023 22:09:06 +0200
Subject: [PATCH] fix proposal for #733

---
 etc/dbus-serialbattery/battery.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/etc/dbus-serialbattery/battery.py b/etc/dbus-serialbattery/battery.py
index d92500fd..d2e92eb7 100644
--- a/etc/dbus-serialbattery/battery.py
+++ b/etc/dbus-serialbattery/battery.py
@@ -250,7 +250,8 @@ def manage_charge_voltage_linear(self) -> None:
         voltageSum = 0
         penaltySum = 0
         tDiff = 0
-
+        # meassurment and variation tolerance in volts
+        measurementToleranceVariation = 0.0215
         try:
             # calculate battery sum
             for i in range(self.cell_count):
@@ -269,7 +270,7 @@ def manage_charge_voltage_linear(self) -> None:
             if self.max_voltage_start_time is None:
                 # start timer, if max voltage is reached and cells are balanced
                 if (
-                    self.max_battery_voltage - utils.VOLTAGE_DROP <= voltageSum
+                    self.max_battery_voltage - utils.VOLTAGE_DROP - measurementToleranceVariation <= voltageSum
                     and voltageDiff <= utils.CELL_VOLTAGE_DIFF_KEEP_MAX_VOLTAGE_UNTIL
                     and self.allow_max_voltage
                 ):
@@ -290,7 +291,7 @@ def manage_charge_voltage_linear(self) -> None:
                     self.max_voltage_start_time = None
                 # we don't forget to reset max_voltage_start_time wenn we going to bulk(dynamic) mode
                 # regardless of whether we were in absorption mode or not
-                if voltageSum < self.max_battery_voltage - utils.VOLTAGE_DROP:
+                if voltageSum < self.max_battery_voltage - utils.VOLTAGE_DROP - measurementToleranceVariation:
                     self.max_voltage_start_time = None
 
             # INFO: battery will only switch to Absorption, if all cells are balanced.