no message

This commit is contained in:
belevo\mh
2026-04-30 16:01:33 +02:00
parent eda14a74c6
commit 88ea835aa1
+6 -69
View File
@@ -39,7 +39,7 @@ class Bat_EV_SDL_V3_Beta extends IPSModule
$this->SetTimerInterval("UpdateTimer", ($intervalSec > 0) ? $intervalSec * 1000 : 0);
// Cache neu bauen (force)
$this->BuildBatteryCache(true);
$this->ResetSDLTo50Percent();
$this->Update();
}
public function RequestAction($Ident, $Value)
@@ -172,15 +172,7 @@ public function Update()
$underKWh = (float)($c["underKWh"] ?? 0.0);
$upKWh = (float)($c["upKWh"] ?? 0.0);
// Grenz-Anker nur wenn SDL wirklich in Richtung Grenze fährt:
// Laden (Ist > 0): oberhalb up -> Upper Hit
if ($real_kWh > $upKWh && $pSdlIstW_raw > 0.0) {
$sdlHitUpperBySDL = true;
}
// Entladen (Ist < 0): unterhalb under -> Lower Hit
if ($real_kWh < $underKWh && $pSdlIstW_raw < 0.0) {
$sdlHitLowerBySDL = true;
}
// EV-Fenster (dynamisch erweitert bei SDL virt leer/voll)
$evUnderKWh = $underKWh;
@@ -353,31 +345,7 @@ public function Update()
$intHash = $cacheHash;
}
if ($cacheHash !== "" && $cacheHash !== $intHash) {
$Esdl_kWh = max(0.0, min($SDL_kWh_ges_cfg, $SDL_start_kWh_cfg));
$dtH = 0.0;
$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 Startpunkt: Esdl_kWh=" . round($Esdl_kWh, 3), 0);
}
// ----------------------------------------------------------
// OPTIONAL: Grenz-Anker, aber jetzt basierend auf IST-Richtung
// (verhindert Drift an echten Grenzen)
// ----------------------------------------------------------
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",
"Grenz-Anker (IST): Esdl_kWh=" . round($Esdl_kWh, 3) .
" upper=" . ($sdlHitUpperBySDL ? "1" : "0") .
" lower=" . ($sdlHitLowerBySDL ? "1" : "0"),
0
);
}
// ==========================================================
// FIX #2 (dein Wunsch): Integration NUR mit aktueller SDL-Leistung
@@ -535,6 +503,10 @@ public function Update()
$this->SetBuffer("BatCacheJSON", json_encode($cache));
$this->SendDebug("Cache", "Battery cache rebuilt (" . count($cache["bats"]) . " bats)", 0);
}
private function GetBufferSafe(string $name): string
{
$v = $this->GetBuffer($name);
@@ -999,42 +971,7 @@ private function WriteByVendorRegistersSingleMode(string $typ, array $cfg, float
// $setInt($varMode, 0);
}
private function ResetSDLTo50Percent(): void
{
$cache = json_decode($this->GetBufferSafe("BatCacheJSON"), true);
if (!is_array($cache) || empty($cache["bats"])) {
return;
}
$sdlKWhTotal = 0.0;
foreach ($cache["bats"] as $bat) {
$sdlKWhTotal += (float)($bat["SDL_kWh_total"] ?? 0.0);
}
if ($sdlKWhTotal <= 0.0) {
return;
}
$startKWh = 0.0;
foreach ($cache["bats"] as $bat) {
$startKWh += (float)($bat["underKWh"] ?? 0.0);
}
$startKWh = max(0.0, min($sdlKWhTotal, $startKWh));
$this->SetBuffer("Int_E_SDL_kWh", (string)$startKWh);
$this->SetBuffer("Int_Init_SDL", "1");
$this->SetBuffer("Int_LastTs", (string)microtime(true));
// wichtig: Hash merken, damit direkt danach kein Resync kommt
$cacheHash = (string)$this->GetBufferSafe("BatCacheHash");
if ($cacheHash !== "") {
$this->SetBuffer("Int_CFG_HASH", $cacheHash);
}
}
private function GetTotalBatteryPowerIstW(): float
{