Alte Module, welche nicht mehr benötigt, entfernt.
Batteriemodul wurde mit Goodwe, Sig Energy und Solaredge klar im Modul abgegrenzt.
This commit is contained in:
@@ -17,15 +17,34 @@
|
||||
"suffix": "Sekunden"
|
||||
},
|
||||
{
|
||||
"type": "NumberSpinner",
|
||||
"type":"Select",
|
||||
"name":"Batterietyp",
|
||||
"caption":"Batterietyp",
|
||||
"options":[
|
||||
{
|
||||
"caption":"Goodwe",
|
||||
"value":1
|
||||
},
|
||||
{
|
||||
"caption":"Solaredge",
|
||||
"value":2
|
||||
},
|
||||
{
|
||||
"caption":"Sig Energy",
|
||||
"value":3
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SelectVariable",
|
||||
"name": "MaxBatterieleistung",
|
||||
"caption": "Maximale Batterieleistung",
|
||||
"caption": "Maximale Ladeleistung",
|
||||
"suffix": ""
|
||||
},
|
||||
{
|
||||
"type": "NumberSpinner",
|
||||
"type": "SelectVariable",
|
||||
"name": "MaxNachladen",
|
||||
"caption": "Maximum Nachladen",
|
||||
"caption": "Maximum Nachladeleistung",
|
||||
"suffix": ""
|
||||
},
|
||||
{
|
||||
@@ -52,7 +71,7 @@
|
||||
},
|
||||
{
|
||||
"caption":"Durch EMS Symcon",
|
||||
"value":4
|
||||
"value":2
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -67,10 +86,9 @@
|
||||
"name": "Netzbezug",
|
||||
"caption": "Variable mit dem zu regelnden Netzbezug"
|
||||
},
|
||||
{
|
||||
"type": "SelectVariable",
|
||||
"name": "Batterieleistung_Effektiv",
|
||||
"caption": "Effektive, aktuelle Batterieleistung"
|
||||
{
|
||||
"type": "Label",
|
||||
"caption": "Je nach Wr-Type bekommt Laden_Entlade andere Werte.\nGoodwe: Laden=11, Entladen=12,\nSolaredge: Laden=3, Entladen=4,\nSig Energy: Laden=3, Entladen=6, P in kW"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"id": "{F6C6A4B2-C5BB-4D94-2629-01D8B0D4CAF5}",
|
||||
"id": "{166B9E49-882B-ADED-F256-4DD4CC24DF6C}",
|
||||
"name": "Batterie",
|
||||
"type": 3,
|
||||
"vendor": "Belevo AG",
|
||||
|
||||
@@ -12,17 +12,16 @@ class Batterie extends IPSModule
|
||||
$this->RegisterPropertyInteger("AufdasNachladen",0);
|
||||
$this->RegisterPropertyInteger("MinimumEntladen",0);
|
||||
$this->RegisterPropertyInteger("Batterieladezustand",0);
|
||||
$this->RegisterPropertyInteger("Batteriemanagement", 1);
|
||||
$this->RegisterPropertyInteger("Batteriemanagement", 1);
|
||||
$this->RegisterPropertyInteger("Batterietyp", 1);
|
||||
$this->RegisterPropertyInteger("MaxNachladen",0);
|
||||
$this->RegisterPropertyInteger("Netzbezug", 0); // Initialisierung mit 0
|
||||
$this->RegisterPropertyInteger("Interval", 2); // Recheninterval
|
||||
$this->RegisterPropertyInteger("Batterieleistung_Effektiv", 0); // Recheninterval
|
||||
|
||||
|
||||
// Variabeln für Kommunkation mit Manager
|
||||
$this->RegisterVariableFloat("Entladeleistung","Entladeleistung", "",0);
|
||||
$this->RegisterVariableInteger("Batteriemanagement_Variabel","Batteriemanagement_Variabel", "",0);
|
||||
$this->RegisterVariableInteger("Laden3_Entladen4","Laden3_Entladen4", "",3);
|
||||
$this->RegisterVariableFloat("Ladeleistung","Ladeleistung", "",0);
|
||||
$this->RegisterVariableInteger("Laden_Entladen","Laden_Entladen", "",3);
|
||||
$this->RegisterVariableInteger("Aktuelle_Leistung", "Aktuelle_Leistung", "", 0);
|
||||
$this->RegisterVariableString("PowerSteps", "PowerSteps");
|
||||
$this->RegisterVariableBoolean("Idle", "Idle", "", 0);
|
||||
@@ -58,49 +57,143 @@ class Batterie extends IPSModule
|
||||
$batterieManagement = $this->ReadPropertyInteger("Batteriemanagement");
|
||||
$this->SetValue("Batteriemanagement_Variabel", $batterieManagement);
|
||||
$this->SetTimerInterval("Timer_Do_UserCalc_Battery",$this->ReadPropertyInteger("Interval")*1000);
|
||||
}
|
||||
|
||||
$batterietyp = $this->ReadPropertyInteger("Batterietyp");
|
||||
|
||||
private function GeneratePowerSteps($additionalValue)
|
||||
{
|
||||
$maxleistung = $this->ReadPropertyInteger("MaxBatterieleistung");
|
||||
$stepSize = 250; // Schrittgröße
|
||||
$stepSizeSmall = 50; // Kleine Schrittgröße
|
||||
|
||||
// Array direkt als Range erzeugen (schneller als Schleife)
|
||||
$array_powersteps = range(-$maxleistung, $maxleistung, $stepSize);
|
||||
|
||||
// Nächstgelegenen Wert direkt bestimmen (rundet auf den nächsten Step)
|
||||
$closestValue = round($additionalValue / $stepSize) * $stepSize;
|
||||
|
||||
// Falls der Wert nicht im Bereich liegt, abbrechen
|
||||
if (!in_array($closestValue, $array_powersteps)) {
|
||||
return $array_powersteps;
|
||||
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);
|
||||
$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);
|
||||
$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);
|
||||
$this->MaintainVariable("Laden_Entladen", "Laden_Entladen", VARIABLETYPE_INTEGER, "", 12, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Index des gefundenen Werts suchen
|
||||
$index = array_search($closestValue, $array_powersteps);
|
||||
|
||||
// Zusätzliche Werte berechnen und auf MaxLeistung begrenzen
|
||||
$newValues = array_filter([
|
||||
$closestValue - 4 * $stepSizeSmall,
|
||||
$closestValue - 3 * $stepSizeSmall,
|
||||
$closestValue - 2 * $stepSizeSmall,
|
||||
$closestValue - $stepSizeSmall,
|
||||
$closestValue,
|
||||
$closestValue + $stepSizeSmall,
|
||||
$closestValue + 2 * $stepSizeSmall,
|
||||
$closestValue + 3 * $stepSizeSmall,
|
||||
$closestValue + 4 * $stepSizeSmall,
|
||||
], function ($value) use ($maxleistung) {
|
||||
return $value >= -$maxleistung && $value <= $maxleistung;
|
||||
});
|
||||
|
||||
// Effizienteres Einfügen der Werte (direkt an der Stelle)
|
||||
array_splice($array_powersteps, $index, 1, $newValues);
|
||||
|
||||
return $array_powersteps;
|
||||
|
||||
$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 MessageSink($TimeStamp, $SenderID, $Message, $Data)
|
||||
{
|
||||
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($additionalValue)
|
||||
{
|
||||
|
||||
$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++;
|
||||
}
|
||||
// $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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -132,39 +225,128 @@ public function RequestAction($Ident, $Value)
|
||||
public function SetAktuelle_Leistung(int $power)
|
||||
{
|
||||
|
||||
|
||||
$batterietyp = $this->ReadPropertyInteger("Batterietyp");
|
||||
$batterieManagement = $this->ReadPropertyInteger("Batteriemanagement");
|
||||
// Wechselrichter steuert das Laden/Entladen der Batterie
|
||||
if ($batterieManagement == 1) {
|
||||
|
||||
// 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);
|
||||
|
||||
//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("Ladeleistung", $power);
|
||||
$this->SetValue("Entladeleistung", 0);
|
||||
$this->SetValue("Laden3_Entladen4", 3);
|
||||
} else {
|
||||
$this->SetValue("Entladeleistung", abs($power));
|
||||
$this->SetValue("Ladeleistung", 0);
|
||||
$this->SetValue("Laden3_Entladen4", 4);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
if ($power >= 0) {
|
||||
$this->SetValue("Ladeleistung", $power);
|
||||
$this->SetValue("Entladeleistung", 0);
|
||||
$this->SetValue("Laden3_Entladen4", 3);
|
||||
} else {
|
||||
$this->SetValue("Entladeleistung", abs($power));
|
||||
$this->SetValue("Ladeleistung", 0);
|
||||
$this->SetValue("Laden3_Entladen4", 4);
|
||||
}
|
||||
}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 == 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("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) {
|
||||
@@ -193,7 +375,7 @@ public function RequestAction($Ident, $Value)
|
||||
$array_powersteps = $this->GeneratePowerSteps($this->GetValue("Aktuelle_Leistung"));
|
||||
$aufdasnachladen = $this->ReadPropertyInteger("AufdasNachladen");
|
||||
$minimumentladen = $this->ReadPropertyInteger("MinimumEntladen");
|
||||
$maxleistung = $this->ReadPropertyInteger("MaxBatterieleistung");
|
||||
$maxleistung = GetValue($this->ReadPropertyInteger("MaxBatterieleistung"));
|
||||
$dummy_array = [];
|
||||
$batterieladezustand = GetValue($this->ReadPropertyInteger("Batterieladezustand"));
|
||||
$filtered_powersteps_entladen = [];
|
||||
@@ -277,7 +459,7 @@ public function RequestAction($Ident, $Value)
|
||||
|
||||
}elseif($batterieladezustand<$aufdasnachladen){
|
||||
|
||||
$dummy_array[] = $this->ReadPropertyInteger("MaxNachladen");
|
||||
$dummy_array[] = GetValue($this->ReadPropertyInteger("MaxNachladen"));
|
||||
$this->SetValue("PowerSteps", json_encode($dummy_array));
|
||||
IPS_LogMessage("Batterie", "im 3");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user