no message
This commit is contained in:
+382
-380
@@ -1,512 +1,514 @@
|
||||
<?php
|
||||
|
||||
class Batterie extends IPSModule
|
||||
{
|
||||
public function Create()
|
||||
{
|
||||
parent::Create();
|
||||
|
||||
// Batterie spezifische Eigenschaften
|
||||
$this->RegisterPropertyInteger("MaxBatterieleistung", 0);
|
||||
$this->RegisterPropertyInteger("Batteriespannung", 50);
|
||||
$this->RegisterPropertyInteger("AufdasNachladen", 0);
|
||||
$this->RegisterPropertyInteger("MinimumEntladen", 0);
|
||||
$this->RegisterPropertyInteger("Batterieladezustand", 0);
|
||||
$this->RegisterPropertyInteger("Batteriemanagement", 1);
|
||||
$this->RegisterPropertyInteger("Batterietyp", 1);
|
||||
$this->RegisterPropertyInteger("MaxNachladen", 0);
|
||||
$this->RegisterPropertyInteger("Netzbezug", 0);
|
||||
$this->RegisterPropertyInteger("AktuelleBatterieleistung", 0); // Initialisierung mit 0
|
||||
$this->RegisterPropertyInteger("AufdasNachladen",0);
|
||||
$this->RegisterPropertyInteger("MinimumEntladen",0);
|
||||
$this->RegisterPropertyInteger("Batterieladezustand",0);
|
||||
$this->RegisterPropertyInteger("Batteriemanagement", 1);
|
||||
$this->RegisterPropertyInteger("Batterietyp", 1);
|
||||
$this->RegisterPropertyInteger("MaxNachladen",0);
|
||||
$this->RegisterPropertyInteger("Netzbezug", 0);
|
||||
$this->RegisterPropertyInteger("AktuelleBatterieleistung", 0);// Initialisierung mit 0
|
||||
$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
|
||||
$this->RegisterVariableInteger("Aktuelle_Leistung", "Aktuelle zugeteilte Leistung", "", 0);
|
||||
$this->RegisterVariableString("PowerSteps", "Leistungsschritte");
|
||||
$this->RegisterVariableInteger("Batteriemanagement_Variabel","Batteriemanagement_Variabel", "",0);
|
||||
$this->RegisterVariableInteger("Laden_Entladen","Laden_Entladen", "",3);
|
||||
$this->RegisterVariableInteger("Aktuelle_Leistung", "Aktuelle_Leistung", "", 0);
|
||||
$this->RegisterVariableString("PowerSteps", "PowerSteps");
|
||||
$this->RegisterVariableBoolean("Idle", "Idle", "", 0);
|
||||
$this->RegisterVariableInteger("Sperre_Prio", "Priorität Peakshaving");
|
||||
$this->RegisterVariableInteger("PV_Prio", "Priorität PV");
|
||||
$this->RegisterVariableInteger("Power", "Leistung Batterie");
|
||||
$this->RegisterVariableBoolean("Is_Peak_Shaving", "Peakshavingmodus");
|
||||
$this->RegisterVariableInteger("Leistung_Delta", "Leistung Delta", "", 0);
|
||||
$this->RegisterVariableFloat("Bezogene_Energie", "Bezogene Energie", "", 0);
|
||||
$this->RegisterVariableInteger("Sperre_Prio", "Sperre_Prio");
|
||||
$this->RegisterVariableInteger("PV_Prio", "PV_Prio");
|
||||
$this->RegisterVariableInteger("Power", "Power");
|
||||
$this->RegisterVariableBoolean("Is_Peak_Shaving", "Is_Peak_Shaving");
|
||||
$this->RegisterVariableInteger("Leistung_Delta", "Leistung_Delta", "", 0);
|
||||
|
||||
|
||||
$this->RegisterVariableBoolean("Hysterese", "Hysterese","",false);
|
||||
|
||||
|
||||
|
||||
$this->RegisterVariableFloat("Bezogene_Energie", "Bezogene_Energie", "", 0);
|
||||
|
||||
// Hilfsvariabeln für Idle zustand
|
||||
$this->RegisterPropertyInteger("IdleCounterMax", 2);
|
||||
$this->RegisterVariableInteger("IdleCounter", "IdleCounter", "", 0);
|
||||
$this->SetValue("IdleCounter", 0);
|
||||
|
||||
// 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()
|
||||
{
|
||||
parent::ApplyChanges();
|
||||
|
||||
$batterieManagement = $this->ReadPropertyInteger("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");
|
||||
// Batterietypabhängige Variabeln Initialisieren
|
||||
switch ($batterietyp)
|
||||
{
|
||||
case 0: // Herstellerunabhängig
|
||||
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, false);
|
||||
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, true);
|
||||
$this->MaintainVariable("Entladeleistung", "Entladeleistung", VARIABLETYPE_FLOAT, "", 13, true);
|
||||
break;
|
||||
|
||||
switch ($batterietyp) {
|
||||
case 1: // Goodwe
|
||||
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, true);
|
||||
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, false);
|
||||
$this->MaintainVariable("Entladeleistung", "Entladeleistung", VARIABLETYPE_FLOAT, "", 13, false);
|
||||
break;
|
||||
$this->MaintainVariable("Laden_Entladen", "Laden_Entladen", VARIABLETYPE_INTEGER, "", 12, true);
|
||||
break;
|
||||
|
||||
case 2: // Solaredge
|
||||
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, false);
|
||||
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, 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
|
||||
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, false);
|
||||
$this->MaintainVariable("Ladeleistung", "Ladeleistung", VARIABLETYPE_FLOAT, "", 11, true);
|
||||
$this->MaintainVariable("Entladeleistung", "Entladeleistung", VARIABLETYPE_FLOAT, "", 13, true);
|
||||
break;
|
||||
$this->MaintainVariable("Laden_Entladen", "Laden_Entladen", VARIABLETYPE_INTEGER, "", 12, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Default, werden alle ausgeschaltet
|
||||
// Sicherheit: alles weg
|
||||
$this->MaintainVariable("Goodwe_EntLadeleistung", "Goodwe_EntLadeleistung", VARIABLETYPE_FLOAT, "", 10, 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);
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
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)
|
||||
{
|
||||
if ($Message !== VM_UPDATE)
|
||||
{
|
||||
return;
|
||||
{
|
||||
if ($Message !== VM_UPDATE) {
|
||||
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");
|
||||
$maxNachVar = $this->ReadPropertyInteger("MaxNachladen");
|
||||
if ($SenderID === $maxBatVar || $SenderID === $maxNachVar)
|
||||
{
|
||||
// PowerSteps sofort neu berechnen (mit aktuellem Peak-Status)
|
||||
$this->GetCurrentData($this->GetValue("Is_Peak_Shaving"));
|
||||
// $index ist jetzt Einfügeposition
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
// 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)
|
||||
{
|
||||
$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))
|
||||
{
|
||||
$this->SetValue("Entladeleistung", 0);
|
||||
$this->SetValue("Ladeleistung", 0);
|
||||
$this->SetValue("Batteriemanagement_Variabel", 0);
|
||||
return;
|
||||
// Enelix Steuert
|
||||
{
|
||||
|
||||
|
||||
$batterietyp = $this->ReadPropertyInteger("Batterietyp");
|
||||
$batterieManagement = $this->ReadPropertyInteger("Batteriemanagement");
|
||||
|
||||
// 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 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
|
||||
} 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
|
||||
|
||||
}
|
||||
elseif ($batterieManagement == 2 && $batterietyp == 2)
|
||||
{
|
||||
$this->SetValue("Batteriemanagement_Variabel", 4);
|
||||
}
|
||||
// Variabeln entsprechend gewältem Batterietyp setzen
|
||||
$batterietyp = $this->ReadPropertyInteger("Batterietyp");
|
||||
if ($batterietyp == 0)
|
||||
{
|
||||
//Herstellerunabhängig
|
||||
if ($this->GetValue("Is_Peak_Shaving") == true)
|
||||
{
|
||||
if ($power >= 0)
|
||||
{
|
||||
$this->SetValue("Ladeleistung", $power);
|
||||
$this->SetValue("Entladeleistung", 0);
|
||||
$this->SetValue("Laden_Entladen", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->SetValue("Entladeleistung", abs($power));
|
||||
$this->SetValue("Ladeleistung", 0);
|
||||
$this->SetValue("Laden_Entladen", 1);
|
||||
}
|
||||
}elseif ($batterieManagement == 2 && $batterietyp == 2) {
|
||||
$this->SetValue("Batteriemanagement_Variabel", 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($power >= 0)
|
||||
{
|
||||
$this->SetValue("Ladeleistung", $power);
|
||||
$this->SetValue("Entladeleistung", 0);
|
||||
$this->SetValue("Laden_Entladen", 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->SetValue("Entladeleistung", abs($power));
|
||||
$this->SetValue("Ladeleistung", 0);
|
||||
$this->SetValue("Laden_Entladen", 1);
|
||||
}
|
||||
|
||||
|
||||
$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 ($batterietyp == 2) {//Solaredge
|
||||
|
||||
//-----------------------Solaredge-------------------------------------//
|
||||
$this->SetValue("Goodwe_EntLadeleistung",0);
|
||||
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 == 1)
|
||||
{
|
||||
//Goodwe
|
||||
$this->SetValue("Entladeleistung", 0);
|
||||
$this->SetValue("Ladeleistung", 0);
|
||||
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);
|
||||
}
|
||||
} elseif ($batterietyp == 3) {//Sig Energy
|
||||
|
||||
//-----------------------Sig Energy-------------------------------------//
|
||||
$this->SetValue("Goodwe_EntLadeleistung",0);
|
||||
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("Goodwe_EntLadeleistung", abs($power));
|
||||
$this->SetValue("Laden_Entladen", 11);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->SetValue("Goodwe_EntLadeleistung", abs($power));
|
||||
$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);
|
||||
}
|
||||
|
||||
}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
|
||||
$lastPower = GetValue($this->GetIDForIdent("Aktuelle_Leistung"));
|
||||
if ($power != $lastPower)
|
||||
{
|
||||
if ($power != $lastPower) {
|
||||
$this->SetValue("Idle", false);
|
||||
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
|
||||
$this->SetValue(
|
||||
"IdleCounter",
|
||||
$this->ReadPropertyInteger("IdleCounterMax")
|
||||
);
|
||||
}
|
||||
|
||||
// Setze die neue aktuelle Leistung
|
||||
$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
|
||||
$this->ProcessIdleCounter();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function GetCurrentData(bool $Peak)
|
||||
{
|
||||
// Aktuelle Daten ausarbeiten und Berechnen
|
||||
$array_powersteps = $this->GeneratePowerSteps($this->GetValue("Aktuelle_Leistung"));
|
||||
IPS_LogMessage("Batterie", "Currentdata");
|
||||
|
||||
$array_powersteps = $this->GeneratePowerSteps();
|
||||
$aufdasnachladen = $this->ReadPropertyInteger("AufdasNachladen");
|
||||
$minimumentladen = $this->ReadPropertyInteger("MinimumEntladen");
|
||||
$maxleistung = GetValue($this->ReadPropertyInteger("MaxBatterieleistung")); //Ladeleistung
|
||||
$maxentladeleistung = GetValue($this->ReadPropertyInteger("MaxNachladen")); //Entladeleistung
|
||||
$maxleistung = GetValue($this->ReadPropertyInteger("MaxBatterieleistung"));//Ladeleistung
|
||||
$maxentladeleistung = GetValue($this->ReadPropertyInteger("MaxNachladen"));//Entladeleistung
|
||||
$dummy_array = [];
|
||||
$batterieladezustand = GetValue($this->ReadPropertyInteger("Batterieladezustand"));
|
||||
$filtered_powersteps_entladen = [];
|
||||
if ($this->ReadPropertyInteger("Batteriemanagement") == 1)
|
||||
{
|
||||
if ($this->ReadPropertyInteger("Batteriemanagement") == 1) {
|
||||
$dummy_array[] = 0;
|
||||
return $this->SetValue("PowerSteps", json_encode($dummy_array));
|
||||
}
|
||||
|
||||
|
||||
$netzbezug = GetValue($this->ReadPropertyInteger("Netzbezug"));
|
||||
$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);
|
||||
}
|
||||
elseif ($batterieladezustand <= $aufdasnachladen)
|
||||
{
|
||||
|
||||
}elseif($batterieladezustand<=$aufdasnachladen){
|
||||
$this->SetValue("Hysterese", true);
|
||||
}
|
||||
|
||||
$hyst = $this->GetValue("Hysterese");
|
||||
if ($Peak)
|
||||
{
|
||||
if ($batterieladezustand > $aufdasnachladen && $hyst == false)
|
||||
{
|
||||
|
||||
if($Peak){
|
||||
IPS_LogMessage("Batterie", "Im if teil");
|
||||
|
||||
if($batterieladezustand>$aufdasnachladen && $hyst==false){
|
||||
|
||||
$dummy_array[] = $netzbezug;
|
||||
$this->SetValue("PowerSteps", json_encode($dummy_array));
|
||||
}
|
||||
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;
|
||||
});
|
||||
$filtered_powersteps_laden = array_values($filtered_powersteps);
|
||||
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
|
||||
|
||||
}elseif($batterieladezustand>$minimumentladen){
|
||||
|
||||
$this->SetValue("PowerSteps", json_encode($array_powersteps));
|
||||
}
|
||||
elseif ($batterieladezustand > $minimumentladen)
|
||||
{
|
||||
$this->SetValue("PowerSteps", json_encode($array_powersteps));
|
||||
}
|
||||
else
|
||||
{
|
||||
$filtered_powersteps = array_filter($array_powersteps, function ($value)
|
||||
{
|
||||
else{
|
||||
|
||||
$filtered_powersteps = array_filter($array_powersteps, function ($value) {
|
||||
return $value >= 0;
|
||||
});
|
||||
$filtered_powersteps_laden = array_values($filtered_powersteps);
|
||||
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($batterieladezustand > 99)
|
||||
{
|
||||
$filtered_powersteps = array_filter($array_powersteps, function ($value)
|
||||
{
|
||||
|
||||
}else{
|
||||
IPS_LogMessage("Batterie", "Im else teil");
|
||||
|
||||
|
||||
if($batterieladezustand>99){
|
||||
IPS_LogMessage("Batterie", "im 1");
|
||||
|
||||
$filtered_powersteps = array_filter($array_powersteps, function ($value) {
|
||||
return $value <= 0;
|
||||
});
|
||||
$filtered_powersteps_laden = array_values($filtered_powersteps);
|
||||
$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));
|
||||
}
|
||||
elseif ($batterieladezustand >= $aufdasnachladen && $hyst == true)
|
||||
{
|
||||
$filtered_powersteps = array_filter($array_powersteps, function ($value)
|
||||
{
|
||||
IPS_LogMessage("Batterie", "im 2");
|
||||
|
||||
|
||||
}elseif($batterieladezustand>=$aufdasnachladen && $hyst==true){
|
||||
|
||||
$filtered_powersteps = array_filter($array_powersteps, function ($value) {
|
||||
return $value >= 0;
|
||||
});
|
||||
$filtered_powersteps_laden = array_values($filtered_powersteps);
|
||||
$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("MaxBatterieleistung"));
|
||||
$this->SetValue("PowerSteps", json_encode($dummy_array));
|
||||
IPS_LogMessage("Batterie", "im 3");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// Ab hier Hilfsfunktionen
|
||||
private function GeneratePowerSteps($additionalValue)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
// Hilfsfunktion zum Prüfen ob die Batterie schon wieder Leistung verändern kann
|
||||
$lastpower = GetValue("Aktuelle_Leistung");
|
||||
if ($lastpower != GetValue("Aktuelle_Leistung"))
|
||||
{
|
||||
if ($lastpower != GetValue("Aktuelle_Leistung")) {
|
||||
$this->SetValue("Idle", false);
|
||||
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
|
||||
$this->SetValue(
|
||||
"IdleCounter",
|
||||
$this->ReadPropertyInteger("IdleCounterMax")
|
||||
);
|
||||
}
|
||||
// IdleCounter auslesen und verarbeiten
|
||||
$idleCounter = $this->GetValue("IdleCounter");
|
||||
if ($idleCounter > 0)
|
||||
{
|
||||
if ($idleCounter > 0) {
|
||||
$this->SetValue("Idle", false);
|
||||
$this->SetValue("IdleCounter", $idleCounter - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$this->SetValue("Idle", true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function ProcessIdleCounter()
|
||||
{
|
||||
// IdleCounter auslesen und verarbeiten
|
||||
$idleCounter = $this->GetValue("IdleCounter");
|
||||
if ($idleCounter > 0)
|
||||
{
|
||||
if ($idleCounter > 0) {
|
||||
$this->SetValue("Idle", false);
|
||||
$this->SetValue("IdleCounter", $idleCounter - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$this->SetValue("Idle", true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user