234 lines
8.4 KiB
PHP
234 lines
8.4 KiB
PHP
<?php
|
|
|
|
class Boiler_2_Stufig_Mit_Fueler extends IPSModule
|
|
{
|
|
public function Create()
|
|
{
|
|
parent::Create();
|
|
|
|
// Boiler spezifische Properties
|
|
$this->RegisterPropertyInteger("BoilerLeistungTeillast", 3000);
|
|
$this->RegisterPropertyInteger("BoilerLeistungVolllast", 6000);
|
|
$this->RegisterPropertyInteger("Boilerfuehler_PT1", 0);
|
|
$this->RegisterPropertyInteger("Kontakt_Teillast", 0);
|
|
$this->RegisterPropertyInteger("Kontakt_Volllast", 0);
|
|
|
|
|
|
// Boiler spezifische Variablen
|
|
$this->RegisterVariableInteger("Mindesttemperatur","Mindesttemperatur","",45);
|
|
$this->RegisterVariableInteger("Maximaltemperatur","Maximaltemperatur","",60);
|
|
$this->RegisterVariableInteger("Legionellentemperatur","Legionellentemperatur","",65);
|
|
$this->RegisterVariableInteger("LegioCounter", "LegioCounter", "", 0);
|
|
$this->RegisterVariableInteger("Boilertemperatur", "Boilertemperatur", "°C", 0);
|
|
|
|
// Variabeln für Kommunkation mit Manager
|
|
$this->RegisterVariableInteger("Sperre_Prio", "Sperre_Prio");
|
|
$this->RegisterVariableInteger("PV_Prio", "PV_Prio");
|
|
$this->RegisterVariableBoolean("Idle", "Idle", "", 0);
|
|
$this->RegisterVariableInteger("Aktuelle_Leistung", "Aktuelle_Leistung", "", 0);
|
|
$this->RegisterVariableFloat("Bezogene_Energie", "Bezogene_Energie", "", 0);
|
|
$this->RegisterVariableString("PowerSteps", "PowerSteps");
|
|
|
|
// Hilfsvariabeln für Idle zustand
|
|
$this->RegisterPropertyInteger("IdleCounterMax", 2);
|
|
$this->RegisterVariableInteger("IdleCounter", "IdleCounter", "", 0);
|
|
$this->SetValue("IdleCounter", 0);
|
|
|
|
// Initialisiere Idle
|
|
$this->SetValue("Idle", true);
|
|
}
|
|
|
|
public function ApplyChanges()
|
|
{
|
|
parent::ApplyChanges();
|
|
}
|
|
|
|
// Aktionen verarbeiten
|
|
public function RequestAction($Ident, $Value)
|
|
{
|
|
switch ($Ident) {
|
|
case "SetAktuelle_Leistung":
|
|
$this->SetAktuelle_Leistung($Value);
|
|
break;
|
|
case "GetCurrentData":
|
|
return $this->GetCurrentData($Value);
|
|
default:
|
|
throw new Exception("Invalid Ident");
|
|
}
|
|
}
|
|
|
|
// 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("BoilerLeistungVolllast")) {
|
|
SetValue($this->ReadPropertyInteger("Kontakt_Volllast"), true);
|
|
SetValue($this->ReadPropertyInteger("Kontakt_Teillast"), false);
|
|
} elseif (
|
|
$power == $this->ReadPropertyInteger("BoilerLeistungTeillast")
|
|
) {
|
|
SetValue($this->ReadPropertyInteger("Kontakt_Volllast"), false);
|
|
SetValue($this->ReadPropertyInteger("Kontakt_Teillast"), true);
|
|
} else {
|
|
SetValue($this->ReadPropertyInteger("Kontakt_Volllast"), false);
|
|
SetValue($this->ReadPropertyInteger("Kontakt_Teillast"), false);
|
|
}
|
|
|
|
// Prüfe auf Änderung der Power im Vergleich zur letzten Einstellung
|
|
$lastPower = GetValue($this->GetIDForIdent("Aktuelle_Leistung"));
|
|
if ($power != $lastPower) {
|
|
$this->SetValue("Idle", false);
|
|
$this->SetValue(
|
|
"IdleCounter",
|
|
$this->ReadPropertyInteger("IdleCounterMax")
|
|
);
|
|
}
|
|
|
|
// Setze die neue Aktuelle_Leistung
|
|
$this->SetValue("Aktuelle_Leistung", $power);
|
|
|
|
// IdleCounter verarbeiten
|
|
$this->ProcessIdleCounter();
|
|
}
|
|
|
|
// Methode zum Abrufen der aktuellen Daten
|
|
public function GetCurrentData(bool $Peak)
|
|
{
|
|
$LegioCounter = $this->GetValue("LegioCounter");
|
|
|
|
|
|
$boilerFuehlerPT1ID = $this->ReadPropertyInteger("Boilerfuehler_PT1");
|
|
|
|
if (IPS_VariableExists($boilerFuehlerPT1ID)) {
|
|
$boilerPT1 = GetValue($boilerFuehlerPT1ID);
|
|
} else {
|
|
$boilerPT1 = 0.0; // Standardwert
|
|
}
|
|
|
|
$boilerTempID = $this->GetIDForIdent("Boilertemperatur");
|
|
if (IPS_VariableExists($boilerTempID)) {
|
|
$boilerTemp = $this->GetValue("Boilertemperatur");
|
|
} else {
|
|
$boilerTemp = 0.0; // Standardwert
|
|
}
|
|
|
|
// PT
|
|
$time_constant = 120; // Zeitkonstante in Sekunden (1 Minute)
|
|
$delta_t = 30; // Zeitdifferenz zwischen den Messungen (30 Sekunden)
|
|
$alpha = $delta_t / ($time_constant + $delta_t);
|
|
$newBoilerTemp = $boilerTemp + $alpha * ($boilerPT1 - $boilerTemp);
|
|
$this->SetValue("Boilertemperatur", $newBoilerTemp);
|
|
|
|
|
|
|
|
|
|
$minTemp = $this->GetValue("Mindesttemperatur");
|
|
$maxTemp = $this->GetValue("Maximaltemperatur");
|
|
$LegioTemp = $this->GetValue("Legionellentemperatur");
|
|
$teilLeistung = $this->ReadPropertyInteger("BoilerLeistungTeillast");
|
|
$vollLeistung = $this->ReadPropertyInteger("BoilerLeistungVolllast");
|
|
|
|
$AktuelleVollast = GetValue(
|
|
$this->ReadPropertyInteger("Kontakt_Volllast")
|
|
);
|
|
$AktuelleTeillast = GetValue(
|
|
$this->ReadPropertyInteger("Kontakt_Teillast")
|
|
);
|
|
|
|
if ($boilerTemp > $LegioTemp) {
|
|
$LegioCounter = 0;
|
|
} else {
|
|
$LegioCounter = $LegioCounter + 1;
|
|
}
|
|
if ($LegioCounter > 69120) {
|
|
$maxTemp = $LegioTemp;
|
|
}
|
|
if ($LegioCounter > 120960 && $this->ist_nachts()) {
|
|
$minTemp = $LegioTemp;
|
|
}
|
|
|
|
$this->SetValue("LegioCounter", $LegioCounter);
|
|
|
|
if ($Peak) {
|
|
if ($boilerTemp < $minTemp) {
|
|
$this->SetValue( "PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]) );
|
|
} elseif (
|
|
$boilerTemp < $minTemp + 5 &&
|
|
($AktuelleVollast || $AktuelleTeillast)
|
|
) {
|
|
$this->SetValue(
|
|
"PowerSteps",
|
|
json_encode([0, $teilLeistung, $vollLeistung])
|
|
);
|
|
} else {
|
|
$this->SetValue("PowerSteps", json_encode([0]));
|
|
}
|
|
} else {
|
|
if ($boilerTemp < $minTemp) {
|
|
$this->SetValue("PowerSteps", json_encode([$vollLeistung]));
|
|
} elseif (
|
|
$boilerTemp < $minTemp + 5 &&
|
|
($AktuelleVollast || $AktuelleTeillast)
|
|
) {
|
|
$this->SetValue("PowerSteps", json_encode([$vollLeistung]));
|
|
} elseif ($boilerTemp < $maxTemp - 5) {
|
|
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
|
|
} elseif ( $boilerTemp < $maxTemp && ($AktuelleVollast || $AktuelleTeillast)
|
|
) {
|
|
$this->SetValue( "PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
|
|
} else {
|
|
$this->SetValue("PowerSteps", json_encode([0]));
|
|
}
|
|
}
|
|
}
|
|
|
|
private function ProcessIdleCounter()
|
|
{
|
|
// IdleCounter auslesen und verarbeiten
|
|
$idleCounter = $this->GetValue("IdleCounter");
|
|
if ($idleCounter > 0) {
|
|
$this->SetValue("Idle", false);
|
|
$this->SetValue("IdleCounter", $idleCounter - 1);
|
|
} else {
|
|
$this->SetValue("Idle", true);
|
|
}
|
|
}
|
|
|
|
private function CheckIdle($power)
|
|
{
|
|
$lastpower = GetValue("Aktuelle_Leistung");
|
|
if ($lastpower != GetValue("Aktuelle_Leistung")) {
|
|
$this->SetValue("Idle", false);
|
|
$this->SetValue(
|
|
"IdleCounter",
|
|
$this->ReadPropertyInteger("IdleCounterMax")
|
|
);
|
|
}
|
|
// IdleCounter auslesen und verarbeiten
|
|
$idleCounter = $this->GetValue("IdleCounter");
|
|
if ($idleCounter > 0) {
|
|
$this->SetValue("Idle", false);
|
|
$this->SetValue("IdleCounter", $idleCounter - 1);
|
|
} else {
|
|
$this->SetValue("Idle", true);
|
|
}
|
|
}
|
|
|
|
private function ist_nachts()
|
|
{
|
|
date_default_timezone_set("Europe/Berlin"); // Setze hier deine Zeitzone
|
|
|
|
$aktuelle_zeit = strtotime(date("H:i")); // Aktuelle Zeit in Stunden und Minuten umwandeln
|
|
$start_nacht = strtotime("22:00"); // Startzeit der Nacht (22 Uhr)
|
|
$ende_nacht = strtotime("07:00"); // Endzeit der Nacht (7 Uhr)
|
|
|
|
if ($aktuelle_zeit >= $start_nacht || $aktuelle_zeit < $ende_nacht) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|