From b330058d5b64068f574b2a3dbbe74fbfb9edd068 Mon Sep 17 00:00:00 2001 From: "belevo\\mh" Date: Fri, 8 May 2026 11:22:22 +0200 Subject: [PATCH] no message --- Bat_EV_SDL_V4/module.php | 57 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/Bat_EV_SDL_V4/module.php b/Bat_EV_SDL_V4/module.php index fa7827f..f297cdf 100644 --- a/Bat_EV_SDL_V4/module.php +++ b/Bat_EV_SDL_V4/module.php @@ -110,9 +110,12 @@ class Bat_EV_SDL_V4 extends IPSModule return; } - $this->BuildBatteryPlan(true); + $this->BuildBatteryPlan(false); $plan = json_decode($this->GetBufferSafe("BatPlanJSON"), true); + + $plan = $this->RefreshDynamicPlanValues($plan); + if (!is_array($plan) || empty($plan["bats"])) { $this->WriteAllZero("plan empty/invalid"); return; @@ -885,6 +888,58 @@ class Bat_EV_SDL_V4 extends IPSModule return $current + (($target > $current) ? $maxStep : -$maxStep); } + + private function RefreshDynamicPlanValues(array $plan): array + { + foreach ($plan["bats"] as &$bat) { + $socVarId = (int)($bat["socVarId"] ?? 0); + $capKWh = (float)($bat["capKWh"] ?? 0.0); + + $realSocPct = $this->ReadSocPercent($socVarId); + $realKWh = $capKWh * $realSocPct / 100.0; + + $minPhysicalKWh = (float)($bat["minPhysicalKWh"] ?? 0.0); + $underKWh = (float)($bat["underKWh"] ?? 0.0); + $upKWh = (float)($bat["upKWh"] ?? 0.0); + + $bat["real_SOC_pct"] = round($realSocPct, 3); + $bat["real_kWh"] = round($realKWh, 3); + + $bat["SDL_Discharge_kW"] = + ($realKWh >= $minPhysicalKWh) + ? (float)$bat["sdlShareKW_entladen"] + : 0.0; + + $bat["EV_Discharge_kW"] = + ($realKWh > $underKWh) + ? (float)$bat["evShareKW_entladen"] + : 0.0; + + $bat["EV_Charge_kW"] = + ($realKWh < $upKWh) + ? (float)$bat["evShareKW_laden"] + : 0.0; + + $bat["SDL_Charge_kW"] = + (float)$bat["sdlShareKW_laden"]; + } + unset($bat); + + $plan["total"]["SDL_Charge_kW"] = 0.0; + $plan["total"]["SDL_Discharge_kW"] = 0.0; + $plan["total"]["EV_Charge_kW"] = 0.0; + $plan["total"]["EV_Discharge_kW"] = 0.0; + + foreach ($plan["bats"] as $bat) { + $plan["total"]["SDL_Charge_kW"] += (float)$bat["SDL_Charge_kW"]; + $plan["total"]["SDL_Discharge_kW"] += (float)$bat["SDL_Discharge_kW"]; + $plan["total"]["EV_Charge_kW"] += (float)$bat["EV_Charge_kW"]; + $plan["total"]["EV_Discharge_kW"] += (float)$bat["EV_Discharge_kW"]; + } + + return $plan; + } + private function SetIdentValue(string $ident, $value): void { $id = @$this->GetIDForIdent($ident);