das ganze zum normalen boiler rübergenommen

This commit is contained in:
dh
2025-02-05 16:22:16 +01:00
parent 0f8c3206bd
commit d0c30a13d4
3 changed files with 105 additions and 6 deletions
+65 -2
View File
@@ -14,6 +14,9 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule
$this->RegisterPropertyInteger("Kontakt_Teillast", 0);
$this->RegisterPropertyInteger("Kontakt_Volllast", 0);
$this->RegisterPropertyBoolean("Boilertemperatur_glätten", false);
$this->RegisterPropertyInteger("Boilervolumen", 300);
$this->RegisterPropertyString("Zeitplan", "");
// Boiler spezifische Variablen
@@ -78,6 +81,55 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule
}
}
public function getNextTimeAndTemperature($zeitplan) {
$arr = json_decode($zeitplan, true);
if (empty($arr)) {
return null;
}
$currentTime = new DateTime();
$nextEntry = null;
$minDiff = PHP_INT_MAX;
foreach ($arr as $entry) {
$entryTime = DateTime::createFromFormat('H:i', $entry['Uhrzeit']);
if ($entryTime < $currentTime) {
$entryTime->modify('+1 day');
}
$diff = $currentTime->diff($entryTime)->format('%r%a') * 24 * 60 + $currentTime->diff($entryTime)->format('%r%h') * 60 + $currentTime->diff($entryTime)->format('%r%i');
if ($diff < $minDiff) {
$minDiff = $diff;
$nextEntry = $entry;
}
}
return $nextEntry;
}
public function calculateRemainingTime($nextTime) {
$currentTime = new DateTime();
$nextDateTime = DateTime::createFromFormat('H:i', $nextTime);
if ($nextDateTime < $currentTime) {
$nextDateTime->modify('+1 day');
}
$interval = $currentTime->diff($nextDateTime);
return $interval->h + ($interval->i / 60);
}
public function calculateRequiredHeat($boilervolumen, $tempDiff) {
// Annahme: spezifische Wärmekapazität von Wasser = 4.186 J/g°C
// 1 Liter Wasser = 1000 Gramm
$specificHeatCapacity = 4.186; // J/g°C
$waterMass = $boilervolumen * 1000; // Gramm
return $specificHeatCapacity * $waterMass * $tempDiff; // Joules
}
public function canBoilerReachTemperature($boilervolumen, $boilerTemper, $nextTemp, $remainingTime, $vollleistung) {
$tempDiff = $nextTemp - $boilerTemper;
$requiredHeat = $this->calculateRequiredHeat($boilervolumen, $tempDiff);
$availableHeat = $vollleistung * $remainingTime * 3600; // Leistung in Watt * Zeit in Sekunden
return $availableHeat >= $requiredHeat;
}
// Methode zum Setzen des aktuellen Stromverbrauchs
public function SetAktuelle_Leistung(int $power)
{
@@ -158,8 +210,6 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule
}
$boilerTemp = $this->GetValue("Boilertemperatur");
$minTemp = $this->GetValue("Mindesttemperatur");
$maxTemp = $this->GetValue("Maximaltemperatur");
@@ -167,6 +217,19 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule
$teilLeistung = $this->ReadPropertyInteger("BoilerLeistungTeillast");
$vollLeistung = $this->ReadPropertyInteger("BoilerLeistungVolllast");
$nextEntry = $this->getNextTimeAndTemperature($this->ReadPropertyString("Zeitplan"));
if ($nextEntry !== null) {
$remainingTime = $this->calculateRemainingTime($nextEntry['Uhrzeit']);
$nextTemp = $nextEntry['Solltemperatur'];
if (!$this->canBoilerReachTemperature($this->ReadPropertyInteger("Boilervolumen"), $boilerTemp, $nextTemp, $remainingTime, $vollLeistung)) {
$minTemp = $nextTemp;
}
}
$AktuelleVollast = GetValue(
$this->ReadPropertyInteger("Kontakt_Volllast")
);