diff --git a/Bat_EV_SDL/module.php b/Bat_EV_SDL/module.php index 75c8d03..7a2d9b3 100644 --- a/Bat_EV_SDL/module.php +++ b/Bat_EV_SDL/module.php @@ -16,16 +16,15 @@ class Bat_EV_SDL extends IPSModule $this->RegisterVariableFloat("SDL_Pos", "SDL Energie verfügbar (%)", "", 10); $this->RegisterVariableFloat("SoC_EV", "EV Energie verfügbar (%)", "", 11); // Leistungsgrenzen - $this->RegisterVariableFloat("P_SDL_max", "SDL max (W)", "", 20); + $this->RegisterVariableFloat("P_SDL_laden", "P SDL laden max (W)", "", 21); $this->RegisterVariableFloat("P_SDL_entladen", "P SDL entladen max (W)", "", 22); - $this->RegisterVariableFloat("P_EV_max", "EV max (W)", "", 30); $this->RegisterVariableFloat("P_EV_laden", "P EV laden max (W)", "", 31); $this->RegisterVariableFloat("P_EV_entladen", "P EV entladen max (W)", "", 32); // Debug $this->RegisterVariableString("CalcJSON", "Berechnung (JSON)", "", 99); // Timer - $this->RegisterTimer("UpdateTimer", 0, 'GEF_Update($_IPS["TARGET"]);'); + $this->RegisterTimer("UpdateTimer", 0, 'Bat_EV_SDL_Update($_IPS["TARGET"]);'); } public function ApplyChanges() { @@ -120,10 +119,12 @@ class Bat_EV_SDL extends IPSModule $sdlShareKW = $sdlTotalkW/$sumBatPowerkW*$pBatkW; // SDL Power $evShareKW = $pBatkW - $sdlShareKW ; // EV Power - $underKWh = $sdlShareKW * $hours;// untere GRenze für SDL + //$underKWh = $sdlShareKW * $hours;// untere GRenze für SDL + $underKWh = max(0.0, min($underKWh, $capKWh / 2.0)); $upKWh = $capKWh - $underKWh ; // obere Grenze für SDL $SDL_kWh = 2*$underKWh; //SDL kWh - $EV_kWH = $capKWh - 2*$underKWh; // EV kWh + //$EV_kWH = $capKWh - 2*$underKWh; // EV kWh + $EV_kWH = max(0.0, $capKWh - $SDL_kWh); $real_kWh = $capKWh/100 * $socPct;// Jetziger Füllstand in kWh if ($underKWh < $real_kWh && $upKWh > $real_kWh ){ @@ -138,7 +139,10 @@ class Bat_EV_SDL extends IPSModule $real_kWh_sdl = $underKWh; } elseif ($upKWh < $real_kWh) { $EV_SOC = 100; - $SDL_SOC = ($capKWh - $EV_kWH) / (2*$underKWh) * 100; + + $SDL_SOC = (2*$underKWh) / ($capKWh - $real_kWh + $underKWh) * 100; + + $sdlDisKW = $sdlShareKW; // SDL- $evDisKW = $evShareKW; // EV- $sdlChKW = $sdlShareKW; // SDL+ @@ -209,8 +213,10 @@ class Bat_EV_SDL extends IPSModule } - $evPosPct = $real_kWh_ev_ges/ $EV_kWh_ges *100 ; - $sdlPosPct = $real_kWh_sdl_ges/ $SDL_kWh_ges *100 ; + //$evPosPct = $real_kWh_ev_ges/ $EV_kWh_ges *100 ; + //$sdlPosPct = $real_kWh_sdl_ges/ $SDL_kWh_ges *100 ; + $evPosPct = ($EV_kWh_ges > 0) ? ($real_kWh_ev_ges / $EV_kWh_ges * 100.0) : 0.0; + $sdlPosPct = ($SDL_kWh_ges > 0) ? ($real_kWh_sdl_ges / $SDL_kWh_ges * 100.0) : 0.0; // Variablen setzen $this->SetIdentValue("SDL_Pos", round($sdlPosPct, 3)); $this->SetIdentValue("SoC_EV", round($evPosPct, 3)); @@ -239,10 +245,9 @@ class Bat_EV_SDL extends IPSModule { $this->SetIdentValue("SDL_Pos", 0.0); $this->SetIdentValue("SoC_EV", 0.0); - $this->SetIdentValue("P_SDL_max", 0.0); + $this->SetIdentValue("P_SDL_laden", 0.0); $this->SetIdentValue("P_SDL_entladen", 0.0); - $this->SetIdentValue("P_EV_max", 0.0); $this->SetIdentValue("P_EV_laden", 0.0); $this->SetIdentValue("P_EV_entladen", 0.0); $this->SetIdentValue("CalcJSON", json_encode(["error" => $reason], JSON_PRETTY_PRINT));