From 369e2fb786d764651025c80568fa149a76178bfa Mon Sep 17 00:00:00 2001 From: David Rapan Date: Thu, 15 Aug 2024 19:16:30 +0200 Subject: [PATCH] fix: Battery SOH when wrong corrected capacity --- custom_components/solarman/sensor.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/custom_components/solarman/sensor.py b/custom_components/solarman/sensor.py index a12c985..e015bcc 100644 --- a/custom_components/solarman/sensor.py +++ b/custom_components/solarman/sensor.py @@ -106,9 +106,11 @@ def update(self): match self.sensor_name: case "Battery SOH": total_battery_charge = self.get_data("Total Battery Charge", None) - battery_capacity = self.get_data("Battery Corrected Capacity", None) - if battery_capacity <= 0: - battery_capacity = self.get_data("Battery Capacity", None) + battery_capacity = self.get_data("Battery Capacity", None) + battery_capacity_5 = battery_capacity / 100 * 5 + battery_corrected_capacity = self.get_data("Battery Corrected Capacity", None) + if battery_capacity - battery_capacity_5 <= battery_corrected_capacity <= battery_capacity + battery_capacity_5: + battery_capacity = battery_corrected_capacity if total_battery_charge and battery_capacity and self._battery_nominal_voltage and self._battery_life_cycle_rating: self._attr_state = get_number(100 - total_battery_charge / get_battery_power_capacity(battery_capacity, self._battery_nominal_voltage) / (self._battery_life_cycle_rating * 0.05), self._digits) case "Battery State":