Verbrauchermodul 1-Stufig hinzugefügt
This commit is contained in:
+374
-372
@@ -1,512 +1,514 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Batterie extends IPSModule
|
class Batterie extends IPSModule
|
||||||
{
|
{
|
||||||
public function Create()
|
public function Create()
|
||||||
{
|
{
|
||||||
parent::Create();
|
parent::Create();
|
||||||
|
|
||||||
// Batterie spezifische Eigenschaften
|
// Batterie spezifische Eigenschaften
|
||||||
$this->RegisterPropertyInteger("MaxBatterieleistung", 0);
|
$this->RegisterPropertyInteger("MaxBatterieleistung", 0);
|
||||||
$this->RegisterPropertyInteger("Batteriespannung", 50);
|
$this->RegisterPropertyInteger("Batteriespannung", 50);
|
||||||
$this->RegisterPropertyInteger("AufdasNachladen", 0);
|
$this->RegisterPropertyInteger("AufdasNachladen",0);
|
||||||
$this->RegisterPropertyInteger("MinimumEntladen", 0);
|
$this->RegisterPropertyInteger("MinimumEntladen",0);
|
||||||
$this->RegisterPropertyInteger("Batterieladezustand", 0);
|
$this->RegisterPropertyInteger("Batterieladezustand",0);
|
||||||
$this->RegisterPropertyInteger("Batteriemanagement", 1);
|
$this->RegisterPropertyInteger("Batteriemanagement", 1);
|
||||||
$this->RegisterPropertyInteger("Batterietyp", 1);
|
$this->RegisterPropertyInteger("Batterietyp", 1);
|
||||||
$this->RegisterPropertyInteger("MaxNachladen", 0);
|
$this->RegisterPropertyInteger("MaxNachladen",0);
|
||||||
$this->RegisterPropertyInteger("Netzbezug", 0);
|
$this->RegisterPropertyInteger("Netzbezug", 0);
|
||||||
$this->RegisterPropertyInteger("AktuelleBatterieleistung", 0); // Initialisierung mit 0
|
$this->RegisterPropertyInteger("AktuelleBatterieleistung", 0);// Initialisierung mit 0
|
||||||
$this->RegisterPropertyInteger("Interval", 2); // Recheninterval
|
$this->RegisterPropertyInteger("Interval", 2); // Recheninterval
|
||||||
$this->RegisterVariableInteger("Batteriemanagement_Variabel", "Batteriemanagement_Variabel", "", 0);
|
|
||||||
$this->RegisterVariableInteger("Laden_Entladen", "Laden_Entladen", "", 3);
|
|
||||||
$this->RegisterVariableBoolean("Hysterese", "Hysterese", "", false);
|
|
||||||
// Variabeln für Kommunkation mit Manager
|
// Variabeln für Kommunkation mit Manager
|
||||||
$this->RegisterVariableInteger("Aktuelle_Leistung", "Aktuelle zugeteilte Leistung", "", 0);
|
$this->RegisterVariableInteger("Batteriemanagement_Variabel","Batteriemanagement_Variabel", "",0);
|
||||||
$this->RegisterVariableString("PowerSteps", "Leistungsschritte");
|
$this->RegisterVariableInteger("Laden_Entladen","Laden_Entladen", "",3);
|
||||||
|
$this->RegisterVariableInteger("Aktuelle_Leistung", "Aktuelle_Leistung", "", 0);
|
||||||
|
$this->RegisterVariableString("PowerSteps", "PowerSteps");
|
||||||
$this->RegisterVariableBoolean("Idle", "Idle", "", 0);
|
$this->RegisterVariableBoolean("Idle", "Idle", "", 0);
|
||||||
$this->RegisterVariableInteger("Sperre_Prio", "Priorität Peakshaving");
|
$this->RegisterVariableInteger("Sperre_Prio", "Sperre_Prio");
|
||||||
$this->RegisterVariableInteger("PV_Prio", "Priorität PV");
|
$this->RegisterVariableInteger("PV_Prio", "PV_Prio");
|
||||||
$this->RegisterVariableInteger("Power", "Leistung Batterie");
|
$this->RegisterVariableInteger("Power", "Power");
|
||||||
$this->RegisterVariableBoolean("Is_Peak_Shaving", "Peakshavingmodus");
|
$this->RegisterVariableBoolean("Is_Peak_Shaving", "Is_Peak_Shaving");
|
||||||
$this->RegisterVariableInteger("Leistung_Delta", "Leistung Delta", "", 0);
|
$this->RegisterVariableInteger("Leistung_Delta", "Leistung_Delta", "", 0);
|
||||||
$this->RegisterVariableFloat("Bezogene_Energie", "Bezogene Energie", "", 0);
|
|
||||||
|
|
||||||
|
$this->RegisterVariableBoolean("Hysterese", "Hysterese","",false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$this->RegisterVariableFloat("Bezogene_Energie", "Bezogene_Energie", "", 0);
|
||||||
|
|
||||||
// Hilfsvariabeln für Idle zustand
|
// Hilfsvariabeln für Idle zustand
|
||||||
$this->RegisterPropertyInteger("IdleCounterMax", 2);
|
$this->RegisterPropertyInteger("IdleCounterMax", 2);
|
||||||
$this->RegisterVariableInteger("IdleCounter", "IdleCounter", "", 0);
|
$this->RegisterVariableInteger("IdleCounter", "IdleCounter", "", 0);
|
||||||
$this->SetValue("IdleCounter", 0);
|
$this->SetValue("IdleCounter", 0);
|
||||||
|
|
||||||
// Initialisiere Idle
|
// Initialisiere Idle
|
||||||
$this->RegisterTimer("Timer_Do_UserCalc_Battery", $this->ReadPropertyInteger("Interval") * 1000, "IPS_RequestAction(" . $this->InstanceID . ', "Do_UserCalc", "");');
|
$this->SetValue("Idle", true);
|
||||||
|
|
||||||
|
$this->RegisterTimer("Timer_Do_UserCalc_Battery",$this->ReadPropertyInteger("Interval")*1000,"IPS_RequestAction(" .$this->InstanceID .', "Do_UserCalc", "");');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges()
|
public function ApplyChanges()
|
||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
|
|
||||||
$batterieManagement = $this->ReadPropertyInteger("Batteriemanagement");
|
$batterieManagement = $this->ReadPropertyInteger("Batteriemanagement");
|
||||||
$this->SetValue("Batteriemanagement_Variabel", $batterieManagement);
|
$this->SetValue("Batteriemanagement_Variabel", $batterieManagement);
|
||||||
$this->SetTimerInterval("Timer_Do_UserCalc_Battery", $this->ReadPropertyInteger("Interval") * 1000);
|
$this->SetTimerInterval("Timer_Do_UserCalc_Battery",$this->ReadPropertyInteger("Interval")*1000);
|
||||||
|
|
||||||
$batterietyp = $this->ReadPropertyInteger("Batterietyp");
|
$batterietyp = $this->ReadPropertyInteger("Batterietyp");
|
||||||
// Batterietypabhängige Variabeln Initialisieren
|
|
||||||
switch ($batterietyp)
|
switch ($batterietyp) {
|
||||||
{
|
|
||||||
case 0: // Herstellerunabhängig
|
|
||||||
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, false);
|
|
||||||
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, false);
|
|
||||||
$this->MaintainVariable("Entladeleistung", "Entladeleistung", VARIABLETYPE_FLOAT, "", 13, false);
|
|
||||||
break;
|
|
||||||
case 1: // Goodwe
|
case 1: // Goodwe
|
||||||
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, true);
|
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, true);
|
||||||
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, false);
|
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, false);
|
||||||
$this->MaintainVariable("Entladeleistung", "Entladeleistung", VARIABLETYPE_FLOAT, "", 13, false);
|
$this->MaintainVariable("Entladeleistung", "Entladeleistung", VARIABLETYPE_FLOAT, "", 13, false);
|
||||||
break;
|
$this->MaintainVariable("Laden_Entladen", "Laden_Entladen", VARIABLETYPE_INTEGER, "", 12, true);
|
||||||
|
break;
|
||||||
|
|
||||||
case 2: // Solaredge
|
case 2: // Solaredge
|
||||||
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, false);
|
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, false);
|
||||||
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, true);
|
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, true);
|
||||||
$this->MaintainVariable("Entladeleistung", "Entladeleistung", VARIABLETYPE_FLOAT, "", 13, true);
|
$this->MaintainVariable("Entladeleistung", "Entladeleistung", VARIABLETYPE_FLOAT, "", 13, true);
|
||||||
break;
|
$this->MaintainVariable("Laden_Entladen", "Laden_Entladen", VARIABLETYPE_INTEGER, "", 12, true);
|
||||||
|
break;
|
||||||
|
|
||||||
case 3: // SiG Energy
|
case 3: // SiG Energy
|
||||||
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, false);
|
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, false);
|
||||||
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, true);
|
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, true);
|
||||||
$this->MaintainVariable("Entladeleistung", "Entladeleistung", VARIABLETYPE_FLOAT, "", 13, true);
|
$this->MaintainVariable("Entladeleistung", "Entladeleistung", VARIABLETYPE_FLOAT, "", 13, true);
|
||||||
break;
|
$this->MaintainVariable("Laden_Entladen", "Laden_Entladen", VARIABLETYPE_INTEGER, "", 12, true);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Default, werden alle ausgeschaltet
|
// Sicherheit: alles weg
|
||||||
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, false);
|
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, false);
|
||||||
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, false);
|
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, false);
|
||||||
|
$this->MaintainVariable("Laden_Entladen", "Laden_Entladen", VARIABLETYPE_INTEGER, "", 12, false);
|
||||||
$this->MaintainVariable("Entladeleistung", "Entladeleistung", VARIABLETYPE_FLOAT, "", 13, false);
|
$this->MaintainVariable("Entladeleistung", "Entladeleistung", VARIABLETYPE_FLOAT, "", 13, false);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
//
|
|
||||||
$maxBatVar = $this->ReadPropertyInteger("MaxBatterieleistung");
|
|
||||||
$maxNachVar = $this->ReadPropertyInteger("MaxNachladen");
|
|
||||||
if ($maxBatVar > 0)
|
|
||||||
{
|
|
||||||
$this->RegisterMessage($maxBatVar, VM_UPDATE);
|
|
||||||
}
|
|
||||||
if ($maxNachVar > 0)
|
|
||||||
{
|
|
||||||
$this->RegisterMessage($maxNachVar, VM_UPDATE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$maxBatVar = $this->ReadPropertyInteger("MaxBatterieleistung");
|
||||||
|
$maxNachVar = $this->ReadPropertyInteger("MaxNachladen");
|
||||||
|
|
||||||
|
if ($maxBatVar > 0) {
|
||||||
|
$this->RegisterMessage($maxBatVar, VM_UPDATE);
|
||||||
|
}
|
||||||
|
if ($maxNachVar > 0) {
|
||||||
|
$this->RegisterMessage($maxNachVar, VM_UPDATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public function RequestAction($Ident, $Value)
|
|
||||||
{
|
|
||||||
switch ($Ident)
|
|
||||||
{
|
|
||||||
case "SetAktuelle_Leistung":
|
|
||||||
$this->SetValue("Power", (int)$Value);
|
|
||||||
break;
|
|
||||||
case "GetCurrentData":
|
|
||||||
$this->SetValue("Is_Peak_Shaving", (bool)$Value);
|
|
||||||
break;
|
|
||||||
case "Do_UserCalc":
|
|
||||||
$this->SetAktuelle_Leistung($this->GetValue("Power"));
|
|
||||||
$this->GetCurrentData($this->GetValue("Is_Peak_Shaving"));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Nach aufruf bei anpassung Batteriewerte, sofort Getcurrentdata aufrufen.
|
|
||||||
public function MessageSink($TimeStamp, $SenderID, $Message, $Data)
|
public function MessageSink($TimeStamp, $SenderID, $Message, $Data)
|
||||||
{
|
{
|
||||||
if ($Message !== VM_UPDATE)
|
if ($Message !== VM_UPDATE) {
|
||||||
{
|
return;
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
$maxBatVar = $this->ReadPropertyInteger("MaxBatterieleistung");
|
||||||
|
$maxNachVar = $this->ReadPropertyInteger("MaxNachladen");
|
||||||
|
|
||||||
|
if ($SenderID === $maxBatVar || $SenderID === $maxNachVar) {
|
||||||
|
// PowerSteps sofort neu berechnen (mit aktuellem Peak-Status)
|
||||||
|
$this->GetCurrentData($this->GetValue("Is_Peak_Shaving"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private function GeneratePowerSteps()
|
||||||
|
{
|
||||||
|
|
||||||
|
$maxleistung_raw = GetValue($this->ReadPropertyInteger("MaxBatterieleistung"));
|
||||||
|
$nachladen_raw = GetValue($this->ReadPropertyInteger("MaxNachladen"));
|
||||||
|
|
||||||
|
$stepSize = 250; // Grobe Schrittgröße
|
||||||
|
$stepSizeSmall = 50; // Feine Schrittgröße
|
||||||
|
|
||||||
|
// Grenzen auf 50er abrunden (floor)
|
||||||
|
$maxleistung = (int)(floor($maxleistung_raw / $stepSizeSmall) * $stepSizeSmall);
|
||||||
|
$minleistung = (int)(-floor($nachladen_raw / $stepSizeSmall) * $stepSizeSmall); // negativ!
|
||||||
|
|
||||||
|
// Sicherheitscheck: falls Werte komisch sind
|
||||||
|
if ($maxleistung < 0) $maxleistung = 0;
|
||||||
|
if ($minleistung > 0) $minleistung = 0;
|
||||||
|
|
||||||
|
// Grundarray: von min bis max in 250er Schritten
|
||||||
|
$neg = ($minleistung < 0) ? range($minleistung, 0, $stepSize) : [0];
|
||||||
|
$pos = range(0, $maxleistung, $stepSize);
|
||||||
|
|
||||||
|
$array_powersteps = array_values(array_unique(array_merge($neg, $pos)));
|
||||||
|
sort($array_powersteps, SORT_NUMERIC);
|
||||||
|
|
||||||
|
// Zusätzlichen Wert auf 50er abrunden (floor, nicht round!)
|
||||||
|
// (wichtig: floor bei negativen Zahlen geht "weiter runter", daher extra Logik)
|
||||||
|
$closestValue = (int)(floor($additionalValue / $stepSizeSmall) * $stepSizeSmall);
|
||||||
|
|
||||||
|
// Clamp in den Bereich
|
||||||
|
if ($closestValue < $minleistung) $closestValue = $minleistung;
|
||||||
|
if ($closestValue > $maxleistung) $closestValue = $maxleistung;
|
||||||
|
|
||||||
|
// Prüfen ob der Wert im Array existiert (bei 250er Raster oft NICHT)
|
||||||
|
$index = array_search($closestValue, $array_powersteps, true);
|
||||||
|
|
||||||
|
// Wenn nicht vorhanden: an der richtigen Stelle einsortieren
|
||||||
|
if ($index === false) {
|
||||||
|
$index = 0;
|
||||||
|
$count = count($array_powersteps);
|
||||||
|
while ($index < $count && $array_powersteps[$index] < $closestValue) {
|
||||||
|
$index++;
|
||||||
}
|
}
|
||||||
$maxBatVar = $this->ReadPropertyInteger("MaxBatterieleistung");
|
// $index ist jetzt Einfügeposition
|
||||||
$maxNachVar = $this->ReadPropertyInteger("MaxNachladen");
|
}
|
||||||
if ($SenderID === $maxBatVar || $SenderID === $maxNachVar)
|
|
||||||
{
|
// Feine Werte um closestValue herum (±4 * 50)
|
||||||
// PowerSteps sofort neu berechnen (mit aktuellem Peak-Status)
|
$newValues = [];
|
||||||
$this->GetCurrentData($this->GetValue("Is_Peak_Shaving"));
|
for ($i = -4; $i <= 4; $i++) {
|
||||||
|
$v = $closestValue + ($i * $stepSizeSmall);
|
||||||
|
if ($v >= $minleistung && $v <= $maxleistung) {
|
||||||
|
$newValues[] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Aktuelle Leistung setzen lassen, der Manager vorgibt
|
|
||||||
|
// Duplikate vermeiden (falls schon Werte vorhanden sind)
|
||||||
|
$newValues = array_values(array_unique($newValues));
|
||||||
|
|
||||||
|
// Wenn closestValue exakt im Grundarray war: diesen einen ersetzen
|
||||||
|
// sonst: feinwerte einfach an der Einfügestelle einfügen
|
||||||
|
if (array_search($closestValue, $array_powersteps, true) !== false) {
|
||||||
|
$existingIndex = array_search($closestValue, $array_powersteps, true);
|
||||||
|
array_splice($array_powersteps, $existingIndex, 1, $newValues);
|
||||||
|
} else {
|
||||||
|
array_splice($array_powersteps, $index, 0, $newValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Am Ende sortieren + Duplikate killen (sicher ist sicher)
|
||||||
|
$array_powersteps = array_values(array_unique($array_powersteps));
|
||||||
|
sort($array_powersteps, SORT_NUMERIC);
|
||||||
|
|
||||||
|
return $array_powersteps;
|
||||||
|
} // Ende Array Steps
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function RequestAction($Ident, $Value)
|
||||||
|
{
|
||||||
|
switch ($Ident) {
|
||||||
|
|
||||||
|
case "SetAktuelle_Leistung":
|
||||||
|
$this->SetValue("Power", (int)$Value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "GetCurrentData":
|
||||||
|
$this->SetValue("Is_Peak_Shaving", (bool)$Value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case "Do_UserCalc":
|
||||||
|
|
||||||
|
$this->SetAktuelle_Leistung($this->GetValue("Power"));
|
||||||
|
$this->GetCurrentData($this->GetValue("Is_Peak_Shaving"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Exception("Invalid Ident");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function SetAktuelle_Leistung(int $power)
|
public function SetAktuelle_Leistung(int $power)
|
||||||
{
|
{
|
||||||
$batterietyp = $this->ReadPropertyInteger("Batterietyp");
|
|
||||||
$batterieManagement = $this->ReadPropertyInteger("Batteriemanagement");
|
|
||||||
//Fallunterscheidung, soll Enelix überhaupt steuern?
|
|
||||||
// Wechselrichter steuert
|
|
||||||
// Goodwe, Solaredge WR Modus
|
|
||||||
if ($batterieManagement == 1 && ($batterietyp == 1 || $batterietyp == 2))
|
|
||||||
{
|
|
||||||
$this->SetValue("Entladeleistung", 0);
|
|
||||||
$this->SetValue("Ladeleistung", 0);
|
|
||||||
$this->SetValue("Batteriemanagement_Variabel", 1);
|
|
||||||
return;
|
|
||||||
//Sig Energy, Herstellerunabhänig im WR Modus
|
|
||||||
|
|
||||||
}
|
|
||||||
elseif ($batterieManagement == 1 && ($batterietyp == 0 || $batterietyp == 3))
|
$batterietyp = $this->ReadPropertyInteger("Batterietyp");
|
||||||
{
|
$batterieManagement = $this->ReadPropertyInteger("Batteriemanagement");
|
||||||
$this->SetValue("Entladeleistung", 0);
|
|
||||||
$this->SetValue("Ladeleistung", 0);
|
// Goodwe, Solaredge WR Modus
|
||||||
$this->SetValue("Batteriemanagement_Variabel", 0);
|
if ($batterieManagement == 1 && ($batterietyp == 1 || $batterietyp == 2)) {
|
||||||
return;
|
$this->SetValue("Entladeleistung", 0);
|
||||||
// Enelix Steuert
|
$this->SetValue("Ladeleistung", 0);
|
||||||
|
$this->SetValue("Batteriemanagement_Variabel", 1);
|
||||||
|
return;
|
||||||
|
//Sig Energy WR Modus
|
||||||
|
} elseif ($batterieManagement == 1 && $batterietyp == 3) {
|
||||||
|
$this->SetValue("Entladeleistung", 0);
|
||||||
|
$this->SetValue("Ladeleistung", 0);
|
||||||
|
$this->SetValue("Batteriemanagement_Variabel", 0);
|
||||||
|
return;
|
||||||
|
|
||||||
// Sig Energy Symcon Modus
|
// Sig Energy Symcon Modus
|
||||||
|
} elseif ($batterieManagement == 2 && $batterietyp == 3) {
|
||||||
|
$this->SetValue("Batteriemanagement_Variabel", 1);
|
||||||
|
|
||||||
}
|
|
||||||
elseif ($batterieManagement == 2 && ($batterietyp == 0 || $batterietyp == 3))
|
|
||||||
{
|
|
||||||
$this->SetValue("Batteriemanagement_Variabel", 1);
|
|
||||||
//Solaredge Symcon Modus
|
//Solaredge Symcon Modus
|
||||||
|
}elseif ($batterieManagement == 2 && $batterietyp == 2) {
|
||||||
|
$this->SetValue("Batteriemanagement_Variabel", 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$batterietyp = $this->ReadPropertyInteger("Batterietyp");
|
||||||
|
if ($batterietyp == 1) {//Goodwe
|
||||||
|
$this->SetValue("Entladeleistung", 0);
|
||||||
|
$this->SetValue("Ladeleistung", 0);
|
||||||
|
//-----------------------Gooodwee-------------------------------------//
|
||||||
|
if($this->GetValue("Is_Peak_Shaving")==true){
|
||||||
|
|
||||||
|
if ($power >= 0) {
|
||||||
|
$this->SetValue("Goodwe_EntLadeleistung", abs($power));
|
||||||
|
$this->SetValue("Laden_Entladen", 11);
|
||||||
|
} else {
|
||||||
|
$this->SetValue("Goodwe_EntLadeleistung", abs($power));
|
||||||
|
$this->SetValue("Laden_Entladen", 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
if ($power >= 0) {
|
||||||
|
$this->SetValue("Goodwe_EntLadeleistung", abs($power));
|
||||||
|
$this->SetValue("Laden_Entladen", 11);
|
||||||
|
} else {
|
||||||
|
$this->SetValue("Goodwe_EntLadeleistung", abs($power));
|
||||||
|
$this->SetValue("Laden_Entladen", 12);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
elseif ($batterieManagement == 2 && $batterietyp == 2)
|
|
||||||
{
|
}elseif ($batterietyp == 2) {//Solaredge
|
||||||
$this->SetValue("Batteriemanagement_Variabel", 4);
|
|
||||||
}
|
//-----------------------Solaredge-------------------------------------//
|
||||||
// Variabeln entsprechend gewältem Batterietyp setzen
|
$this->SetValue("Goodwe_EntLadeleistung",0);
|
||||||
$batterietyp = $this->ReadPropertyInteger("Batterietyp");
|
if($this->GetValue("Is_Peak_Shaving")==true){
|
||||||
if ($batterietyp == 0)
|
|
||||||
{
|
if ($power >= 0) {
|
||||||
//Herstellerunabhängig
|
$this->SetValue("Ladeleistung", $power);
|
||||||
if ($this->GetValue("Is_Peak_Shaving") == true)
|
$this->SetValue("Entladeleistung", 0);
|
||||||
{
|
$this->SetValue("Laden_Entladen", 3);
|
||||||
if ($power >= 0)
|
} else {
|
||||||
{
|
$this->SetValue("Entladeleistung", abs($power));
|
||||||
$this->SetValue("Ladeleistung", $power);
|
$this->SetValue("Ladeleistung", 0);
|
||||||
$this->SetValue("Entladeleistung", 0);
|
$this->SetValue("Laden_Entladen", 4);
|
||||||
$this->SetValue("Laden_Entladen", 0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->SetValue("Entladeleistung", abs($power));
|
|
||||||
$this->SetValue("Ladeleistung", 0);
|
|
||||||
$this->SetValue("Laden_Entladen", 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
}else{
|
||||||
if ($power >= 0)
|
if ($power >= 0) {
|
||||||
{
|
$this->SetValue("Ladeleistung", $power);
|
||||||
$this->SetValue("Ladeleistung", $power);
|
$this->SetValue("Entladeleistung", 0);
|
||||||
$this->SetValue("Entladeleistung", 0);
|
$this->SetValue("Laden_Entladen", 3);
|
||||||
$this->SetValue("Laden_Entladen", 0);
|
} else {
|
||||||
}
|
$this->SetValue("Entladeleistung", abs($power));
|
||||||
else
|
$this->SetValue("Ladeleistung", 0);
|
||||||
{
|
$this->SetValue("Laden_Entladen", 4);
|
||||||
$this->SetValue("Entladeleistung", abs($power));
|
|
||||||
$this->SetValue("Ladeleistung", 0);
|
|
||||||
$this->SetValue("Laden_Entladen", 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($batterietyp == 1)
|
} elseif ($batterietyp == 3) {//Sig Energy
|
||||||
{
|
|
||||||
//Goodwe
|
//-----------------------Sig Energy-------------------------------------//
|
||||||
$this->SetValue("Entladeleistung", 0);
|
$this->SetValue("Goodwe_EntLadeleistung",0);
|
||||||
$this->SetValue("Ladeleistung", 0);
|
if($this->GetValue("Is_Peak_Shaving")==true){
|
||||||
if ($this->GetValue("Is_Peak_Shaving") == true)
|
|
||||||
{
|
if ($power >= 0) {
|
||||||
if ($power >= 0)
|
$this->SetValue("Ladeleistung", $power/1000);
|
||||||
{
|
$this->SetValue("Entladeleistung", 0);
|
||||||
$this->SetValue("Goodwe_EntLadeleistung", abs($power));
|
$this->SetValue("Laden_Entladen", 3);
|
||||||
$this->SetValue("Laden_Entladen", 11);
|
} else {
|
||||||
}
|
$this->SetValue("Entladeleistung", abs($power)/1000);
|
||||||
else
|
$this->SetValue("Ladeleistung", 0);
|
||||||
{
|
$this->SetValue("Laden_Entladen", 6);
|
||||||
$this->SetValue("Goodwe_EntLadeleistung", abs($power));
|
|
||||||
$this->SetValue("Laden_Entladen", 12);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
}else{
|
||||||
if ($power >= 0)
|
if ($power >= 0) {
|
||||||
{
|
$this->SetValue("Ladeleistung", $power/1000);
|
||||||
$this->SetValue("Goodwe_EntLadeleistung", abs($power));
|
$this->SetValue("Entladeleistung", 0);
|
||||||
$this->SetValue("Laden_Entladen", 11);
|
$this->SetValue("Laden_Entladen", 3);
|
||||||
}
|
} else {
|
||||||
else
|
$this->SetValue("Entladeleistung", abs($power)/1000);
|
||||||
{
|
$this->SetValue("Ladeleistung", 0);
|
||||||
$this->SetValue("Goodwe_EntLadeleistung", abs($power));
|
$this->SetValue("Laden_Entladen", 6);
|
||||||
$this->SetValue("Laden_Entladen", 12);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif ($batterietyp == 2)
|
|
||||||
{
|
|
||||||
//Solaredge
|
|
||||||
if ($this->GetValue("Is_Peak_Shaving") == true)
|
|
||||||
{
|
|
||||||
if ($power >= 0)
|
|
||||||
{
|
|
||||||
$this->SetValue("Ladeleistung", $power);
|
|
||||||
$this->SetValue("Entladeleistung", 0);
|
|
||||||
$this->SetValue("Laden_Entladen", 3);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->SetValue("Entladeleistung", abs($power));
|
|
||||||
$this->SetValue("Ladeleistung", 0);
|
|
||||||
$this->SetValue("Laden_Entladen", 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($power >= 0)
|
|
||||||
{
|
|
||||||
$this->SetValue("Ladeleistung", $power);
|
|
||||||
$this->SetValue("Entladeleistung", 0);
|
|
||||||
$this->SetValue("Laden_Entladen", 3);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->SetValue("Entladeleistung", abs($power));
|
|
||||||
$this->SetValue("Ladeleistung", 0);
|
|
||||||
$this->SetValue("Laden_Entladen", 4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif ($batterietyp == 3)
|
|
||||||
{
|
|
||||||
//Sig Energy
|
|
||||||
if ($this->GetValue("Is_Peak_Shaving") == true)
|
|
||||||
{
|
|
||||||
if ($power >= 0)
|
|
||||||
{
|
|
||||||
$this->SetValue("Ladeleistung", $power / 1000);
|
|
||||||
$this->SetValue("Entladeleistung", 0);
|
|
||||||
$this->SetValue("Laden_Entladen", 3);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->SetValue("Entladeleistung", abs($power) / 1000);
|
|
||||||
$this->SetValue("Ladeleistung", 0);
|
|
||||||
$this->SetValue("Laden_Entladen", 6);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($power >= 0)
|
|
||||||
{
|
|
||||||
$this->SetValue("Ladeleistung", $power / 1000);
|
|
||||||
$this->SetValue("Entladeleistung", 0);
|
|
||||||
$this->SetValue("Laden_Entladen", 3);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->SetValue("Entladeleistung", abs($power) / 1000);
|
|
||||||
$this->SetValue("Ladeleistung", 0);
|
|
||||||
$this->SetValue("Laden_Entladen", 6);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Prüfe auf Änderung der Leistung im Vergleich zur letzten Einstellung
|
// Prüfe auf Änderung der Leistung im Vergleich zur letzten Einstellung
|
||||||
$lastPower = GetValue($this->GetIDForIdent("Aktuelle_Leistung"));
|
$lastPower = GetValue($this->GetIDForIdent("Aktuelle_Leistung"));
|
||||||
if ($power != $lastPower)
|
if ($power != $lastPower) {
|
||||||
{
|
|
||||||
$this->SetValue("Idle", false);
|
$this->SetValue("Idle", false);
|
||||||
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
|
$this->SetValue(
|
||||||
|
"IdleCounter",
|
||||||
|
$this->ReadPropertyInteger("IdleCounterMax")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setze die neue aktuelle Leistung
|
// Setze die neue aktuelle Leistung
|
||||||
$this->SetValue("Aktuelle_Leistung", $power);
|
$this->SetValue("Aktuelle_Leistung", $power);
|
||||||
$this->SetValue("Bezogene_Energie", $this->GetValue("Bezogene_Energie") + $this->GetValue("Aktuelle_Leistung") * ($this->ReadPropertyInteger("Interval") / 3600));
|
$this->SetValue("Bezogene_Energie", ($this->GetValue("Bezogene_Energie") + ($this->GetValue("Aktuelle_Leistung")*($this->ReadPropertyInteger("Interval")/3600))));
|
||||||
|
|
||||||
// IdleCounter verarbeiten
|
// IdleCounter verarbeiten
|
||||||
$this->ProcessIdleCounter();
|
$this->ProcessIdleCounter();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function GetCurrentData(bool $Peak)
|
public function GetCurrentData(bool $Peak)
|
||||||
{
|
{
|
||||||
// Aktuelle Daten ausarbeiten und Berechnen
|
IPS_LogMessage("Batterie", "Currentdata");
|
||||||
|
|
||||||
$array_powersteps = $this->GeneratePowerSteps();
|
$array_powersteps = $this->GeneratePowerSteps();
|
||||||
$aufdasnachladen = $this->ReadPropertyInteger("AufdasNachladen");
|
$aufdasnachladen = $this->ReadPropertyInteger("AufdasNachladen");
|
||||||
$minimumentladen = $this->ReadPropertyInteger("MinimumEntladen");
|
$minimumentladen = $this->ReadPropertyInteger("MinimumEntladen");
|
||||||
$maxleistung = GetValue($this->ReadPropertyInteger("MaxBatterieleistung")); //Ladeleistung
|
$maxleistung = GetValue($this->ReadPropertyInteger("MaxBatterieleistung"));//Ladeleistung
|
||||||
$maxentladeleistung = GetValue($this->ReadPropertyInteger("MaxNachladen")); //Entladeleistung
|
$maxentladeleistung = GetValue($this->ReadPropertyInteger("MaxNachladen"));//Entladeleistung
|
||||||
$dummy_array = [];
|
$dummy_array = [];
|
||||||
$batterieladezustand = GetValue($this->ReadPropertyInteger("Batterieladezustand"));
|
$batterieladezustand = GetValue($this->ReadPropertyInteger("Batterieladezustand"));
|
||||||
$filtered_powersteps_entladen = [];
|
$filtered_powersteps_entladen = [];
|
||||||
if ($this->ReadPropertyInteger("Batteriemanagement") == 1)
|
if ($this->ReadPropertyInteger("Batteriemanagement") == 1) {
|
||||||
{
|
|
||||||
$dummy_array[] = 0;
|
$dummy_array[] = 0;
|
||||||
return $this->SetValue("PowerSteps", json_encode($dummy_array));
|
return $this->SetValue("PowerSteps", json_encode($dummy_array));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$netzbezug = GetValue($this->ReadPropertyInteger("Netzbezug"));
|
$netzbezug = GetValue($this->ReadPropertyInteger("Netzbezug"));
|
||||||
$bat_leistung = GetValue($this->ReadPropertyInteger("AktuelleBatterieleistung"));
|
$bat_leistung = GetValue($this->ReadPropertyInteger("AktuelleBatterieleistung"));
|
||||||
if ($Peak && $netzbezug > 0)
|
|
||||||
{
|
/*
|
||||||
$netzbezug = - min($netzbezug, $maxentladeleistung) + $bat_leistung;
|
if (abs($netzbezug) > $maxentladeleistung) {
|
||||||
|
//$netzbezug = $maxentladeleistung * (-1);
|
||||||
|
$netzbezug = $netzbezug * (-1);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
if ($Peak && $netzbezug > 0) {
|
||||||
|
$netzbezug = -min($netzbezug, $maxentladeleistung) + $bat_leistung;
|
||||||
}
|
}
|
||||||
if ($batterieladezustand > 5 + $aufdasnachladen)
|
|
||||||
{
|
if($batterieladezustand>(5+$aufdasnachladen)){
|
||||||
|
|
||||||
$this->SetValue("Hysterese", false);
|
$this->SetValue("Hysterese", false);
|
||||||
}
|
|
||||||
elseif ($batterieladezustand <= $aufdasnachladen)
|
}elseif($batterieladezustand<=$aufdasnachladen){
|
||||||
{
|
|
||||||
$this->SetValue("Hysterese", true);
|
$this->SetValue("Hysterese", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$hyst = $this->GetValue("Hysterese");
|
$hyst = $this->GetValue("Hysterese");
|
||||||
if ($Peak)
|
|
||||||
{
|
if($Peak){
|
||||||
if ($batterieladezustand > $aufdasnachladen && $hyst == false)
|
IPS_LogMessage("Batterie", "Im if teil");
|
||||||
{
|
|
||||||
|
if($batterieladezustand>$aufdasnachladen && $hyst==false){
|
||||||
|
|
||||||
$dummy_array[] = $netzbezug;
|
$dummy_array[] = $netzbezug;
|
||||||
$this->SetValue("PowerSteps", json_encode($dummy_array));
|
$this->SetValue("PowerSteps", json_encode($dummy_array));
|
||||||
}
|
|
||||||
elseif ($batterieladezustand > $aufdasnachladen && $hyst == true)
|
}elseif($batterieladezustand>$aufdasnachladen && $hyst==true){
|
||||||
{
|
|
||||||
$filtered_powersteps = array_filter($array_powersteps, function ($value)
|
|
||||||
{
|
$filtered_powersteps = array_filter($array_powersteps, function ($value) {
|
||||||
return $value <= 0;
|
return $value <= 0;
|
||||||
});
|
});
|
||||||
$filtered_powersteps_laden = array_values($filtered_powersteps);
|
$filtered_powersteps_laden = array_values($filtered_powersteps);
|
||||||
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
|
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
|
||||||
|
|
||||||
|
}elseif($batterieladezustand>$minimumentladen){
|
||||||
|
|
||||||
|
$this->SetValue("PowerSteps", json_encode($array_powersteps));
|
||||||
}
|
}
|
||||||
elseif ($batterieladezustand > $minimumentladen)
|
else{
|
||||||
{
|
|
||||||
$this->SetValue("PowerSteps", json_encode($array_powersteps));
|
$filtered_powersteps = array_filter($array_powersteps, function ($value) {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$filtered_powersteps = array_filter($array_powersteps, function ($value)
|
|
||||||
{
|
|
||||||
return $value >= 0;
|
return $value >= 0;
|
||||||
});
|
});
|
||||||
$filtered_powersteps_laden = array_values($filtered_powersteps);
|
$filtered_powersteps_laden = array_values($filtered_powersteps);
|
||||||
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
|
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
}else{
|
||||||
{
|
IPS_LogMessage("Batterie", "Im else teil");
|
||||||
if ($batterieladezustand > 99)
|
|
||||||
{
|
|
||||||
$filtered_powersteps = array_filter($array_powersteps, function ($value)
|
if($batterieladezustand>99){
|
||||||
{
|
IPS_LogMessage("Batterie", "im 1");
|
||||||
|
|
||||||
|
$filtered_powersteps = array_filter($array_powersteps, function ($value) {
|
||||||
return $value <= 0;
|
return $value <= 0;
|
||||||
});
|
});
|
||||||
$filtered_powersteps_laden = array_values($filtered_powersteps);
|
$filtered_powersteps_laden = array_values($filtered_powersteps);
|
||||||
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
|
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
|
||||||
}
|
|
||||||
elseif ($batterieladezustand > $aufdasnachladen && $hyst == false)
|
}elseif($batterieladezustand>$aufdasnachladen && $hyst==false){
|
||||||
{
|
|
||||||
$this->SetValue("PowerSteps", json_encode($array_powersteps));
|
$this->SetValue("PowerSteps", json_encode($array_powersteps));
|
||||||
}
|
IPS_LogMessage("Batterie", "im 2");
|
||||||
elseif ($batterieladezustand >= $aufdasnachladen && $hyst == true)
|
|
||||||
{
|
|
||||||
$filtered_powersteps = array_filter($array_powersteps, function ($value)
|
}elseif($batterieladezustand>=$aufdasnachladen && $hyst==true){
|
||||||
{
|
|
||||||
|
$filtered_powersteps = array_filter($array_powersteps, function ($value) {
|
||||||
return $value >= 0;
|
return $value >= 0;
|
||||||
});
|
});
|
||||||
$filtered_powersteps_laden = array_values($filtered_powersteps);
|
$filtered_powersteps_laden = array_values($filtered_powersteps);
|
||||||
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
|
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
|
||||||
}
|
|
||||||
elseif ($batterieladezustand < $aufdasnachladen)
|
|
||||||
{
|
}elseif($batterieladezustand<$aufdasnachladen){
|
||||||
|
|
||||||
//$dummy_array[] = GetValue($this->ReadPropertyInteger("MaxNachladen"));
|
//$dummy_array[] = GetValue($this->ReadPropertyInteger("MaxNachladen"));
|
||||||
$dummy_array[] = GetValue($this->ReadPropertyInteger("MaxBatterieleistung"));
|
$dummy_array[] = GetValue($this->ReadPropertyInteger("MaxBatterieleistung"));
|
||||||
$this->SetValue("PowerSteps", json_encode($dummy_array));
|
$this->SetValue("PowerSteps", json_encode($dummy_array));
|
||||||
|
IPS_LogMessage("Batterie", "im 3");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Ab hier Hilfsfunktionen
|
|
||||||
private function GeneratePowerSteps()
|
|
||||||
{
|
|
||||||
// Hilfsfunktion um die Möglichen Powersteps zu generieren
|
|
||||||
$maxleistung_raw = GetValue($this->ReadPropertyInteger("MaxBatterieleistung"));
|
|
||||||
$nachladen_raw = GetValue($this->ReadPropertyInteger("MaxNachladen"));
|
|
||||||
$stepSize = 250; // Grobe Schrittgröße
|
|
||||||
$stepSizeSmall = 50; // Feine Schrittgröße
|
|
||||||
// Grenzen auf 50er abrunden (floor)
|
|
||||||
$maxleistung = (int)(floor($maxleistung_raw / $stepSizeSmall) * $stepSizeSmall);
|
|
||||||
$minleistung = (int)(-floor($nachladen_raw / $stepSizeSmall) * $stepSizeSmall); // negativ!
|
|
||||||
// Sicherheitscheck: falls Werte komisch sind
|
|
||||||
if ($maxleistung < 0)
|
|
||||||
{
|
|
||||||
$maxleistung = 0;
|
|
||||||
}
|
|
||||||
if ($minleistung > 0)
|
|
||||||
{
|
|
||||||
$minleistung = 0;
|
|
||||||
}
|
|
||||||
// Grundarray: von min bis max in 250er Schritten
|
|
||||||
$neg = $minleistung < 0 ? range($minleistung, 0, $stepSize) : [0];
|
|
||||||
$pos = range(0, $maxleistung, $stepSize);
|
|
||||||
$array_powersteps = array_values(array_unique(array_merge($neg, $pos)));
|
|
||||||
sort($array_powersteps, SORT_NUMERIC);
|
|
||||||
// Zusätzlichen Wert auf 50er abrunden
|
|
||||||
$closestValue = (int)(floor($additionalValue / $stepSizeSmall) * $stepSizeSmall);
|
|
||||||
// Clamp in den Bereich
|
|
||||||
if ($closestValue < $minleistung)
|
|
||||||
{
|
|
||||||
$closestValue = $minleistung;
|
|
||||||
}
|
|
||||||
if ($closestValue > $maxleistung)
|
|
||||||
{
|
|
||||||
$closestValue = $maxleistung;
|
|
||||||
}
|
|
||||||
// Prüfen ob der Wert im Array existiert (bei 250er Raster oft NICHT)
|
|
||||||
$index = array_search($closestValue, $array_powersteps, true);
|
|
||||||
// Wenn nicht vorhanden: an der richtigen Stelle einsortieren
|
|
||||||
if ($index === false)
|
|
||||||
{
|
|
||||||
$index = 0;
|
|
||||||
$count = count($array_powersteps);
|
|
||||||
while ($index < $count && $array_powersteps[$index] < $closestValue)
|
|
||||||
{
|
|
||||||
$index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Feine Werte um closestValue herum (±4 * 50)
|
|
||||||
$newValues = [];
|
|
||||||
for ($i = - 4;$i <= 4;$i++)
|
|
||||||
{
|
|
||||||
$v = $closestValue + $i * $stepSizeSmall;
|
|
||||||
if ($v >= $minleistung && $v <= $maxleistung)
|
|
||||||
{
|
|
||||||
$newValues[] = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Duplikate vermeiden (falls schon Werte vorhanden sind)
|
|
||||||
$newValues = array_values(array_unique($newValues));
|
|
||||||
// Wenn closestValue exakt im Grundarray war: diesen einen ersetzen
|
|
||||||
// sonst: feinwerte einfach an der Einfügestelle einfügen
|
|
||||||
if (array_search($closestValue, $array_powersteps, true) !== false)
|
|
||||||
{
|
|
||||||
$existingIndex = array_search($closestValue, $array_powersteps, true);
|
|
||||||
array_splice($array_powersteps, $existingIndex, 1, $newValues);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
array_splice($array_powersteps, $index, 0, $newValues);
|
|
||||||
}
|
|
||||||
// Am Ende sortieren
|
|
||||||
$array_powersteps = array_values(array_unique($array_powersteps));
|
|
||||||
sort($array_powersteps, SORT_NUMERIC);
|
|
||||||
return $array_powersteps;
|
|
||||||
}
|
|
||||||
private function CheckIdle($power)
|
private function CheckIdle($power)
|
||||||
{
|
{
|
||||||
// Hilfsfunktion zum Prüfen ob die Batterie schon wieder Leistung verändern kann
|
|
||||||
$lastpower = GetValue("Aktuelle_Leistung");
|
$lastpower = GetValue("Aktuelle_Leistung");
|
||||||
if ($lastpower != GetValue("Aktuelle_Leistung"))
|
if ($lastpower != GetValue("Aktuelle_Leistung")) {
|
||||||
{
|
|
||||||
$this->SetValue("Idle", false);
|
$this->SetValue("Idle", false);
|
||||||
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
|
$this->SetValue(
|
||||||
|
"IdleCounter",
|
||||||
|
$this->ReadPropertyInteger("IdleCounterMax")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// IdleCounter auslesen und verarbeiten
|
// IdleCounter auslesen und verarbeiten
|
||||||
$idleCounter = $this->GetValue("IdleCounter");
|
$idleCounter = $this->GetValue("IdleCounter");
|
||||||
if ($idleCounter > 0)
|
if ($idleCounter > 0) {
|
||||||
{
|
|
||||||
$this->SetValue("Idle", false);
|
$this->SetValue("Idle", false);
|
||||||
$this->SetValue("IdleCounter", $idleCounter - 1);
|
$this->SetValue("IdleCounter", $idleCounter - 1);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->SetValue("Idle", true);
|
$this->SetValue("Idle", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function ProcessIdleCounter()
|
private function ProcessIdleCounter()
|
||||||
{
|
{
|
||||||
// IdleCounter auslesen und verarbeiten
|
// IdleCounter auslesen und verarbeiten
|
||||||
$idleCounter = $this->GetValue("IdleCounter");
|
$idleCounter = $this->GetValue("IdleCounter");
|
||||||
if ($idleCounter > 0)
|
if ($idleCounter > 0) {
|
||||||
{
|
|
||||||
$this->SetValue("Idle", false);
|
$this->SetValue("Idle", false);
|
||||||
$this->SetValue("IdleCounter", $idleCounter - 1);
|
$this->SetValue("IdleCounter", $idleCounter - 1);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->SetValue("Idle", true);
|
$this->SetValue("Idle", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
+4
-4
@@ -183,9 +183,9 @@ class Manager extends IPSModule
|
|||||||
// Wenn die Prio geleich ist, sortiere danach welcher verbraucher bisher am wenigsten Energie bekommen hat.
|
// Wenn die Prio geleich ist, sortiere danach welcher verbraucher bisher am wenigsten Energie bekommen hat.
|
||||||
if ($a[$primaryKey] == $b[$primaryKey])
|
if ($a[$primaryKey] == $b[$primaryKey])
|
||||||
{
|
{
|
||||||
return round($a["Bezogene_Energie"] / 2000) <= > round($b["Bezogene_Energie"] / 2000);
|
return round($a["Bezogene_Energie"] / 2000) <= round($b["Bezogene_Energie"] / 2000);
|
||||||
}
|
}
|
||||||
return $a[$primaryKey] <= > $b[$primaryKey];
|
return $a[$primaryKey] <= $b[$primaryKey];
|
||||||
});
|
});
|
||||||
// Primärschlüssel für die Priorität basierend auf dem Parameter auswählen (für sortierung in gruppen anschliessend)
|
// Primärschlüssel für die Priorität basierend auf dem Parameter auswählen (für sortierung in gruppen anschliessend)
|
||||||
$priorityKey = $Is_Peak_Shaving ? "Sperre_Prio" : "PV_Prio";
|
$priorityKey = $Is_Peak_Shaving ? "Sperre_Prio" : "PV_Prio";
|
||||||
@@ -299,7 +299,7 @@ class Manager extends IPSModule
|
|||||||
// Sortiere die Schritte nach Größe
|
// Sortiere die Schritte nach Größe
|
||||||
usort($allSteps, function ($a, $b)
|
usort($allSteps, function ($a, $b)
|
||||||
{
|
{
|
||||||
return $a["step"] <= > $b["step"];
|
return $a["step"] <= $b["step"];
|
||||||
});
|
});
|
||||||
//if remaining power >0
|
//if remaining power >0
|
||||||
// Iteriere durch alle Schritte
|
// Iteriere durch alle Schritte
|
||||||
@@ -361,7 +361,7 @@ class Manager extends IPSModule
|
|||||||
// Sortiere die Schritte nach Größe
|
// Sortiere die Schritte nach Größe
|
||||||
usort($allSteps, function ($a, $b)
|
usort($allSteps, function ($a, $b)
|
||||||
{
|
{
|
||||||
return $a["step"] <= > $b["step"];
|
return $a["step"] <= $b["step"];
|
||||||
});
|
});
|
||||||
$remainingPower = $remainingPower * -1;
|
$remainingPower = $remainingPower * -1;
|
||||||
// Iteriere durch alle Schritte
|
// Iteriere durch alle Schritte
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
# Enelix-Verbrauchermodul 1-Stufig
|
||||||
|
|
||||||
|
Dieses Modul integriert einfache, nicht-modulierende Verbraucher (Ein/Aus) wie klassische Heizstäbe, Wärmepumpen oder einfache Boiler in das Belevo Energiemanagement-System (Enelix). Es schaltet den Verbraucher basierend auf PV-Überschuss, Peak-Shaving-Vorgaben und einer garantierten Mindestlaufzeit während der Nachtstunden.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Inhaltsverzeichnis
|
||||||
|
|
||||||
|
1. [Funktionsumfang](#1-funktionsumfang)
|
||||||
|
2. [Voraussetzungen](#2-voraussetzungen)
|
||||||
|
3. [Installation](#3-installation)
|
||||||
|
4. [Instanz anlegen & Konfiguration](#4-instanz-anlegen--konfiguration)
|
||||||
|
5. [Statusvariablen](#5-statusvariablen)
|
||||||
|
6. [WebFront / Bedienung](#6-webfront--bedienung)
|
||||||
|
7. [Mapping auf Code-Komponenten](#7-mapping-auf-code-komponenten)
|
||||||
|
8. [Zukünftige Erweiterungen](#8-zukünftige-erweiterungen)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Funktionsumfang
|
||||||
|
|
||||||
|
- **1-Stufige Steuerung:** Bietet dem Enelix-Manager exakt zwei Zustände an: `0` (Aus) oder die definierte `Leistung` (Ein).
|
||||||
|
- **Direkte Aktor-Steuerung:** Schaltet eine hinterlegte IP-Symcon Variable (`Schaltkontakt1`) direkt auf `true` oder `false`.
|
||||||
|
- **Nacht-Mindestlaufzeit:** Sichert ab, dass der Verbraucher nachts (22:00 bis 07:00 Uhr) eine definierte Mindestlaufzeit (`Mindesttlaufzeit`) erreicht. Wird diese nicht über PV-Überschuss am Tag erreicht, erzwingt das Modul die Einschaltung (Netzbezug).
|
||||||
|
- **Taktschutz (Verzögerungslogik):** Die Einstellung `Zeit_Zwischen_Zustandswechseln` blockiert für x Minuten nach einem Schaltvorgang weitere Leistungsänderungen, um das Relais oder den angeschlossenen Verbraucher vor schnellem Takten zu schützen.
|
||||||
|
- **Manager-Sperrlogik (Idle):** Ein Zähler (`IdleCounterMax`) verzögert die Rückmeldung an den Manager, bis der Verbraucher seinen Status stabil gewechselt hat.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Voraussetzungen
|
||||||
|
|
||||||
|
- IP-Symcon **≥ 8.0**
|
||||||
|
- Modul-URL: `https://git.belevo.ch/dh/enelix.git`
|
||||||
|
- Vorhandener und eingerichteter Enelix Manager.
|
||||||
|
- Physischer Schaltaktor (z.B. Shelly, KNX Schaltaktor) zur Steuerung des Verbrauchers.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Installation
|
||||||
|
|
||||||
|
1. In IP-Symcon **Module Control** öffnen.
|
||||||
|
2. **Hinzufügen → Git-Repository**.
|
||||||
|
3. URL eingeben und **Installieren**.
|
||||||
|
4. IP-Symcon neu starten.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Instanz anlegen & Konfiguration
|
||||||
|
|
||||||
|
### 4.1 Instanz anlegen
|
||||||
|
|
||||||
|
- Rechtsklick **Instanzen** → **Instanz hinzufügen**
|
||||||
|
- Filter: **Belevo**
|
||||||
|
- Auswahl: **Verbraucher 1-Stufig**
|
||||||
|
|
||||||
|
### 4.2 Properties
|
||||||
|
|
||||||
|
| Name | Typ | Beschreibung |
|
||||||
|
|---|---|---|
|
||||||
|
| **BoilerLeistung** | NumberSpinner | Leistungsaufnahme des Verbrauchers unter Volllast in Watt (z.B. 6000). |
|
||||||
|
| **Mindesttlaufzeit** | NumberSpinner | Garantierte Mindestlaufzeit in Stunden, die nachts erreicht werden muss. |
|
||||||
|
| **Zeit_Zwischen_Zustandswechseln**| NumberSpinner | Taktschutz: Sperrzeit in Minuten zwischen zwei Schaltvorgängen. |
|
||||||
|
| **Schaltkontakt1** | SelectVariable | Objekt-ID der Variable, die den physischen Aktor schaltet (Boolean). |
|
||||||
|
| **Interval** | NumberSpinner | Berechnungsintervall in Sekunden (Standard: 5). |
|
||||||
|
| **IdleCounterMax** | NumberSpinner | Anzahl Intervall-Zyklen zwischen zwei Schaltvorgängen für die Manager-Freigabe. |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Statusvariablen
|
||||||
|
|
||||||
|
| Ident | Typ | Beschreibung |
|
||||||
|
|---|---|---|
|
||||||
|
| **IstNacht** | Boolean | Zeigt an, ob aktuell der Nacht-Modus (22:00 - 07:00) aktiv ist. |
|
||||||
|
| **DailyOnTime** | Integer | Zähler für die Laufzeit im aktuellen Zyklus (wird zu Beginn der Nacht genullt). |
|
||||||
|
| **IsTimerActive** | Boolean | Status des Taktschutzes (`true` = Statuswechsel aktuell blockiert). |
|
||||||
|
| **Aktuelle_Leistung** | Integer | Die aktuell vom Manager zugewiesene Soll-Leistung (0 oder `BoilerLeistung`). |
|
||||||
|
| **PowerSteps** | String | JSON-Array der dem Manager angebotenen Schritte (z.B. `[0, 6000]`). |
|
||||||
|
| **Idle** | Boolean | Status der Manager-Sperrzeit (`true` = bereit für neue Werte, `false` = gesperrt). |
|
||||||
|
| **Sperre_Prio** | Integer | Priorität für die Leistungszuteilung im Peak-Shaving-Modus. |
|
||||||
|
| **PV_Prio** | Integer | Priorität für die Leistungszuteilung im Solarlade-Modus. |
|
||||||
|
| **Bezogene_Energie** | Float | Rechnerisch aufsummierte Energie (Leistung × Zeit). |
|
||||||
|
| **Is_Peak_Shaving** | Boolean | Vom Manager übermittelter aktueller Betriebsmodus. |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. WebFront / Bedienung
|
||||||
|
|
||||||
|
Im WebFront dient das Modul hauptsächlich der Visualisierung und der Prioritäten-Steuerung:
|
||||||
|
- Überwachung, ob der Nacht-Modus (`IstNacht`) aktiv ist und wie lange der Verbraucher bereits lief (`DailyOnTime`).
|
||||||
|
- Kontrolle der aktuell zugewiesenen Leistung (`Aktuelle_Leistung`) und des Taktschutzes (`IsTimerActive`).
|
||||||
|
- Anpassung der Steuerungsprioritäten (`PV_Prio`, `Sperre_Prio`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. Mapping auf Code-Komponenten
|
||||||
|
|
||||||
|
| Komponente | Funktion im Code (`module.php`) |
|
||||||
|
|---|---|
|
||||||
|
| **Timer-Registrierung** | `ApplyChanges()` setzt den Haupt-Berechnungstimer `Timer_Do_UserCalc_Verb`. |
|
||||||
|
| **Nacht-Erkennung** | `ist_nachts()` prüft hardcodiert die Zeitspanne 22:00 bis 07:00 Uhr. |
|
||||||
|
| **Laufzeit-Überwachung**| `GetCurrentData()` nullt `DailyOnTime` beim Wechsel von Tag zu Nacht. Die Laufzeit wird in `SetAktuelle_Leistung()` pro Intervall hochgezählt. |
|
||||||
|
| **Betriebslogik** | `GetCurrentData($Peak)` baut die `PowerSteps`. Ist es Nacht und die Mindestlaufzeit nicht erreicht, wird `[BoilerLeistung]` erzwungen. Am Tag oder nach Erreichen der Zeit wird `[0, BoilerLeistung]` für Überschussladen angeboten. |
|
||||||
|
| **Taktschutz** | `SetTimerOn()` und `ResetPowerSteps()` blockieren die Modifikation der `PowerSteps` für die Dauer von `Zeit_Zwischen_Zustandswechseln`. |
|
||||||
|
| **Aktorsteuerung** | `SetAktuelle_Leistung($power)` vergleicht die geforderte Leistung mit `BoilerLeistung` und setzt die Variable in `Schaltkontakt1` entsprechend auf `true` oder `false`. |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. Zukünftige Erweiterungen
|
||||||
|
|
||||||
|
- **Dynamische Nachtzeiten/Stromtarife:** Konfigurierbare Start- und Endzeiten für den Nacht- bzw. Niedertarifzeitraum über die Modul-Properties (statt hardcodiert 22:00 bis 07:00 Uhr).
|
||||||
|
- **Externer Hardware-Status:** Rücklesefunktion des Aktors, um manuelle Schaltungen am Relais in der `DailyOnTime` und Energieberechnung zu berücksichtigen.
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"type": "Label",
|
||||||
|
"caption": "Einstellungen für einstufigen Verbruacher Ein-Aus"
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "IdleCounterMax",
|
||||||
|
"caption": "Zyklen zwischen zwei Leistungsänderungen (Multipliziert sich mit Interval)",
|
||||||
|
"suffix": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "Interval",
|
||||||
|
"caption": "Intervall Neuberechnung der Werte Erst für spätere Versionen, aktuell auf 5 lassen!",
|
||||||
|
"suffix": "Sekunden"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "Mindesttlaufzeit",
|
||||||
|
"caption": "Mindestlaufzeit des Verbruachers wärend eines Tages",
|
||||||
|
"suffix": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "Zeit_Zwischen_Zustandswechseln",
|
||||||
|
"caption": "Mindestlaufzeit des Verbrauchers bei Lastschaltung",
|
||||||
|
"suffix": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "BoilerLeistung",
|
||||||
|
"caption": "Leistung des Verbrauchers",
|
||||||
|
"suffix": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SelectVariable",
|
||||||
|
"name": "Schaltkontakt1",
|
||||||
|
"caption": "Zu schaltenden Kontakt",
|
||||||
|
"test": true
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"id": "{5A156BE6-30FE-55AC-A832-7F80BF043C8C}",
|
||||||
|
"name": "Verbraucher_1_Stufig",
|
||||||
|
"type": 3,
|
||||||
|
"vendor": "Belevo AG",
|
||||||
|
"aliases": ["Verbraucher 1-Stufig"],
|
||||||
|
"parentRequirements": [],
|
||||||
|
"childRequirements": [],
|
||||||
|
"implemented": [],
|
||||||
|
"prefix": "GEF",
|
||||||
|
"url": ""
|
||||||
|
}
|
||||||
@@ -0,0 +1,231 @@
|
|||||||
|
<?php
|
||||||
|
class Verbraucher_1_Stufig extends IPSModule
|
||||||
|
{
|
||||||
|
private $timerID;
|
||||||
|
|
||||||
|
public function Create()
|
||||||
|
{
|
||||||
|
parent::Create();
|
||||||
|
|
||||||
|
// Verbraucherspezifische Properties
|
||||||
|
$this->RegisterPropertyInteger("BoilerLeistung", 6000); // Standardwert für Volllast
|
||||||
|
$this->RegisterPropertyInteger("Mindesttlaufzeit", 4); // Standardwert für Volllast
|
||||||
|
$this->RegisterPropertyInteger("Zeit_Zwischen_Zustandswechseln", 1);
|
||||||
|
$this->RegisterPropertyInteger("Schaltkontakt1", 0);
|
||||||
|
$this->RegisterPropertyInteger("Interval", 5); // Recheninterval
|
||||||
|
// Verbraucherspezifische Variabeln
|
||||||
|
$this->RegisterVariableBoolean("IstNacht", "IstNacht", "", 0);
|
||||||
|
$this->RegisterVariableInteger("DailyOnTime", "DailyOnTime", "", 0);
|
||||||
|
$this->RegisterVariableBoolean("IsTimerActive", "IsTimerActive", "", 0);
|
||||||
|
|
||||||
|
// Verbraucherspezifischer Timer
|
||||||
|
$this->SetValue("IsTimerActive", false);
|
||||||
|
$this->RegisterTimer("ZustandswechselTimer", 0, "IPS_RequestAction(" . $this->InstanceID . ', "ResetPowerSteps", "");');
|
||||||
|
|
||||||
|
// 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");
|
||||||
|
$this->RegisterVariableInteger("Power", "Power");
|
||||||
|
$this->RegisterVariableBoolean("Is_Peak_Shaving", "Is_Peak_Shaving");
|
||||||
|
$this->RegisterVariableInteger("Leistung_Delta", "Leistung_Delta", "", 0);
|
||||||
|
|
||||||
|
// Hilfsvariabeln für Idle zustand
|
||||||
|
$this->RegisterPropertyInteger("IdleCounterMax", 2);
|
||||||
|
$this->RegisterVariableInteger("IdleCounter", "IdleCounter", "", 0);
|
||||||
|
$this->SetValue("IdleCounter", 0);
|
||||||
|
|
||||||
|
// Initialisiere Idle
|
||||||
|
$this->SetValue("Idle", true);
|
||||||
|
|
||||||
|
$this->RegisterTimer("Timer_Do_UserCalc_Verb", $this->ReadPropertyInteger("Interval") * 1000, "IPS_RequestAction(" . $this->InstanceID . ', "Do_UserCalc", "");');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ApplyChanges()
|
||||||
|
{
|
||||||
|
parent::ApplyChanges();
|
||||||
|
$this->SetTimerInterval("Timer_Do_UserCalc_Verb", $this->ReadPropertyInteger("Interval") * 1000);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function RequestAction($Ident, $Value)
|
||||||
|
{
|
||||||
|
switch ($Ident)
|
||||||
|
{
|
||||||
|
|
||||||
|
case "SetAktuelle_Leistung":
|
||||||
|
$this->SetValue("Power", (int)$Value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "GetCurrentData":
|
||||||
|
$this->SetValue("Is_Peak_Shaving", (bool)$Value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "ResetPowerSteps":
|
||||||
|
$this->ResetPowerSteps($Value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Do_UserCalc":
|
||||||
|
$this->SetAktuelle_Leistung($this->GetValue("Power"));
|
||||||
|
$this->GetCurrentData($this->GetValue("Is_Peak_Shaving"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methode zum Setzen der PowerSteps und Timer starten um zu hohes Takten zu unterbinden
|
||||||
|
public function SetTimerOn()
|
||||||
|
{
|
||||||
|
// Timer setzen, der nach "Zeit_Zwischen_Zustandswechseln" abläuft
|
||||||
|
$zeitZwischenZustandswechseln = $this->ReadPropertyInteger("Zeit_Zwischen_Zustandswechseln");
|
||||||
|
$this->SetTimerInterval("ZustandswechselTimer", $zeitZwischenZustandswechseln * 60000); // Timer in Millisekunden
|
||||||
|
IPS_LogMessage("Verbraucher", "In Set Methode");
|
||||||
|
|
||||||
|
// Timer-Status auf true setzen
|
||||||
|
$this->SetValue("IsTimerActive", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methode zum Zurücksetzen von PowerSteps nach Ablauf des Timers
|
||||||
|
public function ResetPowerSteps()
|
||||||
|
{
|
||||||
|
// PowerSteps wieder auf den ursprünglichen Zustand setzen (wie vorherige Funktionalität)
|
||||||
|
$this->SetValue("PowerSteps", json_encode([$this->GetValue("Aktuelle_Leistung") ]));
|
||||||
|
|
||||||
|
// Timer stoppen
|
||||||
|
$this->SetTimerInterval("ZustandswechselTimer", 0);
|
||||||
|
|
||||||
|
// Timer-Status auf false setzen
|
||||||
|
$this->SetValue("IsTimerActive", false);
|
||||||
|
}
|
||||||
|
// Methode zum Setzen des aktuellen Stromverbrauchs
|
||||||
|
public function SetAktuelle_Leistung(float $power)
|
||||||
|
{
|
||||||
|
$this->CheckIdle($power);
|
||||||
|
if ($this->GetValue("Aktuelle_Leistung") != $power)
|
||||||
|
{
|
||||||
|
$this->SetTimerOn();
|
||||||
|
}
|
||||||
|
$this->SetValue("Aktuelle_Leistung", $power);
|
||||||
|
$this->SetValue("Bezogene_Energie", ($this->GetValue("Bezogene_Energie") + ($this->GetValue("Aktuelle_Leistung") * ($this->ReadPropertyInteger("Interval") / 3600))));
|
||||||
|
|
||||||
|
$boilerLeistung = $this->ReadPropertyInteger("BoilerLeistung");
|
||||||
|
$schaltkontaktID = $this->ReadPropertyInteger("Schaltkontakt1");
|
||||||
|
|
||||||
|
if ($power == $boilerLeistung)
|
||||||
|
{
|
||||||
|
$schaltkontaktStatus = true;
|
||||||
|
}
|
||||||
|
elseif ($power == 0)
|
||||||
|
{
|
||||||
|
$schaltkontaktStatus = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Keine Änderung, wenn power nicht 0 oder boilerLeistung entspricht
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$currentStatus = GetValue($this->ReadPropertyInteger("Schaltkontakt1"));
|
||||||
|
|
||||||
|
// Schaltkontaktstatus ändern
|
||||||
|
SetValue($this->ReadPropertyInteger("Schaltkontakt1") , $schaltkontaktStatus);
|
||||||
|
|
||||||
|
if ($schaltkontaktStatus)
|
||||||
|
{
|
||||||
|
$this->SetValue("DailyOnTime", $this->GetValue("DailyOnTime") + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methode zum Abrufen der aktuellen Daten
|
||||||
|
public function GetCurrentData(bool $Peak)
|
||||||
|
{
|
||||||
|
$IstNacht = $this->GetValue("IstNacht");
|
||||||
|
$NeuesIstNacht = $this->ist_nachts();
|
||||||
|
|
||||||
|
if ($IstNacht == true && $NeuesIstNacht == false)
|
||||||
|
{
|
||||||
|
$this->SetValue("DailyOnTime", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->SetValue("IstNacht", $NeuesIstNacht);
|
||||||
|
|
||||||
|
$DailyOnTime = $this->GetValue("DailyOnTime");
|
||||||
|
$Mindestlaufzeit = $this->ReadPropertyInteger("Mindesttlaufzeit") * 60 * 12;
|
||||||
|
|
||||||
|
// Überprüfen, ob der Timer aktiv ist
|
||||||
|
if ($this->GetValue("IsTimerActive"))
|
||||||
|
{
|
||||||
|
// Timer ist aktiv, PowerSteps setzen
|
||||||
|
$this->SetValue("PowerSteps", json_encode([$this->GetValue("Aktuelle_Leistung") ]));
|
||||||
|
}
|
||||||
|
// Wenn Nacht und Mindestlaufzeit nicht erreicht ist
|
||||||
|
elseif ($NeuesIstNacht && $DailyOnTime < $Mindestlaufzeit)
|
||||||
|
{
|
||||||
|
if ($Peak)
|
||||||
|
{
|
||||||
|
$this->SetValue("PowerSteps", json_encode([0, $this->ReadPropertyInteger("BoilerLeistung") , ]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->SetValue("PowerSteps", json_encode([$this->ReadPropertyInteger("BoilerLeistung") ]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Andernfalls
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ($Peak)
|
||||||
|
{
|
||||||
|
$this->SetValue("PowerSteps", json_encode([0]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->SetValue("PowerSteps", json_encode([0, $this->ReadPropertyInteger("BoilerLeistung") , ]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function CheckIdle($power)
|
||||||
|
{
|
||||||
|
$lastpower = GetValue($this->GetIDForIdent("Aktuelle_Leistung"));
|
||||||
|
if ($lastpower != $power)
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user