diff --git a/Bat_EV_SDL_V4/form.json b/Bat_EV_SDL_V4/form.json index 9415ad9..f1119bb 100644 --- a/Bat_EV_SDL_V4/form.json +++ b/Bat_EV_SDL_V4/form.json @@ -106,22 +106,13 @@ "digits": 0 }, { - "type": "NumberSpinner", - "name": "ReserveHoursLaden", - "caption": "SDL Reservezeit Laden", - "suffix": " h", - "minimum": 0, - "maximum": 24, - "digits": 2 - }, - { - "type": "NumberSpinner", - "name": "ReserveHoursEntladen", - "caption": "SDL Reservezeit Entladen", - "suffix": " h", - "minimum": 0, - "maximum": 24, - "digits": 2 + "type": "NumberSpinner", + "name": "ReserveHours", + "caption": "SDL Reservezeit", + "suffix": " h", + "minimum": 0, + "maximum": 24, + "digits": 2 }, { "type": "NumberSpinner", diff --git a/Bat_EV_SDL_V4/module.php b/Bat_EV_SDL_V4/module.php index d4cc61b..66d7c89 100644 --- a/Bat_EV_SDL_V4/module.php +++ b/Bat_EV_SDL_V4/module.php @@ -10,8 +10,7 @@ class Bat_EV_SDL_V4 extends IPSModule $this->RegisterPropertyString("Batteries", "[]"); $this->RegisterPropertyInteger("SDL_Leistung_Laden", 0); // W $this->RegisterPropertyInteger("SDL_Leistung_Entladen", 0); // W - $this->RegisterPropertyFloat("ReserveHoursLaden", 0.5); // h - $this->RegisterPropertyFloat("ReserveHoursEntladen", 0.5); // h + $this->RegisterPropertyFloat("ReserveHours", 0.5); // h $this->RegisterPropertyFloat("SDL_Start_Pos_Config", 50.0); // % $this->RegisterPropertyFloat("EV_Start_Pos_Config", 50.0); // % $this->RegisterPropertyInteger("UpdateInterval", 2); // Sekunden @@ -88,7 +87,24 @@ class Bat_EV_SDL_V4 extends IPSModule } return; } + + if ($Ident === "SDL_Reset") { + if ((bool)$Value) { + $this->ResetVirtualAccount("SDL"); + SetValue($this->GetIDForIdent("SDL_Reset"), false); + $this->Update(); + } + return; + } + if ($Ident === "EV_Reset") { + if ((bool)$Value) { + $this->ResetVirtualAccount("EV"); + SetValue($this->GetIDForIdent("EV_Reset"), false); + $this->Update(); + } + return; + } throw new Exception("Invalid Ident: " . $Ident); } @@ -157,8 +173,7 @@ class Bat_EV_SDL_V4 extends IPSModule $sdlTotalW_laden = max(0, (int)$this->ReadPropertyInteger("SDL_Leistung_Laden")); $sdlTotalW_entladen = max(0, (int)$this->ReadPropertyInteger("SDL_Leistung_Entladen")); - $reserveH_laden = max(0.0, (float)$this->ReadPropertyFloat("ReserveHoursLaden")); - $reserveH_entladen = max(0.0, (float)$this->ReadPropertyFloat("ReserveHoursEntladen")); + $reserveH = max(0.0, (float)$this->ReadPropertyFloat("ReserveHours")); $hash = md5(json_encode([ "Batteries" => $batteriesRaw, @@ -235,8 +250,8 @@ class Bat_EV_SDL_V4 extends IPSModule $evShareKW_entladen = max(0.0, $pBatKW - $sdlShareKW_entladen); // Grenzen: individuell nach Reservezeit. - $underKWh = $sdlShareKW_entladen * $reserveH_entladen; - $upKWh = $capKWh - ($sdlShareKW_laden * $reserveH_laden); + $underKWh = $sdlShareKW_entladen * $reserveH; + $upKWh = $capKWh - ($sdlShareKW_laden * $reserveH); $underKWh = max(0.0, min($capKWh, $underKWh)); $upKWh = max(0.0, min($capKWh, $upKWh)); @@ -769,6 +784,37 @@ class Bat_EV_SDL_V4 extends IPSModule $this->SetIdentValue("CalcJSON", json_encode(["error" => $reason], JSON_PRETTY_PRINT)); } + private function ResetVirtualAccount(string $account): void + { + $plan = json_decode($this->GetBufferSafe("BatPlanJSON"), true); + if (!is_array($plan)) { + $this->BuildBatteryPlan(true); + $plan = json_decode($this->GetBufferSafe("BatPlanJSON"), true); + } + + if (!is_array($plan) || empty($plan["total"])) { + return; + } + + if ($account === "SDL") { + $total = (float)($plan["total"]["SDL_kWh_total"] ?? 0.0); + $startPct = 50.0; + + $this->SetBuffer("Int_E_SDL_kWh", (string)($total * $startPct / 100.0)); + $this->SetBuffer("Int_LastTs", (string)microtime(true)); + return; + } + + if ($account === "EV") { + $total = (float)($plan["total"]["EV_kWh_total"] ?? 0.0); + $startPct = 50.0; + + $this->SetBuffer("Int_E_EV_kWh", (string)($total * $startPct / 100.0)); + $this->SetBuffer("Int_LastTs", (string)microtime(true)); + return; + } + } + private function SetIdentValue(string $ident, $value): void { $id = @$this->GetIDForIdent($ident);