diff --git a/Puffer_Speicher/module.php b/Puffer_Speicher/module.php index d734a2d..a820302 100644 --- a/Puffer_Speicher/module.php +++ b/Puffer_Speicher/module.php @@ -120,19 +120,32 @@ class Puffer_Speicher extends IPSModule // Methode zum Setzen des aktuellen Stromverbrauchs public function SetAktuelle_Leistung(int $power) { - // Schalte Kontakt Teillast und Vollast entsprechend der Power-Einstellung - if ($power == $this->ReadPropertyInteger("PufferLeistung")) { - SetValue($this->ReadPropertyInteger("Heizkontakt2_Puffer"), true); - SetValue($this->ReadPropertyInteger("Heizkontakt1_Puffer"), false); - } elseif ( - $power == $this->ReadPropertyInteger("PufferTeilLeistung") - ) { - SetValue($this->ReadPropertyInteger("Heizkontakt2_Puffer"), false); - SetValue($this->ReadPropertyInteger("Heizkontakt1_Puffer"), true); + $json = $this->ReadPropertyString("LeistungsStufen"); + $leistungsStufen = json_decode($json, true); + + + + // Power = 0 → alle Kontakte aus + if ($power == 0) { + foreach ($leistungsStufen as $stufe) { + $kontaktID = $stufe['Schaltkontakt_Stufe'] ?? 0; + if ($kontaktID > 0) { + SetValue($kontaktID, false); + } + } } else { - SetValue($this->ReadPropertyInteger("Heizkontakt2_Puffer"), false); - SetValue($this->ReadPropertyInteger("Heizkontakt1_Puffer"), false); + // Power > 0 → passende Stufe aktivieren, andere bleiben unverändert + foreach ($leistungsStufen as $stufe) { + $leistung = $stufe['Leistung'] ?? 0; + $kontaktID = $stufe['Schaltkontakt_Stufe'] ?? 0; + + if ($leistung == $power && $kontaktID > 0) { + SetValue($kontaktID, true); + break; // nur eine Stufe aktiv + } + } } + // Prüfe auf Änderung der Power im Vergleich zur letzten Einstellung $lastPower = GetValue($this->GetIDForIdent("Aktuelle_Leistung")); @@ -224,7 +237,7 @@ class Puffer_Speicher extends IPSModule $this->SetValue( "PowerSteps", json_encode([0]) ); } else { if ($boilerTemp < $VT && $hyst== true) { - $this->SetValue("PowerSteps", json_encode([0,$pufferTeilLeistung ,$pufferLeistung])); + $this->SetValue("PowerSteps", json_encode($this->leistungArray)); } elseif ($boilerTemp > $VT - 5 && $hyst== false) { $this->SetValue("PowerSteps", json_encode([0])); } else {