feat(battery): plan a periodic full charge of the stationary battery (#1486)

LFP batteries can only recalibrate their state of charge close to full
charge, so many systems expect a full charge every few weeks and some
start one on their own at an arbitrary, possibly expensive time. EOS can
now plan it instead (GENETIC only, off by default).

New battery settings: full_charge_interval_days (unset = off),
full_charge_soc_percentage, full_charge_detect_percentage,
full_charge_allow_grid and the informational cell_chemistry. The last
full charge is read from the measured SoC history; nothing is stored.
When the next one is due within the horizon (or overdue), the maximum
SoC is raised to the target. With full_charge_allow_grid the optimizer
must reach the target once before the deadline, which is at least 24 h
away (penalty battery_full_charge_miss on the best SoC reached), so it
picks the cheapest time itself. Without it, PV surplus may fill the
battery but the target is not enforced.

Signed-off-by: SchaafAlexander <86607129+SchaafAlexander@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SchaafAlexander
2026-11-08 07:40:13 +01:00
committed by GitHub
co-authored by Claude Opus 5.5
parent b33953d445
commit a06473b6d6
12 changed files with 1085 additions and 6 deletions
@@ -4,7 +4,7 @@ Note: Used for the GENETIC and GENETIC0 algorithm.
"""
import re
from typing import TYPE_CHECKING, Any, Optional
from typing import TYPE_CHECKING, Any, Literal, Optional
import numpy as np
from numpydantic import NDArray, Shape
@@ -212,6 +212,80 @@ class BatteriesCommonSettings(DevicesBaseSettings):
return None
return to_datetime(value)
# ------------------------------------------------------------------
# Periodic full charge (stationary batteries, GENETIC only)
# ------------------------------------------------------------------
cell_chemistry: Optional[Literal["LFP", "NMC", "NCA", "LTO"]] = Field(
default=None,
json_schema_extra={
"x-scope": [str(ConfigScope.GENETIC)],
"description": (
"Cell chemistry of the battery. Informational only, it does not "
"enable anything. LFP batteries usually need a periodic full charge "
"to recalibrate their state of charge, see "
"'full_charge_interval_days'."
),
"examples": [None, "LFP"],
},
)
full_charge_interval_days: Optional[float] = Field(
default=None,
gt=0,
allow_inf_nan=False,
json_schema_extra={
"x-scope": [str(ConfigScope.GENETIC)],
"description": (
"Maximum number of days between two full charges of a stationary "
"battery [d]. The last full charge is taken from the measured state "
"of charge. When the next one falls due within the optimization "
"horizon, the maximum state of charge is raised to "
"'full_charge_soc_percentage'. None disables the periodic full "
"charge. Ignored for electric vehicles."
),
"examples": [None, 21],
},
)
full_charge_soc_percentage: int = Field(
default=100,
ge=1,
le=100,
json_schema_extra={
"x-scope": [str(ConfigScope.GENETIC)],
"description": (
"State of charge a periodic full charge has to reach [%]. May be "
"above 'max_soc_percentage', which then applies on the other days."
),
"examples": [100],
},
)
full_charge_detect_percentage: int = Field(
default=99,
ge=1,
le=100,
json_schema_extra={
"x-scope": [str(ConfigScope.GENETIC)],
"description": (
"Measured state of charge from which the battery counts as fully "
"charged [%]. Many battery management systems never report exactly "
"100 %."
),
"examples": [99],
},
)
full_charge_allow_grid: bool = Field(
default=False,
json_schema_extra={
"x-scope": [str(ConfigScope.GENETIC)],
"description": (
"Enforce a due full charge, charging from the grid if needed. "
"False only raises the maximum state of charge, so that PV surplus "
"can fill the battery, without enforcing the target."
),
"examples": [False, True],
},
)
def to_genetic_pv_bat_param(self) -> "SolarPanelBatteryParameters":
"""Return SolarPanelBatteryParameters for the GENETIC optimizer."""
from akkudoktoreos.devices.genetic.battery import SolarPanelBatteryParameters
@@ -317,6 +391,8 @@ class BatteriesCommonSettings(DevicesBaseSettings):
def _validate_soc_range(self) -> "BatteriesCommonSettings":
if self.min_soc_percentage > self.max_soc_percentage:
raise ValueError("min_soc_percentage must be <= max_soc_percentage")
if self.full_charge_detect_percentage > self.full_charge_soc_percentage:
raise ValueError("full_charge_detect_percentage must be <= full_charge_soc_percentage")
if (
self.min_charge_power_w is not None
and self.max_charge_power_w is not None