Skip to content

Commit fbe5e16

Browse files
committed
Cap time extrapolation gap to prevent charging SOC plateaus
Uncapped extrapolation in get_predicted_soc() inflated prediction during long MQTT gaps (53 min observed), then the never-decrease constraint locked in the inflated value. accumulate_energy() already caps at MAX_ENERGY_GAP_SECONDS (600s) but get_predicted_soc() did not, creating a mismatch that caused visible prediction plateaus. Trace: MQTT burst 10:33-10:35, 53-min gap, extrapolation inflated 51.4%->58.7%, real energy stuck at 0.307 kWh, plateau until re-anchor. After HA restart, 74-min gap from persisted session inflated to 61.5%, second plateau at 61.7% until API sync-up at 62%.
1 parent b0f022d commit fbe5e16

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

custom_components/cardata/soc_prediction.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,15 @@ def get_predicted_soc(
974974

975975
# Extrapolate energy since last power reading using last known power.
976976
# This provides smooth SOC updates between sparse API polls.
977+
# Cap gap to MAX_ENERGY_GAP_SECONDS to match accumulate_energy() —
978+
# without cap, long MQTT gaps inflate prediction, then "never decrease"
979+
# constraint locks in the inflated value creating visible plateaus.
977980
if session.last_power_kw > 0 and session.last_energy_update is not None:
978981
gap = time.time() - session.last_energy_update
979982
if gap > 0:
983+
capped_gap = min(gap, MAX_ENERGY_GAP_SECONDS)
980984
net_power = max(session.last_power_kw - session.last_aux_kw, 0.0)
981-
extra_kwh = net_power * (gap / 3600.0) * efficiency
985+
extra_kwh = net_power * (capped_gap / 3600.0) * efficiency
982986
energy_added_kwh += extra_kwh
983987

984988
# Convert to SOC percentage

0 commit comments

Comments
 (0)