fix: _get_pv_surplus() via grid_power-Aggregat (SDM-630 fix, v1.8.11)

SDM-630 liefert grid_power (negativ=Einspeisung), wurde von active_power-
Logik nicht erfasst. Jetzt einheitlich über grid_power-Aggregat.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
retr0
2026-05-04 11:42:08 +02:00
parent 5942c18df6
commit 0dbf0266a8
2 changed files with 4 additions and 20 deletions
+3 -19
View File
@@ -180,25 +180,9 @@ def _compute_aggregates(allow_stale: bool = False) -> Dict[str, float]:
# ── EMS Hilfsfunktionen ───────────────────────────────────────
def _get_pv_surplus() -> float:
"""PV-Überschuss in Watt aus laufenden Geräten ermitteln.
Goodwe: active_power negativ = Einspeisung (Überschuss).
Growatt: power_to_grid positiv = Einspeisung.
"""
surplus = 0.0
with State.lock:
for inv_cfg in State.inverters_cfg:
d = State.inv_data.get(inv_cfg["id"], {})
if not d.get("modbus_ok") or not d.get("values"):
continue
v = d["values"]
# Goodwe ET: active_power > 0 = Einspeisung, < 0 = Netzbezug
# house_consumption = ppv + pbattery1 - active_power (Bibliotheks-Formel)
if "active_power" in v:
surplus += max(0.0, v["active_power"])
# Growatt
if "power_to_grid" in v:
surplus += max(0.0, v["power_to_grid"])
return surplus
"""PV-Überschuss in Watt. Nutzt grid_power-Aggregat (negativ = Einspeisung)."""
agg = _compute_aggregates(allow_stale=True)
return max(0.0, -agg.get("grid_power", 0.0))
# ── Poll Loop ─────────────────────────────────────────────────