diff --git a/Bat_EV_SDL _V2/module.php b/Bat_EV_SDL _V2/module.php index 0106be8..754f37e 100644 --- a/Bat_EV_SDL _V2/module.php +++ b/Bat_EV_SDL _V2/module.php @@ -663,8 +663,47 @@ private function CalculateBatteryDistribution(float $pEvW, float $pSdlW): array // aktuelle - EV_SOLL = aktuelle SDL // aktuelle - SDL_SOLL = aktuelle EV // ---------------------------- - $this->SetValue("Aktuelle_Leistung_SDL", $pSdlW); - $this->SetValue("Aktuelle_Leistung_EV", $totalPower_ist + $pSdlW); + + + + // --------------------------------------------------------- + // AKTUELLE_Leistung EV/SDL + // Ziel: + // - wenn beide aktiv: beide zeigen totalPower_ist (z.B. ~ -4000W) + // - wenn einer 0 ist: Umschaltbar -> auf "anderen" oder immer auf SDL + // --------------------------------------------------------- + $eps = 0.01; + + // Wenn du willst, dass bei 0 immer SDL bekommt -> true setzen + $preferSDLWhenOneIsZero = true; + + if (abs($pEvW) < $eps && abs($pSdlW) < $eps) { + $this->SetValue("Aktuelle_Leistung_EV", 0.0); + $this->SetValue("Aktuelle_Leistung_SDL", 0.0); + + } elseif (abs($pEvW) < $eps || abs($pSdlW) < $eps) { + // Einer ist 0 + if ($preferSDLWhenOneIsZero) { + // immer SDL bekommt totalPower_ist + $this->SetValue("Aktuelle_Leistung_EV", 0.0); + $this->SetValue("Aktuelle_Leistung_SDL", $totalPower_ist); + } else { + // "klassisch": der nicht-0 Kanal bekommt totalPower_ist + if (abs($pEvW) < $eps) { + $this->SetValue("Aktuelle_Leistung_EV", 0.0); + $this->SetValue("Aktuelle_Leistung_SDL", $totalPower_ist); + } else { + $this->SetValue("Aktuelle_Leistung_EV", $totalPower_ist); + $this->SetValue("Aktuelle_Leistung_SDL", 0.0); + } + } + + } else { + // Beide aktiv -> beide sollen ca. totalPower_ist anzeigen (dein Wunsch) + $this->SetValue("Aktuelle_Leistung_EV", $totalPower_ist); + $this->SetValue("Aktuelle_Leistung_SDL", $totalPower_ist); + } + return $finalOutput; }