no message

This commit is contained in:
belevo\mh
2025-11-27 07:38:14 +01:00
parent b3c7a6b8bc
commit 8e20c07636
14 changed files with 2 additions and 1406 deletions

View File

View File

@@ -1,76 +0,0 @@
{
"elements": [
{
"type": "Label",
"caption": "Konfiguration der Batterie für Peakshaving"
},
{
"type": "NumberSpinner",
"name": "IdleCounterMax",
"caption": "Zyklen zwischen zwei Leistungsänderungen (Multipliziert sich mit Interval)",
"suffix": ""
},
{
"type": "NumberSpinner",
"name": "Interval",
"caption": "Intervall Neuberechnung der Werte",
"suffix": "Sekunden"
},
{
"type": "NumberSpinner",
"name": "MaxBatterieleistung",
"caption": "Maximale Batterieleistung",
"suffix": ""
},
{
"type": "NumberSpinner",
"name": "MaxNachladen",
"caption": "Maximum Nachladen",
"suffix": ""
},
{
"type": "NumberSpinner",
"name": "AufdasNachladen",
"caption": "Auf so viel Prozent nachladen",
"suffix": ""
},
{
"type": "NumberSpinner",
"name": "MinimumEntladen",
"caption": "Minimum des Batterieladezustand",
"suffix": ""
},
{
"type":"Select",
"name":"Batteriemanagement",
"caption":"Batteriemanagement",
"options":[
{
"caption":"Durch Wechselrichter",
"value":1
},
{
"caption":"Durch EMS Symcon",
"value":4
}
]
},
{
"type": "SelectVariable",
"name": "Batterieladezustand",
"caption": "Batterieladezustand",
"test": true
},
{
"type": "SelectVariable",
"name": "Netzbezug",
"caption": "Variable mit dem zu regelnden Netzbezug"
},
{
"type": "SelectVariable",
"name": "Batterieleistung_Effektiv",
"caption": "Effektive, aktuelle Batterieleistung"
}
]
}

View File

@@ -1,12 +0,0 @@
{
"id": "{F6C6A4B2-C5BB-4D94-2629-01D8B0D4CAF5}",
"name": "Batterie",
"type": 3,
"vendor": "Belevo AG",
"aliases": [],
"parentRequirements": [],
"childRequirements": [],
"implemented": [],
"prefix": "GEF",
"url": ""
}

View File

@@ -1,327 +0,0 @@
<?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("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("Aktuelle_Leistung", "Aktuelle_Leistung", "", 0);
$this->RegisterVariableString("PowerSteps", "PowerSteps");
$this->RegisterVariableBoolean("Idle", "Idle", "", 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->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);
}
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;
}
// 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;
}
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)
{
$batterieManagement = $this->ReadPropertyInteger("Batteriemanagement");
// Wechselrichter steuert das Laden/Entladen der Batterie
if ($batterieManagement == 1) {
$this->SetValue("Entladeleistung", 0);
$this->SetValue("Ladeleistung", 0);
return;
}
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);
}
}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);
}
}
// Prüfe auf Änderung der Leistung im Vergleich zur letzten Einstellung
$lastPower = GetValue($this->GetIDForIdent("Aktuelle_Leistung"));
if ($power != $lastPower) {
$this->SetValue("Idle", false);
$this->SetValue(
"IdleCounter",
$this->ReadPropertyInteger("IdleCounterMax")
);
}
// Setze die neue aktuelle Leistung
$this->SetValue("Aktuelle_Leistung", $power);
$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)
{
IPS_LogMessage("Batterie", "Currentdata");
$array_powersteps = $this->GeneratePowerSteps($this->GetValue("Aktuelle_Leistung"));
$aufdasnachladen = $this->ReadPropertyInteger("AufdasNachladen");
$minimumentladen = $this->ReadPropertyInteger("MinimumEntladen");
$maxleistung = $this->ReadPropertyInteger("MaxBatterieleistung");
$dummy_array = [];
$batterieladezustand = GetValue($this->ReadPropertyInteger("Batterieladezustand"));
$filtered_powersteps_entladen = [];
if ($this->ReadPropertyInteger("Batteriemanagement") == 1) {
$dummy_array[] = 0;
return $this->SetValue("PowerSteps", json_encode($dummy_array));
}
$netzbezug = GetValue($this->ReadPropertyInteger("Netzbezug"));
if (abs($netzbezug) > $maxleistung) {
$netzbezug = $maxleistung * (-1);
}
if($batterieladezustand>(5+$aufdasnachladen)){
$this->SetValue("Hysterese", false);
}elseif($batterieladezustand<=$aufdasnachladen){
$this->SetValue("Hysterese", true);
}
$hyst = $this->GetValue("Hysterese");
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) {
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));
}
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{
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){
$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) {
return $value >= 0;
});
$filtered_powersteps_laden = array_values($filtered_powersteps);
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
}elseif($batterieladezustand<$aufdasnachladen){
$dummy_array[] = $this->ReadPropertyInteger("MaxNachladen");
$this->SetValue("PowerSteps", json_encode($dummy_array));
IPS_LogMessage("Batterie", "im 3");
}
}
}
private function CheckIdle($power)
{
$lastpower = GetValue("Aktuelle_Leistung");
if ($lastpower != GetValue("Aktuelle_Leistung")) {
$this->SetValue("Idle", false);
$this->SetValue(
"IdleCounter",
$this->ReadPropertyInteger("IdleCounterMax")
);
}
// IdleCounter auslesen und verarbeiten
$idleCounter = $this->GetValue("IdleCounter");
if ($idleCounter > 0) {
$this->SetValue("Idle", false);
$this->SetValue("IdleCounter", $idleCounter - 1);
} else {
$this->SetValue("Idle", true);
}
}
private function ProcessIdleCounter()
{
// IdleCounter auslesen und verarbeiten
$idleCounter = $this->GetValue("IdleCounter");
if ($idleCounter > 0) {
$this->SetValue("Idle", false);
$this->SetValue("IdleCounter", $idleCounter - 1);
} else {
$this->SetValue("Idle", true);
}
}
}
?>

View File

View File

@@ -1,86 +0,0 @@
{
"elements": [
{
"type": "Label",
"caption": "Konfiguration der Batterie für Peakshaving"
},
{
"type": "NumberSpinner",
"name": "IdleCounterMax",
"caption": "Zyklen zwischen zwei Leistungsänderungen (Multipliziert sich mit Interval)",
"suffix": ""
},
{
"type": "NumberSpinner",
"name": "Interval",
"caption": "Intervall Neuberechnung der Werte",
"suffix": "Sekunden"
},
{
"type":"Select",
"name":"Batterietyp",
"caption":"Batterietyp",
"options":[
{
"caption":"Goodwe",
"value":1
},
{
"caption":"Solaredge",
"value":2
}
]
},
{
"type": "NumberSpinner",
"name": "MaxBatterieleistung",
"caption": "Maximale Batterieleistung",
"suffix": ""
},
{
"type": "NumberSpinner",
"name": "MaxNachladen",
"caption": "Maximum Nachladen",
"suffix": ""
},
{
"type": "NumberSpinner",
"name": "AufdasNachladen",
"caption": "Auf so viel Prozent nachladen",
"suffix": ""
},
{
"type": "NumberSpinner",
"name": "MinimumEntladen",
"caption": "Minimum des Batterieladezustand",
"suffix": ""
},
{
"type":"Select",
"name":"Batteriemanagement",
"caption":"Batteriemanagement",
"options":[
{
"caption":"Durch Wechselrichter",
"value":1
},
{
"caption":"Durch EMS Symcon",
"value":4
}
]
},
{
"type": "SelectVariable",
"name": "Batterieladezustand",
"caption": "Batterieladezustand",
"test": true
},
{
"type": "SelectVariable",
"name": "Netzbezug",
"caption": "Variable mit dem zu regelnden Netzbezug"
}
]
}

View File

@@ -1,12 +0,0 @@
{
"id": "{6F11DCB1-44CB-73AD-9FA2-6035791874C5}",
"name": "Batterie_2",
"type": 3,
"vendor": "Belevo AG",
"aliases": [],
"parentRequirements": [],
"childRequirements": [],
"implemented": [],
"prefix": "GEF",
"url": ""
}

View File

@@ -1,407 +0,0 @@
<?php
class Batterie_2 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); // Initialisierung mit 0
$this->RegisterPropertyInteger("Interval", 2); // 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->RegisterVariableInteger("Laden_Entladen","Laden_Entladen", "",3);
$this->RegisterVariableString("Laden_Entladen_Beschreibung","{Goodwe: Laden=11, Entladen=12}, {Solaredge: Laden=3, Entladen=4}", "",3);
$this->RegisterVariableFloat("Ladeleistung","Ladeleistung", "",0);
$this->RegisterVariableFloat("Goodwe_EntLadeleistung","Goodwe_EntLadeleistung", "",0);
$this->RegisterVariableInteger("Aktuelle_Leistung", "Aktuelle_Leistung", "", 0);
$this->RegisterVariableString("PowerSteps", "PowerSteps");
$this->RegisterVariableBoolean("Idle", "Idle", "", 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->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);
}
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;
}
// 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;
}
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)
{
$batterieManagement = $this->ReadPropertyInteger("Batteriemanagement");
// Wechselrichter steuert das Laden/Entladen der Batterie
if ($batterieManagement == 1) {
$this->SetValue("Entladeleistung", 0);
$this->SetValue("Ladeleistung", 0);
return;
}
/*
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);
}
}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);
}
}
*/
$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);
}
}
}
// Prüfe auf Änderung der Leistung im Vergleich zur letzten Einstellung
$lastPower = GetValue($this->GetIDForIdent("Aktuelle_Leistung"));
if ($power != $lastPower) {
$this->SetValue("Idle", false);
$this->SetValue(
"IdleCounter",
$this->ReadPropertyInteger("IdleCounterMax")
);
}
// Setze die neue aktuelle Leistung
$this->SetValue("Aktuelle_Leistung", $power);
$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)
{
IPS_LogMessage("Batterie", "Currentdata");
$array_powersteps = $this->GeneratePowerSteps($this->GetValue("Aktuelle_Leistung"));
$aufdasnachladen = $this->ReadPropertyInteger("AufdasNachladen");
$minimumentladen = $this->ReadPropertyInteger("MinimumEntladen");
$maxleistung = $this->ReadPropertyInteger("MaxBatterieleistung");
$dummy_array = [];
$batterieladezustand = GetValue($this->ReadPropertyInteger("Batterieladezustand"));
$filtered_powersteps_entladen = [];
if ($this->ReadPropertyInteger("Batteriemanagement") == 1) {
$dummy_array[] = 0;
return $this->SetValue("PowerSteps", json_encode($dummy_array));
}
$netzbezug = GetValue($this->ReadPropertyInteger("Netzbezug"));
if (abs($netzbezug) > $maxleistung) {
$netzbezug = $maxleistung * (-1);
}
if($batterieladezustand>(5+$aufdasnachladen)){
$this->SetValue("Hysterese", false);
}elseif($batterieladezustand<=$aufdasnachladen){
$this->SetValue("Hysterese", true);
}
$hyst = $this->GetValue("Hysterese");
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) {
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));
}
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{
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){
$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) {
return $value >= 0;
});
$filtered_powersteps_laden = array_values($filtered_powersteps);
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
}elseif($batterieladezustand<$aufdasnachladen){
$dummy_array[] = $this->ReadPropertyInteger("MaxNachladen");
$this->SetValue("PowerSteps", json_encode($dummy_array));
IPS_LogMessage("Batterie", "im 3");
}
}
}
private function CheckIdle($power)
{
$lastpower = GetValue("Aktuelle_Leistung");
if ($lastpower != GetValue("Aktuelle_Leistung")) {
$this->SetValue("Idle", false);
$this->SetValue(
"IdleCounter",
$this->ReadPropertyInteger("IdleCounterMax")
);
}
// IdleCounter auslesen und verarbeiten
$idleCounter = $this->GetValue("IdleCounter");
if ($idleCounter > 0) {
$this->SetValue("Idle", false);
$this->SetValue("IdleCounter", $idleCounter - 1);
} else {
$this->SetValue("Idle", true);
}
}
private function ProcessIdleCounter()
{
// IdleCounter auslesen und verarbeiten
$idleCounter = $this->GetValue("IdleCounter");
if ($idleCounter > 0) {
$this->SetValue("Idle", false);
$this->SetValue("IdleCounter", $idleCounter - 1);
} else {
$this->SetValue("Idle", true);
}
}
}
?>

View File

@@ -1,6 +1,6 @@
{
"id": "{166B9E49-882B-ADED-F256-4DD4CC24DF6C}",
"name": "Batterie_3",
"name": "Batterie",
"type": 3,
"vendor": "Belevo AG",
"aliases": [],

View File

@@ -1,6 +1,6 @@
<?php
class Batterie_3 extends IPSModule
class Batterie extends IPSModule
{
public function Create()
{

View File

@@ -1,87 +0,0 @@
{
"elements": [
{
"type": "Label",
"caption": "Konfiguration der Batterie für Peakshaving"
},
{
"type": "NumberSpinner",
"name": "IdleCounterMax",
"caption": "Zyklen zwischen zwei Leistungsänderungen (Multipliziert sich mit Interval)",
"suffix": ""
},
{
"type": "NumberSpinner",
"name": "Interval",
"caption": "Intervall Neuberechnung der Werte",
"suffix": "Sekunden"
},
{
"type": "NumberSpinner",
"name": "MaxBatterieleistung",
"caption": "Maximale Batterieleistung",
"suffix": ""
},
{
"type": "NumberSpinner",
"name": "MaxNachladen",
"caption": "Maximum Nachladen",
"suffix": ""
},
{
"type": "NumberSpinner",
"name": "AufdasNachladen",
"caption": "Auf so viel % nachladen",
"suffix": ""
},
{
"type": "NumberSpinner",
"name": "MinimumEntladen",
"caption": "Minimal % des Batterieladezustand",
"suffix": ""
},
{
"type":"Select",
"name":"Batteriemanagement",
"caption":"Batteriemanagement",
"options":[
{
"caption":"Durch Wechselrichter",
"value":2
},
{
"caption":"Durch EMS Symcon",
"value":0
}
]
},
{
"type": "SelectVariable",
"name": "Batteriespannung",
"caption": "Batteriespannung",
"test": true
},
{
"type": "SelectVariable",
"name": "Batterie_Ladezustand",
"caption": "Batterie Ladeszutand %",
"test": true
},
{
"type": "SelectVariable",
"name": "Netzbezug",
"caption": "Variable mit dem zu regelnden Netzbezug"
},
{
"type": "SelectVariable",
"name": "Kotnrolle_TOU_Spannung",
"caption": "Kontrollvariabel Spannung TOU1"
},
{
"type": "SelectVariable",
"name": "Kotnrolle_Selling_CT",
"caption": "Kontrollvariabel Selling First/Zero Export to CT"
}
]
}

View File

@@ -1,12 +0,0 @@
{
"id": "{76529CAE-191C-41BF-5FDE-EF4A4FE25651}",
"name": "Batterie_Deye",
"type": 3,
"vendor": "Belevo AG",
"aliases": [],
"parentRequirements": [],
"childRequirements": [],
"implemented": [],
"prefix": "GEF",
"url": ""
}

View File

@@ -1,385 +0,0 @@
<?php
class Batterie_Deye extends IPSModule
{
public function Create()
{
parent::Create();
// Batterie spezifische Eigenschaften
$this->RegisterPropertyInteger("MaxBatterieleistung", 0);
$this->RegisterPropertyInteger("Batteriespannung", 50);
$this->RegisterPropertyInteger("Batterie_Ladezustand", 50);
$this->RegisterPropertyFloat("AufdasNachladen",0);
$this->RegisterPropertyFloat("MinimumEntladen",0);
$this->RegisterPropertyInteger("Batteriemanagement", 1);
$this->RegisterPropertyInteger("Kotnrolle_TOU_Spannung", 0);
$this->RegisterPropertyInteger("Kotnrolle_Selling_CT", 0);
$this->RegisterPropertyInteger("MaxNachladen",0);
$this->RegisterPropertyInteger("Netzbezug", 0); // Initialisierung mit 0
$this->RegisterPropertyInteger("Interval", 2); // Recheninterval
// Variabeln für Kommunkation mit Manager
$this->RegisterVariableInteger("Batteriemanagement_Variabel","Batteriemanagement_Variabel", "",0);
$this->RegisterVariableInteger("Ladestrom","Ladestrom", "",0);
$this->RegisterVariableInteger("Entladestrom","Entladestrom", "",0);
$this->RegisterVariableInteger("Batteriespannung_laden_entladen","Batteriespannung_laden_entladen","",0);
$this->RegisterVariableInteger("Aktuelle_Leistung", "Aktuelle_Leistung", "", 0);
$this->RegisterVariableString("PowerSteps", "PowerSteps");
$this->RegisterVariableBoolean("Idle", "Idle", "", 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->RegisterVariableBoolean("Schreibkontrolle", "Schreibkontrolle","",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->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);
}
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;
}
// 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;
}
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)
{
$y = (-1)*$power;
if ($y < 0) {
// Laden
$uVarID = $this->ReadPropertyInteger("Batteriespannung");
if ($uVarID > 0 && IPS_VariableExists($uVarID)) {
$U = GetValue($uVarID);
if ($U > 0) {
$lade_strom = abs($y) / $U;
} else {
$lade_strom = 0;
}
} else {
$lade_strom = 0;
}
$this->SetValue("Ladestrom", $lade_strom);
$this->SetValue("Entladestrom", 0);
$this->SetValue("Batteriespannung_laden_entladen", 100);
} elseif ($y > 0) {
// Entladen
$uVarID = $this->ReadPropertyInteger("Batteriespannung");
if ($uVarID > 0 && IPS_VariableExists($uVarID)) {
$U = GetValue($uVarID);
if ($U > 0) {
$entlade_strom = $y / $U;
} else {
$entlade_strom = 0;
}
} else {
$entlade_strom = 0;
}
$this->SetValue("Entladestrom", $entlade_strom);
$this->SetValue("Ladestrom", 0);
$this->SetValue("Batteriespannung_laden_entladen", 5);
} else {
// Kein Stromfluss (Leistung = 0)
$this->SetValue("Ladestrom", 0);
$this->SetValue("Entladestrom", 0);
}
$batterieManagement = $this->ReadPropertyInteger("Batteriemanagement");
// Wechselrichter steuert das Laden/Entladen der Batterie
if ($batterieManagement == 2) {
$this->SetValue("Ladestrom", 0);
$this->SetValue("Entladestrom", 0);
return;
}
// Prüfe auf Änderung der Leistung im Vergleich zur letzten Einstellung
$lastPower = GetValue($this->GetIDForIdent("Aktuelle_Leistung"));
if ($power != $lastPower) {
$this->SetValue("Idle", false);
$this->SetValue(
"IdleCounter",
$this->ReadPropertyInteger("IdleCounterMax")
);
}
// Setze die neue aktuelle Leistung
$this->SetValue("Aktuelle_Leistung", $power);
$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)
{
$ct = GetValue($this->ReadPropertyInteger("Kotnrolle_Selling_CT"));
$sell_Ct = $this->GetValue("Batteriemanagement_Variabel");
if ($ct != $sell_Ct) {
$this->SetValue("Schreibkontrolle", false);
} else {
$this->SetValue("Schreibkontrolle", true);
}
//$a = 2.54 * pow($V, 2) - 252 * $V + 6255.4;
$ladestrom_1 = $this->GetValue("Ladestrom");
$entadestrom_1 = $this->GetValue("Entladedestrom");
/*
if ($ladestrom_1 > 0 ) {
$V = GetValue($this->ReadPropertyInteger("Batteriespannung")) - 1;
}elseif ($entadestrom_1 > 0) {
$V = GetValue($this->ReadPropertyInteger("Batteriespannung")) + 1;
} else {
$V = GetValue($this->ReadPropertyInteger("Batteriespannung"));
}
*/
IPS_LogMessage("Batterie", "Currentdata");
$array_powersteps = $this->GeneratePowerSteps($this->GetValue("Aktuelle_Leistung"));
$aufdasnachladen = $this->ReadPropertyFloat("AufdasNachladen");
$minimumentladen = $this->ReadPropertyFloat("MinimumEntladen");
$maxleistung = $this->ReadPropertyInteger("MaxBatterieleistung");
$dummy_array = [];
$batterieladezustand = GetValue($this->ReadPropertyInteger("Batterie_Ladezustand"));
$filtered_powersteps_entladen = [];
if ($this->ReadPropertyInteger("Batteriemanagement") == 2) {
$dummy_array[] = 0;
return $this->SetValue("PowerSteps", json_encode($dummy_array));
}
$netzbezug = GetValue($this->ReadPropertyInteger("Netzbezug"));
if (abs($netzbezug) > $maxleistung) {
$netzbezug = $maxleistung * (-1);
}
if($batterieladezustand>(5+$aufdasnachladen)){
$this->SetValue("Hysterese", false);
}elseif($batterieladezustand<=$aufdasnachladen){
$this->SetValue("Hysterese", true);
}
$hyst = $this->GetValue("Hysterese");
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) {
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));
}
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{
IPS_LogMessage("Batterie", "Im else teil");
if($batterieladezustand>99.9){
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){
$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) {
return $value >= 0;
});
$filtered_powersteps_laden = array_values($filtered_powersteps);
$this->SetValue("PowerSteps", json_encode($filtered_powersteps_laden));
}elseif($batterieladezustand<$aufdasnachladen){
$dummy_array[] = $this->ReadPropertyInteger("MaxNachladen");
$this->SetValue("PowerSteps", json_encode($dummy_array));
IPS_LogMessage("Batterie", "im 3");
}
}
}
private function CheckIdle($power)
{
$lastpower = GetValue("Aktuelle_Leistung");
if ($lastpower != GetValue("Aktuelle_Leistung")) {
$this->SetValue("Idle", false);
$this->SetValue(
"IdleCounter",
$this->ReadPropertyInteger("IdleCounterMax")
);
}
// IdleCounter auslesen und verarbeiten
$idleCounter = $this->GetValue("IdleCounter");
if ($idleCounter > 0) {
$this->SetValue("Idle", false);
$this->SetValue("IdleCounter", $idleCounter - 1);
} else {
$this->SetValue("Idle", true);
}
}
private function ProcessIdleCounter()
{
// IdleCounter auslesen und verarbeiten
$idleCounter = $this->GetValue("IdleCounter");
if ($idleCounter > 0) {
$this->SetValue("Idle", false);
$this->SetValue("IdleCounter", $idleCounter - 1);
} else {
$this->SetValue("Idle", true);
}
}
}
?>