From deec2aafdabeaab897cb3d8439028c44bf55f233 Mon Sep 17 00:00:00 2001 From: "belevo\\mh" Date: Fri, 17 Apr 2026 13:38:46 +0200 Subject: [PATCH] no message --- Bat_EV_SDL _V2/module.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Bat_EV_SDL _V2/module.php b/Bat_EV_SDL _V2/module.php index 7182d69..031d33c 100644 --- a/Bat_EV_SDL _V2/module.php +++ b/Bat_EV_SDL _V2/module.php @@ -667,7 +667,7 @@ private function CalculateBatteryDistribution(float $pEvW, float $pSdlW): array - + /* $eps = 0.01; $aktEV = 0.0; @@ -716,7 +716,37 @@ private function CalculateBatteryDistribution(float $pEvW, float $pSdlW): array $this->SetValue("Aktuelle_Leistung_EV", (float)$aktEV); $this->SetValue("Aktuelle_Leistung_SDL", (float)$aktSDL); + */ + $eps = 0.01; + + $sumSoll = (float)($pEvW + $pSdlW); + + if (abs($sumSoll) > $eps) { + // Normalfall: wir skalieren so, dass EV+SDL genau totalPower_ist ergibt + $factor = (float)($totalPower_ist / $sumSoll); + + $aktEV = (float)($pEvW * $factor); + $aktSDL = (float)($pSdlW * $factor); + + } else { + // Sonderfall: Soll hebt sich nahezu auf (sumSoll ~ 0) + // -> wenn Ist ebenfalls ~0: Soll anzeigen + if (abs($totalPower_ist) < 50.0) { // 50W Toleranz kannst du anpassen + $aktEV = (float)$pEvW; + $aktSDL = (float)$pSdlW; + } else { + // Ist ist nicht 0 obwohl Sollsumme 0 -> Abweichung zuweisen (z.B. SDL) + $aktEV = (float)$pEvW; + $aktSDL = (float)($totalPower_ist - $aktEV); + // Alternative: Abweichung EV geben: + // $aktSDL = (float)$pSdlW; + // $aktEV = (float)($totalPower_ist - $aktSDL); + } + } + + $this->SetValue("Aktuelle_Leistung_EV", $aktEV); + $this->SetValue("Aktuelle_Leistung_SDL", $aktSDL);