no message
This commit is contained in:
+122
-138
@@ -53,9 +53,8 @@ class Bat_EV_SDL_V3_Beta extends IPSModule
|
|||||||
}
|
}
|
||||||
throw new Exception("Invalid Ident: " . $Ident);
|
throw new Exception("Invalid Ident: " . $Ident);
|
||||||
}
|
}
|
||||||
public function Update()
|
public function Update()
|
||||||
{
|
{
|
||||||
// Reentranzschutz – verhindert parallele Update()-Läufe
|
|
||||||
$semKey = 'BatEVSDL_Update_' . $this->InstanceID;
|
$semKey = 'BatEVSDL_Update_' . $this->InstanceID;
|
||||||
|
|
||||||
if (!IPS_SemaphoreEnter($semKey, 5000)) {
|
if (!IPS_SemaphoreEnter($semKey, 5000)) {
|
||||||
@@ -64,12 +63,10 @@ class Bat_EV_SDL_V3_Beta extends IPSModule
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (!GetValue($this->GetIDForIdent("State"))) {
|
if (!GetValue($this->GetIDForIdent("State"))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache nur neu bauen, wenn nötig
|
|
||||||
$this->BuildBatteryCache(false);
|
$this->BuildBatteryCache(false);
|
||||||
|
|
||||||
$cache = json_decode($this->GetBufferSafe("BatCacheJSON"), true);
|
$cache = json_decode($this->GetBufferSafe("BatCacheJSON"), true);
|
||||||
@@ -78,44 +75,29 @@ class Bat_EV_SDL_V3_Beta extends IPSModule
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====================
|
|
||||||
// Zeitbasis (ms-genau)
|
|
||||||
// =====================
|
|
||||||
$now = microtime(true);
|
$now = microtime(true);
|
||||||
|
|
||||||
$lastTs = (float)$this->GetBufferSafe("Int_LastTs"); // Float!
|
$lastTs = (float)$this->GetBufferSafe("Int_LastTs");
|
||||||
$Esdl_kWh = (float)$this->GetBufferSafe("Int_E_SDL_kWh"); // SDL-Konto in kWh
|
$Esdl_kWh = (float)$this->GetBufferSafe("Int_E_SDL_kWh");
|
||||||
|
|
||||||
if ($lastTs <= 0.0) {
|
if ($lastTs <= 0.0) {
|
||||||
$lastTs = $now;
|
$lastTs = $now;
|
||||||
$Esdl_kWh = 0.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Beim allerersten Lauf NICHT mit 0 % starten,
|
|
||||||
// sondern virtuell auf Mitte setzen.
|
|
||||||
// Bei symmetrischem SDL-Fenster ist das genau 50 %.
|
|
||||||
/*
|
|
||||||
if ($this->GetBufferSafe("Int_Init_SDL") !== "1") {
|
|
||||||
$Esdl_kWh = $SDL_kWh_ges_cfg * 0.5;
|
|
||||||
$this->SetBuffer("Int_Init_SDL", "1");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
$dtSec = $now - $lastTs;
|
$dtSec = $now - $lastTs;
|
||||||
if ($dtSec < 0.0) $dtSec = 0.0;
|
if ($dtSec < 0.0) $dtSec = 0.0;
|
||||||
if ($dtSec > 10.0) $dtSec = 10.0; // optional: Kappe bei Aussetzern
|
if ($dtSec > 10.0) $dtSec = 10.0;
|
||||||
|
|
||||||
$dtH = $dtSec / 3600.0;
|
$dtH = $dtSec / 3600.0;
|
||||||
|
|
||||||
|
$pSdlSollW = (float)GetValue($this->GetIDForIdent("Nennleistung_Soll_SDL"));
|
||||||
|
|
||||||
$calc = [
|
$calc = [
|
||||||
"inputs" => $cache["inputs"] ?? [],
|
"inputs" => $cache["inputs"] ?? [],
|
||||||
"batteries" => [],
|
"batteries" => [],
|
||||||
"total" => []
|
"total" => []
|
||||||
];
|
];
|
||||||
|
|
||||||
// =====================
|
|
||||||
// Summen
|
|
||||||
// =====================
|
|
||||||
$sdlDisKW_ges = 0.0;
|
$sdlDisKW_ges = 0.0;
|
||||||
$evDisKW_ges = 0.0;
|
$evDisKW_ges = 0.0;
|
||||||
$sdlChKW_ges = 0.0;
|
$sdlChKW_ges = 0.0;
|
||||||
@@ -128,8 +110,6 @@ class Bat_EV_SDL_V3_Beta extends IPSModule
|
|||||||
$EV_kWh_ges = 0.0;
|
$EV_kWh_ges = 0.0;
|
||||||
$totalCapKWh = 0.0;
|
$totalCapKWh = 0.0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$SDL_kWh_ges_cfg = 0.0;
|
$SDL_kWh_ges_cfg = 0.0;
|
||||||
$SDL_start_kWh_cfg = 0.0;
|
$SDL_start_kWh_cfg = 0.0;
|
||||||
|
|
||||||
@@ -143,16 +123,13 @@ class Bat_EV_SDL_V3_Beta extends IPSModule
|
|||||||
: 0.0;
|
: 0.0;
|
||||||
|
|
||||||
$startPct = max(0.0, min(100.0, $startPct));
|
$startPct = max(0.0, min(100.0, $startPct));
|
||||||
|
|
||||||
$this->SetIdentValue("SDL_Start_Pos", round($startPct, 3));
|
$this->SetIdentValue("SDL_Start_Pos", round($startPct, 3));
|
||||||
|
|
||||||
|
if ($this->GetBufferSafe("Int_Init_SDL") !== "1") {
|
||||||
|
$Esdl_kWh = max(0.0, min($SDL_kWh_ges_cfg, $SDL_start_kWh_cfg));
|
||||||
|
$this->SetBuffer("Int_Init_SDL", "1");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// aktueller virtueller SDL-Stand
|
|
||||||
$sdlVirtPct = ($SDL_kWh_ges_cfg > 0.0)
|
$sdlVirtPct = ($SDL_kWh_ges_cfg > 0.0)
|
||||||
? ($Esdl_kWh / $SDL_kWh_ges_cfg * 100.0)
|
? ($Esdl_kWh / $SDL_kWh_ges_cfg * 100.0)
|
||||||
: 0.0;
|
: 0.0;
|
||||||
@@ -162,77 +139,80 @@ class Bat_EV_SDL_V3_Beta extends IPSModule
|
|||||||
$sdlIsEmpty = ($sdlVirtPct <= 0.1);
|
$sdlIsEmpty = ($sdlVirtPct <= 0.1);
|
||||||
$sdlIsFull = ($sdlVirtPct >= 99.9);
|
$sdlIsFull = ($sdlVirtPct >= 99.9);
|
||||||
|
|
||||||
foreach ($cache["bats"] as $i => $c) {
|
$sdlHitUpperBySDL = false;
|
||||||
|
$sdlHitLowerBySDL = false;
|
||||||
|
|
||||||
|
foreach ($cache["bats"] as $i => $c) {
|
||||||
$capKWh = (float)($c["capKWh"] ?? 0.0);
|
$capKWh = (float)($c["capKWh"] ?? 0.0);
|
||||||
if ($capKWh <= 0.0) {
|
if ($capKWh <= 0.0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SoC lesen
|
|
||||||
$socVarId = (int)($c["socVarId"] ?? 0);
|
$socVarId = (int)($c["socVarId"] ?? 0);
|
||||||
$socPct = $this->ReadSocPercent($socVarId);
|
$socPct = $this->ReadSocPercent($socVarId);
|
||||||
|
|
||||||
$real_kWh = $capKWh / 100.0 * $socPct;
|
$real_kWh = $capKWh / 100.0 * $socPct;
|
||||||
|
|
||||||
// vorkalkuliert
|
|
||||||
$typ = (string)($c["typ"] ?? ("Bat " . ($i + 1)));
|
$typ = (string)($c["typ"] ?? ("Bat " . ($i + 1)));
|
||||||
$underKWh = (float)($c["underKWh"] ?? 0.0);
|
$underKWh = (float)($c["underKWh"] ?? 0.0);
|
||||||
$upKWh = (float)($c["upKWh"] ?? 0.0);
|
$upKWh = (float)($c["upKWh"] ?? 0.0);
|
||||||
|
|
||||||
// Standard: EV darf nur zwischen underKWh und upKWh arbeiten
|
if ($real_kWh > $upKWh && $pSdlSollW > 0.0) {
|
||||||
|
$sdlHitUpperBySDL = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($real_kWh < $underKWh && $pSdlSollW < 0.0) {
|
||||||
|
$sdlHitLowerBySDL = true;
|
||||||
|
}
|
||||||
|
|
||||||
$evUnderKWh = $underKWh;
|
$evUnderKWh = $underKWh;
|
||||||
$evUpKWh = $upKWh;
|
$evUpKWh = $upKWh;
|
||||||
|
|
||||||
// Wenn SDL virtuell leer ist, darf EV die untere SDL-Reserve verwenden
|
|
||||||
if ($sdlIsEmpty) {
|
if ($sdlIsEmpty) {
|
||||||
$evUnderKWh = 0.0;
|
$evUnderKWh = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wenn SDL virtuell voll ist, darf EV die obere SDL-Reserve verwenden
|
|
||||||
if ($sdlIsFull) {
|
if ($sdlIsFull) {
|
||||||
$evUpKWh = $capKWh;
|
$evUpKWh = $capKWh;
|
||||||
}
|
}
|
||||||
|
|
||||||
$evWindowKWh = max(0.0, $evUpKWh - $evUnderKWh);
|
$evWindowKWh = max(0.0, $evUpKWh - $evUnderKWh);
|
||||||
|
|
||||||
|
$SDL_kWh = (float)($c["SDL_kWh_total"] ?? 0.0);
|
||||||
$SDL_kWh = (float)($c["SDL_kWh_total"] ?? 0.0);
|
$EV_kWh = (float)($c["EV_kWh_total"] ?? 0.0);
|
||||||
$EV_kWh = (float)($c["EV_kWh_total"] ?? 0.0);
|
|
||||||
|
|
||||||
$sdlShareKW_laden = (float)($c["sdlShareKW_laden"] ?? 0.0);
|
$sdlShareKW_laden = (float)($c["sdlShareKW_laden"] ?? 0.0);
|
||||||
$sdlShareKW_entladen = (float)($c["sdlShareKW_entladen"] ?? 0.0);
|
$sdlShareKW_entladen = (float)($c["sdlShareKW_entladen"] ?? 0.0);
|
||||||
$evShareKW_laden = (float)($c["evShareKW_laden"] ?? 0.0);
|
$evShareKW_laden = (float)($c["evShareKW_laden"] ?? 0.0);
|
||||||
$evShareKW_entladen = (float)($c["evShareKW_entladen"] ?? 0.0);
|
$evShareKW_entladen = (float)($c["evShareKW_entladen"] ?? 0.0);
|
||||||
|
|
||||||
// Defaults
|
|
||||||
$EV_SOC = 0.0;
|
$EV_SOC = 0.0;
|
||||||
$SDL_SOC = 0.0;
|
$SDL_SOC = 0.0;
|
||||||
|
|
||||||
$sdlDisKW = 0.0; $evDisKW = 0.0;
|
$sdlDisKW = 0.0;
|
||||||
$sdlChKW = 0.0; $evChKW = 0.0;
|
$evDisKW = 0.0;
|
||||||
|
$sdlChKW = 0.0;
|
||||||
|
$evChKW = 0.0;
|
||||||
|
|
||||||
$real_kWh_ev = 0.0;
|
$real_kWh_ev = 0.0;
|
||||||
$real_kWh_sdl = 0.0;
|
$real_kWh_sdl = 0.0;
|
||||||
|
|
||||||
// --- 3 Fälle ---
|
|
||||||
if ($underKWh <= $real_kWh && $real_kWh <= $upKWh) {
|
if ($underKWh <= $real_kWh && $real_kWh <= $upKWh) {
|
||||||
|
|
||||||
// EV_SOC im Fenster dynamisch (0..100)
|
|
||||||
if ($evWindowKWh > 0.0) {
|
if ($evWindowKWh > 0.0) {
|
||||||
$EV_SOC = 100.0 * ($real_kWh - $evUnderKWh) / $evWindowKWh;
|
$EV_SOC = 100.0 * ($real_kWh - $evUnderKWh) / $evWindowKWh;
|
||||||
} else {
|
} else {
|
||||||
$EV_SOC = 0.0;
|
$EV_SOC = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$EV_SOC = is_finite($EV_SOC) ? max(0.0, min(100.0, $EV_SOC)) : 0.0;
|
$EV_SOC = is_finite($EV_SOC) ? max(0.0, min(100.0, $EV_SOC)) : 0.0;
|
||||||
|
|
||||||
// SDL_SOC (wie in deinem alten Code im Fenster)
|
|
||||||
$denSDL = ($capKWh - $upKWh + $underKWh);
|
$denSDL = ($capKWh - $upKWh + $underKWh);
|
||||||
if ($denSDL > 0.0) {
|
if ($denSDL > 0.0) {
|
||||||
$SDL_SOC = 100.0 * $underKWh / $denSDL;
|
$SDL_SOC = 100.0 * $underKWh / $denSDL;
|
||||||
} else {
|
} else {
|
||||||
$SDL_SOC = 0.0;
|
$SDL_SOC = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$SDL_SOC = is_finite($SDL_SOC) ? max(0.0, min(100.0, $SDL_SOC)) : 0.0;
|
$SDL_SOC = is_finite($SDL_SOC) ? max(0.0, min(100.0, $SDL_SOC)) : 0.0;
|
||||||
|
|
||||||
$sdlDisKW = $sdlShareKW_entladen;
|
$sdlDisKW = $sdlShareKW_entladen;
|
||||||
@@ -244,48 +224,58 @@ class Bat_EV_SDL_V3_Beta extends IPSModule
|
|||||||
$real_kWh_sdl = $real_kWh - $real_kWh_ev;
|
$real_kWh_sdl = $real_kWh - $real_kWh_ev;
|
||||||
|
|
||||||
} elseif ($real_kWh > $evUpKWh) {
|
} elseif ($real_kWh > $evUpKWh) {
|
||||||
|
|
||||||
// Obere Grenze: EV = 100%
|
|
||||||
$EV_SOC = 100.0;
|
$EV_SOC = 100.0;
|
||||||
|
|
||||||
// SDL_SOC (deine obere Formel)
|
|
||||||
$den1 = ($capKWh - $real_kWh + $underKWh);
|
$den1 = ($capKWh - $real_kWh + $underKWh);
|
||||||
$den2 = (2.0 * $underKWh);
|
$den2 = (2.0 * $underKWh);
|
||||||
|
|
||||||
if ($den1 > 0.0 && $den2 > 0.0) {
|
if ($den1 > 0.0 && $den2 > 0.0) {
|
||||||
$SDL_SOC = min(100.0, ($den1 / $den2) * 100.0);
|
$SDL_SOC = min(100.0, ($den1 / $den2) * 100.0);
|
||||||
} else {
|
} else {
|
||||||
$SDL_SOC = 0.0;
|
$SDL_SOC = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$SDL_SOC = is_finite($SDL_SOC) ? max(0.0, min(100.0, $SDL_SOC)) : 0.0;
|
$SDL_SOC = is_finite($SDL_SOC) ? max(0.0, min(100.0, $SDL_SOC)) : 0.0;
|
||||||
|
|
||||||
$sdlDisKW = $sdlShareKW_entladen;
|
$sdlDisKW = $sdlShareKW_entladen;
|
||||||
$evDisKW = $evShareKW_entladen;
|
$evDisKW = $evShareKW_entladen;
|
||||||
$sdlChKW = $sdlShareKW_laden;
|
$sdlChKW = $sdlShareKW_laden;
|
||||||
$evChKW = 0.0; // EV darf oben nicht laden
|
$evChKW = 0.0;
|
||||||
|
|
||||||
$real_kWh_ev = $capKWh - ($capKWh - $upKWh + $underKWh);
|
$real_kWh_ev = $evWindowKWh;
|
||||||
$real_kWh_sdl = ($capKWh - $upKWh + $underKWh) - ($capKWh - $real_kWh);
|
$real_kWh_sdl = max(0.0, $real_kWh - $real_kWh_ev);
|
||||||
|
|
||||||
} elseif ($real_kWh < $evUnderKWh) {
|
} elseif ($real_kWh < $evUnderKWh) {
|
||||||
|
|
||||||
// Untere Grenze: EV = 0%
|
|
||||||
$EV_SOC = 0.0;
|
$EV_SOC = 0.0;
|
||||||
|
|
||||||
// SDL_SOC (deine untere Formel)
|
|
||||||
$den = $upKWh + $underKWh;
|
$den = $upKWh + $underKWh;
|
||||||
$SDL_SOC = ($den > 0.0) ? ($real_kWh * 100.0 / $den) : 0.0;
|
$SDL_SOC = ($den > 0.0) ? ($real_kWh * 100.0 / $den) : 0.0;
|
||||||
$SDL_SOC = is_finite($SDL_SOC) ? max(0.0, min(100.0, $SDL_SOC)) : 0.0;
|
$SDL_SOC = is_finite($SDL_SOC) ? max(0.0, min(100.0, $SDL_SOC)) : 0.0;
|
||||||
|
|
||||||
$sdlDisKW = $sdlShareKW_entladen;
|
$sdlDisKW = $sdlShareKW_entladen;
|
||||||
$evDisKW = 0.0; // EV darf unten nicht entladen
|
$evDisKW = 0.0;
|
||||||
$sdlChKW = $sdlShareKW_laden;
|
$sdlChKW = $sdlShareKW_laden;
|
||||||
$evChKW = $evShareKW_laden;
|
$evChKW = $evShareKW_laden;
|
||||||
|
|
||||||
$real_kWh_ev = 0.0;
|
$real_kWh_ev = 0.0;
|
||||||
$real_kWh_sdl = $real_kWh;
|
$real_kWh_sdl = $real_kWh;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if ($evWindowKWh > 0.0) {
|
||||||
|
$EV_SOC = 100.0 * ($real_kWh - $evUnderKWh) / $evWindowKWh;
|
||||||
|
}
|
||||||
|
|
||||||
|
$EV_SOC = is_finite($EV_SOC) ? max(0.0, min(100.0, $EV_SOC)) : 0.0;
|
||||||
|
|
||||||
|
$sdlDisKW = $sdlShareKW_entladen;
|
||||||
|
$evDisKW = $evShareKW_entladen;
|
||||||
|
$sdlChKW = $sdlShareKW_laden;
|
||||||
|
$evChKW = $evShareKW_laden;
|
||||||
|
|
||||||
|
$real_kWh_ev = max(0.0, min($evWindowKWh, $real_kWh - $evUnderKWh));
|
||||||
|
$real_kWh_sdl = $real_kWh - $real_kWh_ev;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Null/Full Schutz
|
|
||||||
if ($real_kWh <= 0.0) {
|
if ($real_kWh <= 0.0) {
|
||||||
$sdlDisKW = 0.0;
|
$sdlDisKW = 0.0;
|
||||||
$real_kWh_ev = 0.0;
|
$real_kWh_ev = 0.0;
|
||||||
@@ -299,7 +289,6 @@ class Bat_EV_SDL_V3_Beta extends IPSModule
|
|||||||
$real_kWh_ev = max(0.0, $real_kWh_ev);
|
$real_kWh_ev = max(0.0, $real_kWh_ev);
|
||||||
$real_kWh_sdl = max(0.0, $real_kWh_sdl);
|
$real_kWh_sdl = max(0.0, $real_kWh_sdl);
|
||||||
|
|
||||||
// Summen
|
|
||||||
$totalCapKWh += $capKWh;
|
$totalCapKWh += $capKWh;
|
||||||
|
|
||||||
$sdlDisKW_ges += $sdlDisKW;
|
$sdlDisKW_ges += $sdlDisKW;
|
||||||
@@ -317,134 +306,129 @@ class Bat_EV_SDL_V3_Beta extends IPSModule
|
|||||||
"idx" => $c["idx"] ?? $i,
|
"idx" => $c["idx"] ?? $i,
|
||||||
"typ" => $typ,
|
"typ" => $typ,
|
||||||
"SoC_varId" => $socVarId,
|
"SoC_varId" => $socVarId,
|
||||||
"SoC_pct" => round($socPct, 3),
|
"SoC_pct" => round($socPct, 3),
|
||||||
"Effektive kWh" => round($real_kWh, 3),
|
"Effektive kWh" => round($real_kWh, 3),
|
||||||
|
|
||||||
"EV_SOC" => round($EV_SOC, 3),
|
"EV_SOC" => round($EV_SOC, 3),
|
||||||
"SDL_SOC" => round($SDL_SOC, 3),
|
"SDL_SOC" => round($SDL_SOC, 3),
|
||||||
|
|
||||||
"EV_kWh" => round($real_kWh_ev, 3),
|
"EV_kWh" => round($real_kWh_ev, 3),
|
||||||
"SDL_kWh" => round($real_kWh_sdl, 3),
|
"SDL_kWh" => round($real_kWh_sdl, 3),
|
||||||
|
|
||||||
"under_grenze_kWh" => round($underKWh, 3),
|
"under_grenze_kWh" => round($underKWh, 3),
|
||||||
"up_grenze_kWh" => round($upKWh, 3),
|
"up_grenze_kWh" => round($upKWh, 3),
|
||||||
|
|
||||||
"SDL_Charge_kW" => round($sdlChKW, 3),
|
"SDL_Charge_kW" => round($sdlChKW, 3),
|
||||||
"SDL_Discharge_kW" => round($sdlDisKW, 3),
|
"SDL_Discharge_kW" => round($sdlDisKW, 3),
|
||||||
"EV_Charge_kW" => round($evChKW, 3),
|
"EV_Charge_kW" => round($evChKW, 3),
|
||||||
"EV_Discharge_kW" => round($evDisKW, 3),
|
"EV_Discharge_kW" => round($evDisKW, 3),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================
|
$evPosPct = ($EV_kWh_ges > 0.0)
|
||||||
// EV Anzeige: "normal" physikalisch (ja: aus realem SoC!)
|
? ($real_kWh_ev_ges / $EV_kWh_ges * 100.0)
|
||||||
// ============================
|
: 0.0;
|
||||||
$evPosPct = ($EV_kWh_ges > 0.0) ? ($real_kWh_ev_ges / $EV_kWh_ges * 100.0) : 0.0;
|
|
||||||
$evPosPct = max(0.0, min(100.0, $evPosPct));
|
$evPosPct = max(0.0, min(100.0, $evPosPct));
|
||||||
$this->SetIdentValue("SoC_EV", round($evPosPct, 3));
|
$this->SetIdentValue("SoC_EV", round($evPosPct, 3));
|
||||||
|
|
||||||
// ============================
|
|
||||||
// SDL Anzeige: integriert mit Nennleistung_Soll_SDL
|
|
||||||
// UND WICHTIG: bei Soll = 0 -> SoC stehen lassen (kein Resync!)
|
|
||||||
// ============================
|
|
||||||
$pSdlSollW = (float)GetValue($this->GetIDForIdent("Nennleistung_Soll_SDL"));
|
|
||||||
$epsW = 1.0;
|
$epsW = 1.0;
|
||||||
$sdlActive = (abs($pSdlSollW) > $epsW);
|
$sdlActive = (abs($pSdlSollW) > $epsW);
|
||||||
|
|
||||||
// Soll auf erlaubte SDL-Leistung clampen (aus Summen kW->W)
|
|
||||||
$maxSDL_ch = $sdlChKW_ges * 1000.0;
|
$maxSDL_ch = $sdlChKW_ges * 1000.0;
|
||||||
$maxSDL_dis = $sdlDisKW_ges * 1000.0;
|
$maxSDL_dis = $sdlDisKW_ges * 1000.0;
|
||||||
$pSdlSollW = max(-$maxSDL_dis, min($maxSDL_ch, $pSdlSollW));
|
|
||||||
|
|
||||||
|
$pSdlSollW = max(-$maxSDL_dis, min($maxSDL_ch, $pSdlSollW));
|
||||||
// Soll auf erlaubte SDL-Leistung clampen (aus Summen kW->W)// Soll auf = $sdlChKW_ges * 1000.0;
|
|
||||||
$maxSDL_dis = $sdlDisKW_ges * 1000.0;
|
|
||||||
$pSdlSollW = max(-$maxSDL_dis, min($maxSDL_ch, $pSdlSollW));
|
|
||||||
|
|
||||||
/* ============================================================
|
$cacheHash = (string)$this->GetBufferSafe("BatCacheHash");
|
||||||
* RESYNC: Wenn sich Cache/SDL-Leistung geändert hat,
|
$intHash = (string)$this->GetBufferSafe("Int_CFG_HASH");
|
||||||
* dann SDL-Integrator auf physikalischen Wert setzen,
|
|
||||||
* damit SDL_Pos nicht plötzlich auf ~0% springt.
|
|
||||||
* ============================================================ */
|
|
||||||
$cacheHash = (string)$this->GetBufferSafe("BatCacheHash"); // wird in BuildBatteryCache() gesetzt
|
|
||||||
$intHash = (string)$this->GetBufferSafe("Int_CFG_HASH"); // unser gespeicherter Hash
|
|
||||||
|
|
||||||
// Erstinitialisierung
|
|
||||||
if ($intHash === "") {
|
if ($intHash === "") {
|
||||||
$this->SetBuffer("Int_CFG_HASH", $cacheHash);
|
$this->SetBuffer("Int_CFG_HASH", $cacheHash);
|
||||||
$intHash = $cacheHash;
|
$intHash = $cacheHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cacheHash !== "" && $cacheHash !== $intHash) {
|
if ($cacheHash !== "" && $cacheHash !== $intHash) {
|
||||||
|
$Esdl_kWh = max(0.0, min($SDL_kWh_ges_cfg, $SDL_start_kWh_cfg));
|
||||||
|
|
||||||
// Bei Cache-/SDL-Leistungsänderung wieder auf 50 %
|
$lastTs = $now;
|
||||||
$SDL_start_kWh_cfg = 0.0;
|
$dtH = 0.0;
|
||||||
|
|
||||||
foreach ($cache["bats"] as $bc) {
|
$this->SetBuffer("Int_LastTs", (string)$now);
|
||||||
$SDL_start_kWh_cfg += (float)($bc["underKWh"] ?? 0.0);
|
$this->SetBuffer("Int_CFG_HASH", $cacheHash);
|
||||||
}
|
|
||||||
|
|
||||||
$Esdl_kWh = max(0.0, min($SDL_kWh_ges_cfg, $SDL_start_kWh_cfg));
|
|
||||||
|
|
||||||
$lastTs = $now;
|
|
||||||
$this->SetBuffer("Int_LastTs", (string)$now);
|
|
||||||
|
|
||||||
$this->SetBuffer("Int_CFG_HASH", $cacheHash);
|
|
||||||
$this->SetBuffer("Int_Init_SDL", "1");
|
|
||||||
|
|
||||||
$this->SendDebug("SDL", "Reset wegen CacheHash-Change auf 50%: Esdl_kWh=" . round($Esdl_kWh, 3), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Init SDL-Konto einmalig auf physikalische Referenz (nur beim ersten Lauf)
|
|
||||||
if ($this->GetBufferSafe("Int_Init_SDL") !== "1") {
|
|
||||||
$Esdl_kWh = $SDL_kWh_ges_cfg * 0.5;
|
|
||||||
$this->SetBuffer("Int_Init_SDL", "1");
|
$this->SetBuffer("Int_Init_SDL", "1");
|
||||||
|
|
||||||
|
$this->SendDebug("SDL", "Reset wegen CacheHash-Change auf Startpunkt: Esdl_kWh=" . round($Esdl_kWh, 3), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WICHTIG:
|
||||||
|
* Nur wenn SDL selbst in Richtung Grenze fährt, wird der Integrator
|
||||||
|
* auf den physikalischen Grenzpunkt gesetzt.
|
||||||
|
*
|
||||||
|
* EV überschreitet Grenze -> KEIN Sprung von SDL_Pos.
|
||||||
|
*/
|
||||||
|
if ($sdlHitUpperBySDL || $sdlHitLowerBySDL) {
|
||||||
|
$Esdl_kWh = max(0.0, min($SDL_kWh_ges, $real_kWh_sdl_ges));
|
||||||
|
$dtH = 0.0;
|
||||||
|
|
||||||
|
$this->SetBuffer("Int_LastTs", (string)$now);
|
||||||
|
|
||||||
|
$this->SendDebug(
|
||||||
|
"SDL",
|
||||||
|
"Physikalischer Grenz-Anker: Esdl_kWh=" . round($Esdl_kWh, 3) .
|
||||||
|
" upper=" . ($sdlHitUpperBySDL ? "1" : "0") .
|
||||||
|
" lower=" . ($sdlHitLowerBySDL ? "1" : "0"),
|
||||||
|
0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nur wenn aktiv integrieren, sonst: NICHTS -> Konto bleibt stehen
|
|
||||||
if ($sdlActive) {
|
if ($sdlActive) {
|
||||||
$Esdl_kWh += (($pSdlSollW / 1000.0) * $dtH);
|
$Esdl_kWh += (($pSdlSollW / 1000.0) * $dtH);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clamp SDL-Konto
|
$Esdl_kWh = ($SDL_kWh_ges > 0.0)
|
||||||
$Esdl_kWh = ($SDL_kWh_ges > 0.0) ? max(0.0, min($SDL_kWh_ges, $Esdl_kWh)) : 0.0;
|
? max(0.0, min($SDL_kWh_ges, $Esdl_kWh))
|
||||||
|
: 0.0;
|
||||||
|
|
||||||
|
$sdlPosPct = ($SDL_kWh_ges > 0.0)
|
||||||
|
? ($Esdl_kWh / $SDL_kWh_ges * 100.0)
|
||||||
|
: 0.0;
|
||||||
|
|
||||||
$sdlPosPct = ($SDL_kWh_ges > 0.0) ? ($Esdl_kWh / $SDL_kWh_ges * 100.0) : 0.0;
|
|
||||||
$sdlPosPct = max(0.0, min(100.0, $sdlPosPct));
|
$sdlPosPct = max(0.0, min(100.0, $sdlPosPct));
|
||||||
|
|
||||||
$this->SetIdentValue("SDL_Pos", round($sdlPosPct, 3));
|
$this->SetIdentValue("SDL_Pos", round($sdlPosPct, 3));
|
||||||
|
|
||||||
// ============================
|
$this->SetIdentValue("P_SDL_laden", round($sdlChKW_ges * 1000.0, 0));
|
||||||
// Maximalleistungen anzeigen
|
|
||||||
// ============================
|
|
||||||
$this->SetIdentValue("P_SDL_laden", round($sdlChKW_ges * 1000.0, 0));
|
|
||||||
$this->SetIdentValue("P_SDL_entladen", round($sdlDisKW_ges * 1000.0, 0));
|
$this->SetIdentValue("P_SDL_entladen", round($sdlDisKW_ges * 1000.0, 0));
|
||||||
$this->SetIdentValue("P_EV_laden", (int)round($evChKW_ges * 1000.0, 0));
|
$this->SetIdentValue("P_EV_laden", (int)round($evChKW_ges * 1000.0, 0));
|
||||||
$this->SetIdentValue("P_EV_entladen", (int)round($evDisKW_ges * 1000.0, 0));
|
$this->SetIdentValue("P_EV_entladen", (int)round($evDisKW_ges * 1000.0, 0));
|
||||||
|
|
||||||
// Total JSON
|
|
||||||
$calc["total"] = [
|
$calc["total"] = [
|
||||||
"SDL_SoC_pct" => round($sdlPosPct, 3),
|
"SDL_SoC_pct" => round($sdlPosPct, 3),
|
||||||
"EV_SoC_pct" => round($evPosPct, 3),
|
"EV_SoC_pct" => round($evPosPct, 3),
|
||||||
|
|
||||||
"SDL_kWh_total" => round($SDL_kWh_ges, 3),
|
"SDL_kWh_total" => round($SDL_kWh_ges, 3),
|
||||||
"EV_kWh_total" => round($EV_kWh_ges, 3),
|
"EV_kWh_total" => round($EV_kWh_ges, 3),
|
||||||
"SDL_Charge_kW" => round($sdlChKW_ges, 3),
|
|
||||||
|
"SDL_Charge_kW" => round($sdlChKW_ges, 3),
|
||||||
"SDL_Discharge_kW" => round($sdlDisKW_ges, 3),
|
"SDL_Discharge_kW" => round($sdlDisKW_ges, 3),
|
||||||
"EV_Charge_kW" => round($evChKW_ges, 3),
|
"EV_Charge_kW" => round($evChKW_ges, 3),
|
||||||
"EV_Discharge_kW" => round($evDisKW_ges, 3),
|
"EV_Discharge_kW" => round($evDisKW_ges, 3),
|
||||||
"totalCap_kWh" => round($totalCapKWh, 3)
|
|
||||||
|
"totalCap_kWh" => round($totalCapKWh, 3),
|
||||||
|
|
||||||
|
"SDL_Start_pct" => round($startPct, 3),
|
||||||
|
"SDL_IsEmpty" => $sdlIsEmpty,
|
||||||
|
"SDL_IsFull" => $sdlIsFull,
|
||||||
|
"SDL_HitUpperBySDL" => $sdlHitUpperBySDL,
|
||||||
|
"SDL_HitLowerBySDL" => $sdlHitLowerBySDL
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->SetIdentValue("CalcJSON", json_encode($calc, JSON_PRETTY_PRINT));
|
$this->SetIdentValue("CalcJSON", json_encode($calc, JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
// Setpoints wie gehabt
|
|
||||||
$this->ApplySetpoints();
|
$this->ApplySetpoints();
|
||||||
|
|
||||||
// ============================
|
|
||||||
// Integrator State speichern (nur SDL)
|
|
||||||
// ============================
|
|
||||||
$this->SetBuffer("Int_LastTs", (string)$now);
|
$this->SetBuffer("Int_LastTs", (string)$now);
|
||||||
$this->SetBuffer("Int_E_SDL_kWh", (string)$Esdl_kWh);
|
$this->SetBuffer("Int_E_SDL_kWh", (string)$Esdl_kWh);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user