Anpassungen am Ladetaions-Verbraucher Bugfixes wenn ladung nciht mehr startete
This commit is contained in:
0
Batterie_Deye/README.md
Normal file
0
Batterie_Deye/README.md
Normal file
87
Batterie_Deye/form.json
Normal file
87
Batterie_Deye/form.json
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
12
Batterie_Deye/module.json
Normal file
12
Batterie_Deye/module.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"id": "{76529CAE-191C-41BF-5FDE-EF4A4FE25651}",
|
||||||
|
"name": "Batterie_Deye",
|
||||||
|
"type": 3,
|
||||||
|
"vendor": "Belevo AG",
|
||||||
|
"aliases": [],
|
||||||
|
"parentRequirements": [],
|
||||||
|
"childRequirements": [],
|
||||||
|
"implemented": [],
|
||||||
|
"prefix": "GEF",
|
||||||
|
"url": ""
|
||||||
|
}
|
||||||
385
Batterie_Deye/module.php
Normal file
385
Batterie_Deye/module.php
Normal file
@@ -0,0 +1,385 @@
|
|||||||
|
<?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>199.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
67
Boiler_x_Stufig/README.md
Normal file
67
Boiler_x_Stufig/README.md
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
# Manager_1
|
||||||
|
Beschreibung des Moduls.
|
||||||
|
|
||||||
|
### Inhaltsverzeichnis
|
||||||
|
|
||||||
|
1. [Funktionsumfang](#1-funktionsumfang)
|
||||||
|
2. [Voraussetzungen](#2-voraussetzungen)
|
||||||
|
3. [Software-Installation](#3-software-installation)
|
||||||
|
4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon)
|
||||||
|
5. [Statusvariablen und Profile](#5-statusvariablen-und-profile)
|
||||||
|
6. [WebFront](#6-webfront)
|
||||||
|
7. [PHP-Befehlsreferenz](#7-php-befehlsreferenz)
|
||||||
|
|
||||||
|
### 1. Funktionsumfang
|
||||||
|
|
||||||
|
*
|
||||||
|
|
||||||
|
### 2. Voraussetzungen
|
||||||
|
|
||||||
|
- IP-Symcon ab Version 7.1
|
||||||
|
|
||||||
|
### 3. Software-Installation
|
||||||
|
|
||||||
|
* Über den Module Store das 'Manager_1'-Modul installieren.
|
||||||
|
* Alternativ über das Module Control folgende URL hinzufügen
|
||||||
|
|
||||||
|
### 4. Einrichten der Instanzen in IP-Symcon
|
||||||
|
|
||||||
|
Unter 'Instanz hinzufügen' kann das 'Manager_1'-Modul mithilfe des Schnellfilters gefunden werden.
|
||||||
|
- Weitere Informationen zum Hinzufügen von Instanzen in der [Dokumentation der Instanzen](https://www.symcon.de/service/dokumentation/konzepte/instanzen/#Instanz_hinzufügen)
|
||||||
|
|
||||||
|
__Konfigurationsseite__:
|
||||||
|
|
||||||
|
Name | Beschreibung
|
||||||
|
-------- | ------------------
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
||||||
|
### 5. Statusvariablen und Profile
|
||||||
|
|
||||||
|
Die Statusvariablen/Kategorien werden automatisch angelegt. Das Löschen einzelner kann zu Fehlfunktionen führen.
|
||||||
|
|
||||||
|
#### Statusvariablen
|
||||||
|
|
||||||
|
Name | Typ | Beschreibung
|
||||||
|
------ | ------- | ------------
|
||||||
|
| |
|
||||||
|
| |
|
||||||
|
|
||||||
|
#### Profile
|
||||||
|
|
||||||
|
Name | Typ
|
||||||
|
------ | -------
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
||||||
|
### 6. WebFront
|
||||||
|
|
||||||
|
Die Funktionalität, die das Modul im WebFront bietet.
|
||||||
|
|
||||||
|
### 7. PHP-Befehlsreferenz
|
||||||
|
|
||||||
|
`boolean GEF_BeispielFunktion(integer $InstanzID);`
|
||||||
|
Erklärung der Funktion.
|
||||||
|
|
||||||
|
Beispiel:
|
||||||
|
`GEF_BeispielFunktion(12345);`
|
||||||
121
Boiler_x_Stufig/form.json
Normal file
121
Boiler_x_Stufig/form.json
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
{
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"type": "Label",
|
||||||
|
"caption": "Konfiguration der nötigen Schaltkontakte und Nennleistungen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type":"Select",
|
||||||
|
"name":"Boilertemperatur_glätten",
|
||||||
|
"caption":"Boilertemperatur glätten",
|
||||||
|
"options":[
|
||||||
|
{
|
||||||
|
"caption":"Ja",
|
||||||
|
"value":true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"caption":"Nein",
|
||||||
|
"value":false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "ZeitKonstante",
|
||||||
|
"caption": "Zeit Konstante",
|
||||||
|
"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": "IdleCounterMax",
|
||||||
|
"caption": "Zyklen zwischen zwei Leistungsänderungen (Multipliziert sich mit Interval)",
|
||||||
|
"suffix": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type":"List",
|
||||||
|
"name":"LeistungsStufen",
|
||||||
|
"caption":"Anzahl Stufen mit den dazugehörigen Leistungen",
|
||||||
|
"add":true,
|
||||||
|
"delete":true,
|
||||||
|
"columns":[
|
||||||
|
{
|
||||||
|
"caption":"Stufe(n)",
|
||||||
|
"name":"Stufe",
|
||||||
|
"width":"200px",
|
||||||
|
"add":"Stufe",
|
||||||
|
"edit":{
|
||||||
|
"type":"NumberSpinner"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"caption":"Leistung in W",
|
||||||
|
"name":"Leistung",
|
||||||
|
"width":"300px",
|
||||||
|
"add":0,
|
||||||
|
"edit":{
|
||||||
|
"type":"NumberSpinner"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"caption":"Schaltkontakt",
|
||||||
|
"name":"Schaltkontakt_Stufe",
|
||||||
|
"width":"400px",
|
||||||
|
"add":0,
|
||||||
|
"edit":{
|
||||||
|
"type":"SelectVariable"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "Boilervolumen",
|
||||||
|
"caption": "Boilervolumen",
|
||||||
|
"suffix": "Liter"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SelectVariable",
|
||||||
|
"name": "Boilerfuehler_PT1",
|
||||||
|
"caption": "Variable für Boilerfühler PT1",
|
||||||
|
"test": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "List",
|
||||||
|
"name": "Zeitplan",
|
||||||
|
"caption": "Zeitplan für Solltemperaturen",
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"caption": "Uhrzeit",
|
||||||
|
"name": "Uhrzeit",
|
||||||
|
"width": "150px",
|
||||||
|
"add": "00:00",
|
||||||
|
"edit": {
|
||||||
|
"type": "ValidationTextBox"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"caption": "Solltemperatur",
|
||||||
|
"name": "Solltemperatur",
|
||||||
|
"width": "150px",
|
||||||
|
"add": 0,
|
||||||
|
"edit": {
|
||||||
|
"type": "NumberSpinner"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"add": true,
|
||||||
|
"delete": true,
|
||||||
|
"sort": {
|
||||||
|
"column": "Uhrzeit",
|
||||||
|
"direction": "ascending"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
12
Boiler_x_Stufig/module.json
Normal file
12
Boiler_x_Stufig/module.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"id": "{72B9606B-D5E6-6033-F2E4-0B2C5533F726}",
|
||||||
|
"name": "Boiler_x_Stufig",
|
||||||
|
"type": 3,
|
||||||
|
"vendor": "Belevo AG",
|
||||||
|
"aliases": [],
|
||||||
|
"parentRequirements": [],
|
||||||
|
"childRequirements": [],
|
||||||
|
"implemented": [],
|
||||||
|
"prefix": "GEF",
|
||||||
|
"url": ""
|
||||||
|
}
|
||||||
396
Boiler_x_Stufig/module.php
Normal file
396
Boiler_x_Stufig/module.php
Normal file
@@ -0,0 +1,396 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Boiler_x_Stufig extends IPSModule
|
||||||
|
{
|
||||||
|
private array $leistungArray = [];
|
||||||
|
public function Create()
|
||||||
|
{
|
||||||
|
parent::Create();
|
||||||
|
|
||||||
|
// Boiler spezifische Properties
|
||||||
|
$this->RegisterPropertyString("LeistungsStufen", json_encode([])); // Bezeichnung der Liste
|
||||||
|
$this->RegisterPropertyInteger("ZeitKonstante", 120);
|
||||||
|
$this->RegisterPropertyInteger("Boilerfuehler_PT1", 0);
|
||||||
|
$this->RegisterPropertyBoolean("Boilertemperatur_glätten", false);
|
||||||
|
$this->RegisterPropertyInteger("Boilervolumen", 300);
|
||||||
|
$this->RegisterPropertyString("Zeitplan", "");
|
||||||
|
$this->RegisterPropertyInteger("Interval", 5); // Recheninterval
|
||||||
|
|
||||||
|
|
||||||
|
// Boiler spezifische Variablen
|
||||||
|
|
||||||
|
$this->RegisterVariableInteger("Mindesttemperatur","Mindesttemperatur","",45);
|
||||||
|
$this->RegisterVariableInteger("Maximaltemperatur","Maximaltemperatur","",60);
|
||||||
|
$this->RegisterVariableInteger("Legionellentemperatur","Legionellentemperatur","",65);
|
||||||
|
$this->RegisterVariableInteger("LegioCounter", "LegioCounter", "", 0);
|
||||||
|
$this->RegisterVariableInteger("Boilertemperatur", "Boilertemperatur", "", 0);
|
||||||
|
|
||||||
|
|
||||||
|
// 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", '', 0);
|
||||||
|
$this->RegisterVariableBoolean("Is_Peak_Shaving", "Is_Peak_Shaving", "", true);
|
||||||
|
$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_Boiler",$this->ReadPropertyInteger("Interval")*1000,"IPS_RequestAction(" .$this->InstanceID .', "Do_UserCalc", "");');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ApplyChanges()
|
||||||
|
{
|
||||||
|
parent::ApplyChanges();
|
||||||
|
$this->SetTimerInterval("Timer_Do_UserCalc_Boiler",$this->ReadPropertyInteger("Interval")*1000);
|
||||||
|
|
||||||
|
//$this->LadeUndSortiereLeistungen();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function LadeUndSortiereLeistungen()
|
||||||
|
{
|
||||||
|
// Array initialisieren, immer mit 0
|
||||||
|
$this->leistungArray = [0];
|
||||||
|
|
||||||
|
// JSON aus der Property auslesen
|
||||||
|
$json = $this->ReadPropertyString("LeistungsStufen");
|
||||||
|
$leistungsStufen = json_decode($json, true);
|
||||||
|
|
||||||
|
if (is_array($leistungsStufen)) {
|
||||||
|
foreach ($leistungsStufen as $stufe) {
|
||||||
|
$this->leistungArray[] = $stufe['Leistung'] ?? 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Array sortieren (Bubble Sort)
|
||||||
|
$len = count($this->leistungArray);
|
||||||
|
for ($i = 0; $i < $len - 1; $i++) {
|
||||||
|
for ($j = 0; $j < $len - $i - 1; $j++) {
|
||||||
|
if ($this->leistungArray[$j] > $this->leistungArray[$j + 1]) {
|
||||||
|
$temp = $this->leistungArray[$j];
|
||||||
|
$this->leistungArray[$j] = $this->leistungArray[$j + 1];
|
||||||
|
$this->leistungArray[$j + 1] = $temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNextTimeAndTemperature($zeitplan) {
|
||||||
|
$arr = json_decode($zeitplan, true);
|
||||||
|
if (empty($arr)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$currentTime = new DateTime();
|
||||||
|
$nextEntry = null;
|
||||||
|
$minDiff = PHP_INT_MAX;
|
||||||
|
|
||||||
|
foreach ($arr as $entry) {
|
||||||
|
$entryTime = DateTime::createFromFormat('H:i', $entry['Uhrzeit']);
|
||||||
|
if ($entryTime < $currentTime) {
|
||||||
|
$entryTime->modify('+1 day');
|
||||||
|
}
|
||||||
|
$diff = $currentTime->diff($entryTime)->format('%r%a') * 24 * 60 + $currentTime->diff($entryTime)->format('%r%h') * 60 + $currentTime->diff($entryTime)->format('%r%i');
|
||||||
|
if ($diff < $minDiff) {
|
||||||
|
$minDiff = $diff;
|
||||||
|
$nextEntry = $entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $nextEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function calculateRemainingTime($nextTime) {
|
||||||
|
$currentTime = new DateTime();
|
||||||
|
$nextDateTime = DateTime::createFromFormat('H:i', $nextTime);
|
||||||
|
if ($nextDateTime < $currentTime) {
|
||||||
|
$nextDateTime->modify('+1 day');
|
||||||
|
}
|
||||||
|
$interval = $currentTime->diff($nextDateTime);
|
||||||
|
return $interval->h + ($interval->i / 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function calculateRequiredHeat($boilervolumen, $tempDiff) {
|
||||||
|
// Annahme: spezifische Wärmekapazität von Wasser = 4.186 J/g°C
|
||||||
|
// 1 Liter Wasser = 1000 Gramm
|
||||||
|
$specificHeatCapacity = 4.186; // J/g°C
|
||||||
|
$waterMass = $boilervolumen * 1000; // Gramm
|
||||||
|
return $specificHeatCapacity * $waterMass * $tempDiff; // Joules
|
||||||
|
}
|
||||||
|
|
||||||
|
public function canBoilerReachTemperature($boilervolumen, $boilerTemper, $nextTemp, $remainingTime, $vollleistung) {
|
||||||
|
$tempDiff = $nextTemp - $boilerTemper;
|
||||||
|
$requiredHeat = $this->calculateRequiredHeat($boilervolumen, $tempDiff);
|
||||||
|
$availableHeat = $vollleistung * $remainingTime * 3600; // Leistung in Watt * Zeit in Sekunden
|
||||||
|
return $availableHeat >= $requiredHeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methode zum Setzen des aktuellen Stromverbrauchs
|
||||||
|
public function SetAktuelle_Leistung(int $power)
|
||||||
|
{
|
||||||
|
// Lade sicherheitshalber das aktuelle LeistungArray
|
||||||
|
$this->LadeUndSortiereLeistungen();
|
||||||
|
|
||||||
|
// Schleife über alle Leistungsstufen
|
||||||
|
foreach ($this->leistungArray as $leistung) {
|
||||||
|
$kontaktID = $this->GetKontaktIDZuLeistung($leistung);
|
||||||
|
|
||||||
|
// Prüfen, ob Variable existiert und gültige ID
|
||||||
|
if ($kontaktID > 0 && IPS_VariableExists($kontaktID)) {
|
||||||
|
// Setze TRUE für die aktuelle Leistungsstufe, FALSE für alle anderen
|
||||||
|
SetValue($kontaktID, ($leistung === $power));
|
||||||
|
} else {
|
||||||
|
if ($kontaktID > 0) {
|
||||||
|
IPS_LogMessage("ERROR", "KontaktID $kontaktID existiert nicht oder ist ungültig!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prüfe auf Änderung der Power 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetKontaktIDZuLeistung(int $leistung): int
|
||||||
|
{
|
||||||
|
$json = $this->ReadPropertyString("LeistungsStufen");
|
||||||
|
$leistungsStufen = json_decode($json, true);
|
||||||
|
|
||||||
|
if (is_array($leistungsStufen)) {
|
||||||
|
foreach ($leistungsStufen as $stufe) {
|
||||||
|
if (($stufe['Leistung'] ?? 0) == $leistung) {
|
||||||
|
return $stufe['Schaltkontakt_Stufe'] ?? 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methode zum Abrufen der aktuellen Daten
|
||||||
|
public function GetCurrentData(bool $Peak)
|
||||||
|
{
|
||||||
|
$LegioCounter = $this->GetValue("LegioCounter");
|
||||||
|
$this->LadeUndSortiereLeistungen();
|
||||||
|
|
||||||
|
$boilertemperatur_glätten = $this->ReadPropertyBoolean("Boilertemperatur_glätten");
|
||||||
|
|
||||||
|
if ($boilertemperatur_glätten) {
|
||||||
|
// Wenn Glättung aktiviert ist, führe das Glätten durch
|
||||||
|
$boilerFuehlerPT1ID = $this->ReadPropertyInteger("Boilerfuehler_PT1");
|
||||||
|
|
||||||
|
if (IPS_VariableExists($boilerFuehlerPT1ID)) {
|
||||||
|
$boilerPT1 = GetValue($boilerFuehlerPT1ID);
|
||||||
|
} else {
|
||||||
|
$boilerPT1 = 0.0; // Standardwert
|
||||||
|
}
|
||||||
|
|
||||||
|
$boilerTempID = $this->GetIDForIdent("Boilertemperatur");
|
||||||
|
if (IPS_VariableExists($boilerTempID)) {
|
||||||
|
$boilerTemp = $this->GetValue("Boilertemperatur");
|
||||||
|
} else {
|
||||||
|
$boilerTemp = 0.0; // Standardwert
|
||||||
|
}
|
||||||
|
|
||||||
|
// PT
|
||||||
|
$time_constant= $this->ReadPropertyInteger("ZeitKonstante");
|
||||||
|
$delta_t = 5; // Zeitdifferenz zwischen den Messungen (30 Sekunden)
|
||||||
|
$alpha = $delta_t / ($time_constant + $delta_t);
|
||||||
|
$newBoilerTemp = $boilerTemp + $alpha * ($boilerPT1 - $boilerTemp);
|
||||||
|
$this->SetValue("Boilertemperatur", $newBoilerTemp);
|
||||||
|
} else {
|
||||||
|
// Wenn Glättung nicht aktiviert ist, setze die Boilertemperatur direkt auf den Wert des Boilerfühlers
|
||||||
|
$boilerFuehlerPT1ID = $this->ReadPropertyInteger("Boilerfuehler_PT1");
|
||||||
|
|
||||||
|
if (IPS_VariableExists($boilerFuehlerPT1ID)) {
|
||||||
|
$boilerPT1 = GetValue($boilerFuehlerPT1ID);
|
||||||
|
} else {
|
||||||
|
$boilerPT1 = 0.0; // Standardwert
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setze Boilertemperatur direkt auf den Wert des Boilerfühlers
|
||||||
|
$this->SetValue("Boilertemperatur", $boilerPT1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$boilerTemp = $this->GetValue("Boilertemperatur");
|
||||||
|
$minTemp = $this->GetValue("Mindesttemperatur");
|
||||||
|
$maxTemp = $this->GetValue("Maximaltemperatur");
|
||||||
|
$LegioTemp = $this->GetValue("Legionellentemperatur");
|
||||||
|
|
||||||
|
|
||||||
|
$nextEntry = $this->getNextTimeAndTemperature($this->ReadPropertyString("Zeitplan"));
|
||||||
|
if ($nextEntry !== null) {
|
||||||
|
$remainingTime = $this->calculateRemainingTime($nextEntry['Uhrzeit']);
|
||||||
|
$nextTemp = $nextEntry['Solltemperatur'];
|
||||||
|
|
||||||
|
if (!$this->canBoilerReachTemperature($this->ReadPropertyInteger("Boilervolumen"), $boilerTemp, $nextTemp, $remainingTime, $vollLeistung)) {
|
||||||
|
$minTemp = $nextTemp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if ($boilerTemp > $LegioTemp) {
|
||||||
|
$LegioCounter = 0;
|
||||||
|
} else {
|
||||||
|
$LegioCounter = $LegioCounter + 1;
|
||||||
|
}
|
||||||
|
if ($LegioCounter > 69120) {
|
||||||
|
$maxTemp = $LegioTemp;
|
||||||
|
}
|
||||||
|
if ($LegioCounter > 120960 && $this->ist_nachts()) {
|
||||||
|
$minTemp = $LegioTemp;
|
||||||
|
}
|
||||||
|
if ($LegioCounter > 138240) { // Timeout für Legio wenn temperatur nicht erreicht werden kann, setze legionellenfunktion zurück
|
||||||
|
$LegioCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->SetValue("LegioCounter", $LegioCounter);
|
||||||
|
|
||||||
|
|
||||||
|
if ($Peak) {
|
||||||
|
if ($boilerTemp < $minTemp) {
|
||||||
|
$this->SetValue("PowerSteps", json_encode($this->leistungArray));
|
||||||
|
} elseif (
|
||||||
|
$boilerTemp < $minTemp + 5 &&
|
||||||
|
$this->IstEineStufeAktiv()
|
||||||
|
) {
|
||||||
|
$this->SetValue("PowerSteps", json_encode($this->leistungArray));
|
||||||
|
} else {
|
||||||
|
$this->SetValue("PowerSteps", json_encode([0]));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($boilerTemp < $minTemp) {
|
||||||
|
$this->SetValue("PowerSteps", json_encode([max($this->leistungArray)]));
|
||||||
|
|
||||||
|
} elseif (
|
||||||
|
$boilerTemp < $minTemp + 5 &&
|
||||||
|
$this->IstEineStufeAktiv()
|
||||||
|
) {
|
||||||
|
$this->SetValue("PowerSteps", json_encode([max($this->leistungArray)]));
|
||||||
|
|
||||||
|
} elseif ($boilerTemp < $maxTemp - 5) {
|
||||||
|
$this->SetValue("PowerSteps", json_encode($this->leistungArray));
|
||||||
|
} elseif ( $boilerTemp < $maxTemp && $this->IstEineStufeAktiv()
|
||||||
|
) {
|
||||||
|
$this->SetValue("PowerSteps", json_encode($this->leistungArray));
|
||||||
|
} else {
|
||||||
|
$this->SetValue("PowerSteps", json_encode([0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function IstEineStufeAktiv(): bool
|
||||||
|
{
|
||||||
|
$json = $this->ReadPropertyString("LeistungsStufen");
|
||||||
|
$leistungsStufen = json_decode($json, true);
|
||||||
|
|
||||||
|
if (is_array($leistungsStufen)) {
|
||||||
|
foreach ($leistungsStufen as $stufe) {
|
||||||
|
$kontaktID = $stufe['Schaltkontakt_Stufe'] ?? 0;
|
||||||
|
if ($kontaktID > 0 && IPS_VariableExists($kontaktID)) {
|
||||||
|
if (GetValue($kontaktID) === true) {
|
||||||
|
return true; // mindestens eine Stufe ist aktiv
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false; // keine aktiv
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -204,6 +204,7 @@ class Ladestation_v2 extends IPSModule
|
|||||||
|
|
||||||
}else{
|
}else{
|
||||||
$this->SetValue("Car_detected", false);
|
$this->SetValue("Car_detected", false);
|
||||||
|
$this->SetValue("Pending_Counter", 0);
|
||||||
$this->SetValue("Leistung_Delta", 0);
|
$this->SetValue("Leistung_Delta", 0);
|
||||||
$this->SetValue("Car_is_full", false);
|
$this->SetValue("Car_is_full", false);
|
||||||
$this->ResetTimer();
|
$this->ResetTimer();
|
||||||
@@ -698,7 +699,7 @@ class Ladestation_v2 extends IPSModule
|
|||||||
$powerSteps = [];
|
$powerSteps = [];
|
||||||
|
|
||||||
// Konfiguration des powerSteps-Arrays basierend auf den Properties
|
// Konfiguration des powerSteps-Arrays basierend auf den Properties
|
||||||
if (!$ladebereit) {
|
if (!$ladebereit || $this->GetValue("Car_is_full")) {
|
||||||
$powerSteps = [0];
|
$powerSteps = [0];
|
||||||
} elseif (!$Peak && !$solarladen) {
|
} elseif (!$Peak && !$solarladen) {
|
||||||
$powerSteps = [max($this->Get_Array_From_Current($this->GetValue("Is_1_ph"),$this->GetValue("Max_Current"), $this->GetValue("Aktuelle_Leistung"), $this->GetValue("IsTimerActive_Null_Timer")))];
|
$powerSteps = [max($this->Get_Array_From_Current($this->GetValue("Is_1_ph"),$this->GetValue("Max_Current"), $this->GetValue("Aktuelle_Leistung"), $this->GetValue("IsTimerActive_Null_Timer")))];
|
||||||
|
|||||||
@@ -22,6 +22,23 @@
|
|||||||
"name": "Netzbezug",
|
"name": "Netzbezug",
|
||||||
"caption": "Variable mit dem zu regelnden Netzbezug"
|
"caption": "Variable mit dem zu regelnden Netzbezug"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "CheckBox",
|
||||||
|
"name": "UmschaltpunktStatisch",
|
||||||
|
"caption": "Umschaltpunkt Statisch festlegen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "Umschalt_Solarladen",
|
||||||
|
"caption": "Umschaltpunkt auf Solarladen",
|
||||||
|
"suffix": "Watt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "Umschalt_Peakshaving",
|
||||||
|
"caption": "Umschaltpunkt auf Peakshaving",
|
||||||
|
"suffix": "Watt"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "CheckBox",
|
"type": "CheckBox",
|
||||||
"name": "HauptmanagerAktiv",
|
"name": "HauptmanagerAktiv",
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ class Manager extends IPSModule
|
|||||||
$this->RegisterPropertyInteger("Ueberschussleistung", 0);
|
$this->RegisterPropertyInteger("Ueberschussleistung", 0);
|
||||||
$this->RegisterPropertyInteger("Netzbezug", 0); // Initialisierung mit 0
|
$this->RegisterPropertyInteger("Netzbezug", 0); // Initialisierung mit 0
|
||||||
$this->RegisterPropertyString("Verbraucher_Liste", "[]");
|
$this->RegisterPropertyString("Verbraucher_Liste", "[]");
|
||||||
|
$this->RegisterPropertyBoolean("UmschaltpunktStatisch", false); // Initialisierung mit 0
|
||||||
|
$this->RegisterPropertyInteger("Umschalt_Solarladen", 100); // Initialisierung mit 0
|
||||||
|
$this->RegisterPropertyInteger("Umschalt_Peakshaving", 10000); // Initialisierung mit 0
|
||||||
$this->RegisterPropertyBoolean("HauptmanagerAktiv", false); // Initialisierung mit 0
|
$this->RegisterPropertyBoolean("HauptmanagerAktiv", false); // Initialisierung mit 0
|
||||||
$this->RegisterPropertyInteger("ManagerID", 0); // Initialisierung mit 0
|
$this->RegisterPropertyInteger("ManagerID", 0); // Initialisierung mit 0
|
||||||
$this->RegisterPropertyInteger("DatenHoch", 0); // Initialisierung mit 0
|
$this->RegisterPropertyInteger("DatenHoch", 0); // Initialisierung mit 0
|
||||||
@@ -95,20 +98,6 @@ class Manager extends IPSModule
|
|||||||
|
|
||||||
public function DistributeEnergy()
|
public function DistributeEnergy()
|
||||||
{
|
{
|
||||||
// Systemvariablen abrufen
|
|
||||||
$Netzbezug = GetValue($this->ReadPropertyInteger("Netzbezug"));
|
|
||||||
$Peakleistung = $this->ReadPropertyInteger("Peakleistung");
|
|
||||||
$Ueberschussleistung = $this->ReadPropertyInteger("Ueberschussleistung");
|
|
||||||
|
|
||||||
// Fallunterscheidung ob auf Solarladen oder Peakshaving gerregelt wird.
|
|
||||||
if ($Netzbezug < ($Peakleistung + $Ueberschussleistung) / 2) {
|
|
||||||
$remainingPower = -1 * (-1 * $Ueberschussleistung + $Netzbezug);
|
|
||||||
$Is_Peak_Shaving = false;
|
|
||||||
} else {
|
|
||||||
$remainingPower = $Peakleistung - $Netzbezug;
|
|
||||||
$Is_Peak_Shaving = true;
|
|
||||||
}
|
|
||||||
IPS_LogMessage("Manag anfang", $remainingPower);
|
|
||||||
|
|
||||||
// Alle Energieverbraucher auslesen und dekodieren
|
// Alle Energieverbraucher auslesen und dekodieren
|
||||||
$Verbraucher_Liste = json_decode($this->ReadPropertyString("Verbraucher_Liste"), true);
|
$Verbraucher_Liste = json_decode($this->ReadPropertyString("Verbraucher_Liste"), true);
|
||||||
@@ -120,18 +109,11 @@ class Manager extends IPSModule
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Frage alle Energieverbraucher ab, was sie für Leistungen benötigen könnten
|
|
||||||
foreach ($Verbraucher_Liste as $user) {
|
|
||||||
if (IPS_InstanceExists($user["Verbraucher"])) {
|
|
||||||
IPS_RequestAction($user["Verbraucher"],"GetCurrentData", $Is_Peak_Shaving);
|
|
||||||
IPS_LogMessage("Manager", "aufgerufen getcurrentdata");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$filteredVerbraucher = []; // Array das später mit allen Verbrauchsdaten der Energieverbraucher gefüllt wird
|
$filteredVerbraucher = []; // Array das später mit allen Verbrauchsdaten der Energieverbraucher gefüllt wird
|
||||||
$allIdle = true; // Variable zur Überprüfung, ob alle Benutzer Idle = true sind
|
$allIdle = true; // Variable zur Überprüfung, ob alle Benutzer Idle = true sind
|
||||||
$totalAktuelle_Leistung = 0; // Variable zur Summierung der Aktuelle_Leistung Werte
|
$totalAktuelle_Leistung = 0; // Variable zur Summierung der Aktuelle_Leistung Werte
|
||||||
|
$helpvar_offset_peakermitteln = 0; // Variable zur Summierung der Aktuelle_Leistung Werte
|
||||||
|
|
||||||
// Fülle das Array mit allen entsprechenden Werten der Verbraucher ab
|
// Fülle das Array mit allen entsprechenden Werten der Verbraucher ab
|
||||||
foreach ($Verbraucher_Liste as $user) {
|
foreach ($Verbraucher_Liste as $user) {
|
||||||
@@ -172,7 +154,6 @@ class Manager extends IPSModule
|
|||||||
//if(in_array(0, $powerSteps, true)){
|
//if(in_array(0, $powerSteps, true)){
|
||||||
//if(in_array(0, $powerSteps, true)){
|
//if(in_array(0, $powerSteps, true)){
|
||||||
|
|
||||||
|
|
||||||
//}
|
//}
|
||||||
// Addiere die aktuell bereits verwendete Leistung auf, um sie bei der verteilung zu berücksichtigen
|
// Addiere die aktuell bereits verwendete Leistung auf, um sie bei der verteilung zu berücksichtigen
|
||||||
$totalAktuelle_Leistung += ($Aktuelle_Leistung-$delta);
|
$totalAktuelle_Leistung += ($Aktuelle_Leistung-$delta);
|
||||||
@@ -180,9 +161,79 @@ class Manager extends IPSModule
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Berücksichtigung der bereits verteilten Leistungen (nachher kann dafür wieder bei 0 begonnen werden zu verteilen)
|
// Berücksichtigung der bereits verteilten Leistungen (nachher kann dafür wieder bei 0 begonnen werden zu verteilen)
|
||||||
|
// Systemvariablen abrufen
|
||||||
|
$Netzbezug = GetValue($this->ReadPropertyInteger("Netzbezug"));
|
||||||
|
|
||||||
|
IPS_LogMessage("Leistung Am Anfang", "P" . $totalAktuelle_Leistung);
|
||||||
|
|
||||||
|
|
||||||
|
$Peakleistung = $this->ReadPropertyInteger("Peakleistung");
|
||||||
|
$Ueberschussleistung = $this->ReadPropertyInteger("Ueberschussleistung");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(($this->ReadPropertyBoolean("UmschaltpunktStatisch"))==false){
|
||||||
|
|
||||||
|
// Fallunterscheidung ob auf Solarladen oder Peakshaving gerregelt wird.
|
||||||
|
if ($Netzbezug < ($Peakleistung + $Ueberschussleistung) / 2) {
|
||||||
|
$remainingPower = -1 * (-1 * $Ueberschussleistung + $Netzbezug);
|
||||||
|
$Is_Peak_Shaving = false;
|
||||||
|
} else {
|
||||||
|
$remainingPower = $Peakleistung - $Netzbezug;
|
||||||
|
$Is_Peak_Shaving = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{ // Statische ermittlung der Betriebsart
|
||||||
|
|
||||||
|
if($Netzbezug<($this->ReadPropertyInteger("Umschalt_Solarladen"))){
|
||||||
|
|
||||||
|
$remainingPower = -1 * (-1 * $Ueberschussleistung + $Netzbezug);
|
||||||
|
$Is_Peak_Shaving = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
elseif($Netzbezug>($this->ReadPropertyInteger("Umschalt_Peakshaving"))){
|
||||||
|
|
||||||
|
$remainingPower = $Peakleistung - $Netzbezug;
|
||||||
|
$Is_Peak_Shaving = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
elseif( $this->GetValue("Is_Peak_Shaving")==false){
|
||||||
|
|
||||||
|
$remainingPower = -1 * (-1 * $Ueberschussleistung + $Netzbezug);
|
||||||
|
$Is_Peak_Shaving = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
elseif( $this->GetValue("Is_Peak_Shaving")==true){
|
||||||
|
|
||||||
|
$remainingPower = $Peakleistung - $Netzbezug;
|
||||||
|
$Is_Peak_Shaving = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$remainingPower += $totalAktuelle_Leistung;
|
$remainingPower += $totalAktuelle_Leistung;
|
||||||
|
|
||||||
|
IPS_LogMessage("Manag anfang", $remainingPower);
|
||||||
|
|
||||||
|
// Frage alle Energieverbraucher ab, was sie für Leistungen benötigen könnten
|
||||||
|
foreach ($Verbraucher_Liste as $user) {
|
||||||
|
if (IPS_InstanceExists($user["Verbraucher"])) {
|
||||||
|
IPS_RequestAction($user["Verbraucher"],"GetCurrentData", $Is_Peak_Shaving);
|
||||||
|
IPS_LogMessage("Manager", "aufgerufen getcurrentdata");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Abbrechen wenn es keine gefilterten User gibt
|
// Abbrechen wenn es keine gefilterten User gibt
|
||||||
if (empty($filteredVerbraucher)) {
|
if (empty($filteredVerbraucher)) {
|
||||||
|
|||||||
67
Puffer_Speicher/README.md
Normal file
67
Puffer_Speicher/README.md
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
# Manager_1
|
||||||
|
Beschreibung des Moduls.
|
||||||
|
|
||||||
|
### Inhaltsverzeichnis
|
||||||
|
|
||||||
|
1. [Funktionsumfang](#1-funktionsumfang)
|
||||||
|
2. [Voraussetzungen](#2-voraussetzungen)
|
||||||
|
3. [Software-Installation](#3-software-installation)
|
||||||
|
4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon)
|
||||||
|
5. [Statusvariablen und Profile](#5-statusvariablen-und-profile)
|
||||||
|
6. [WebFront](#6-webfront)
|
||||||
|
7. [PHP-Befehlsreferenz](#7-php-befehlsreferenz)
|
||||||
|
|
||||||
|
### 1. Funktionsumfang
|
||||||
|
|
||||||
|
*
|
||||||
|
|
||||||
|
### 2. Voraussetzungen
|
||||||
|
|
||||||
|
- IP-Symcon ab Version 7.1
|
||||||
|
|
||||||
|
### 3. Software-Installation
|
||||||
|
|
||||||
|
* Über den Module Store das 'Manager_1'-Modul installieren.
|
||||||
|
* Alternativ über das Module Control folgende URL hinzufügen
|
||||||
|
|
||||||
|
### 4. Einrichten der Instanzen in IP-Symcon
|
||||||
|
|
||||||
|
Unter 'Instanz hinzufügen' kann das 'Manager_1'-Modul mithilfe des Schnellfilters gefunden werden.
|
||||||
|
- Weitere Informationen zum Hinzufügen von Instanzen in der [Dokumentation der Instanzen](https://www.symcon.de/service/dokumentation/konzepte/instanzen/#Instanz_hinzufügen)
|
||||||
|
|
||||||
|
__Konfigurationsseite__:
|
||||||
|
|
||||||
|
Name | Beschreibung
|
||||||
|
-------- | ------------------
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
||||||
|
### 5. Statusvariablen und Profile
|
||||||
|
|
||||||
|
Die Statusvariablen/Kategorien werden automatisch angelegt. Das Löschen einzelner kann zu Fehlfunktionen führen.
|
||||||
|
|
||||||
|
#### Statusvariablen
|
||||||
|
|
||||||
|
Name | Typ | Beschreibung
|
||||||
|
------ | ------- | ------------
|
||||||
|
| |
|
||||||
|
| |
|
||||||
|
|
||||||
|
#### Profile
|
||||||
|
|
||||||
|
Name | Typ
|
||||||
|
------ | -------
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
||||||
|
### 6. WebFront
|
||||||
|
|
||||||
|
Die Funktionalität, die das Modul im WebFront bietet.
|
||||||
|
|
||||||
|
### 7. PHP-Befehlsreferenz
|
||||||
|
|
||||||
|
`boolean GEF_BeispielFunktion(integer $InstanzID);`
|
||||||
|
Erklärung der Funktion.
|
||||||
|
|
||||||
|
Beispiel:
|
||||||
|
`GEF_BeispielFunktion(12345);`
|
||||||
118
Puffer_Speicher/form.json
Normal file
118
Puffer_Speicher/form.json
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
{
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"type": "Label",
|
||||||
|
"caption": "Konfiguration der nötigen Schaltkontakte und Nennleistungen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type":"Select",
|
||||||
|
"name":"Puffertemperatur_glätten",
|
||||||
|
"caption":"Puffertemperatur glätten",
|
||||||
|
"options":[
|
||||||
|
{
|
||||||
|
"caption":"Ja",
|
||||||
|
"value":true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"caption":"Nein",
|
||||||
|
"value":false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "ZeitKonstante",
|
||||||
|
"caption": "Zeit Konstante",
|
||||||
|
"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": "IdleCounterMax",
|
||||||
|
"caption": "Zyklen zwischen zwei Leistungsänderungen (Multipliziert sich mit Interval)",
|
||||||
|
"suffix": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type":"List",
|
||||||
|
"name":"LeistungsStufen",
|
||||||
|
"caption":"Anzahl Stufen mit den dazugehörigen Leistungen",
|
||||||
|
"add":true,
|
||||||
|
"delete":true,
|
||||||
|
"columns":[
|
||||||
|
{
|
||||||
|
"caption":"Stufe(n)",
|
||||||
|
"name":"Stufe",
|
||||||
|
"width":"200px",
|
||||||
|
"add":"Stufe",
|
||||||
|
"edit":{
|
||||||
|
"type":"NumberSpinner"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"caption":"Leistung in W",
|
||||||
|
"name":"Leistung",
|
||||||
|
"width":"300px",
|
||||||
|
"add":0,
|
||||||
|
"edit":{
|
||||||
|
"type":"NumberSpinner"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"caption":"Schaltkontakt",
|
||||||
|
"name":"Schaltkontakt_Stufe",
|
||||||
|
"width":"400px",
|
||||||
|
"add":0,
|
||||||
|
"edit":{
|
||||||
|
"type":"SelectVariable"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "Label",
|
||||||
|
"caption": "Endpunkte der Pufferfunktion bestimmen: VT = f(AT)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "MaxVT_Temp",
|
||||||
|
"caption": "Max Temperatur VT",
|
||||||
|
"suffix": "°C"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "MinVT_Temp",
|
||||||
|
"caption": "Min Temperatur VT",
|
||||||
|
"suffix": "°C"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "MaxAT_Temp",
|
||||||
|
"caption": "Max Temperatur AT",
|
||||||
|
"suffix": "°C"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "NumberSpinner",
|
||||||
|
"name": "MinAT_Temp",
|
||||||
|
"caption": "Min Temperatur AT",
|
||||||
|
"suffix": "°C"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SelectVariable",
|
||||||
|
"name": "Pufferfuehler_PT1",
|
||||||
|
"caption": "Variable für Pufferfühler PT1",
|
||||||
|
"test": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SelectVariable",
|
||||||
|
"name": "Aussentemp",
|
||||||
|
"caption": "Aussentemperatur",
|
||||||
|
"suffix": "°C"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
12
Puffer_Speicher/module.json
Normal file
12
Puffer_Speicher/module.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"id": "{9F6C34D1-4D5B-37E3-5BE5-1538A2F27C2A}",
|
||||||
|
"name": "Puffer_Speicher",
|
||||||
|
"type": 3,
|
||||||
|
"vendor": "Belevo AG",
|
||||||
|
"aliases": [],
|
||||||
|
"parentRequirements": [],
|
||||||
|
"childRequirements": [],
|
||||||
|
"implemented": [],
|
||||||
|
"prefix": "GEF",
|
||||||
|
"url": ""
|
||||||
|
}
|
||||||
292
Puffer_Speicher/module.php
Normal file
292
Puffer_Speicher/module.php
Normal file
@@ -0,0 +1,292 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Puffer_Speicher extends IPSModule
|
||||||
|
{
|
||||||
|
private array $leistungArray = [];
|
||||||
|
|
||||||
|
public function Create()
|
||||||
|
{
|
||||||
|
parent::Create();
|
||||||
|
|
||||||
|
|
||||||
|
$this->RegisterPropertyString("LeistungsStufen", json_encode([])); // Bezeichnung der Liste
|
||||||
|
$this->RegisterPropertyInteger("ZeitKonstante", 120);
|
||||||
|
$this->RegisterPropertyInteger("Pufferfuehler_PT1", 0);
|
||||||
|
$this->RegisterPropertyInteger("Aussentemp", 20);
|
||||||
|
$this->RegisterPropertyInteger("MinVT_Temp", 20);
|
||||||
|
$this->RegisterPropertyInteger("MaxVT_Temp", 80);
|
||||||
|
$this->RegisterPropertyInteger("MaxAT_Temp", 20);
|
||||||
|
$this->RegisterPropertyInteger("MinAT_Temp", 0);
|
||||||
|
$this->RegisterPropertyBoolean("Puffertemperatur_glätten", false);
|
||||||
|
$this->RegisterPropertyString("Zeitplan", "");
|
||||||
|
$this->RegisterPropertyInteger("Interval", 5); // Recheninterval
|
||||||
|
|
||||||
|
|
||||||
|
// Puffer spezifische Variablen
|
||||||
|
$this->RegisterVariableInteger("Steigung","Steigung","",0);
|
||||||
|
$this->RegisterVariableInteger("Maximaltemperatur"," Berechnete Maximaltemperatur VT","",60);
|
||||||
|
$this->RegisterVariableInteger("Puffertemperatur", "Puffertemperatur", "", 40);
|
||||||
|
$this->RegisterVariableInteger("Aussentemperatur", "Aussentemperatur", "", 15);
|
||||||
|
$this->RegisterVariableBoolean("Hysterese", "Hysterese","",false);
|
||||||
|
|
||||||
|
|
||||||
|
// 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", '', 0);
|
||||||
|
$this->RegisterVariableBoolean("Is_Peak_Shaving", "Is_Peak_Shaving", "", true);
|
||||||
|
$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_Boiler",$this->ReadPropertyInteger("Interval")*1000,"IPS_RequestAction(" .$this->InstanceID .', "Do_UserCalc", "");');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ApplyChanges()
|
||||||
|
{
|
||||||
|
parent::ApplyChanges();
|
||||||
|
$this->SetTimerInterval("Timer_Do_UserCalc_Boiler",$this->ReadPropertyInteger("Interval")*1000);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function LadeUndSortiereLeistungen()
|
||||||
|
{
|
||||||
|
// Array initialisieren, immer mit 0
|
||||||
|
$this->leistungArray = [0];
|
||||||
|
|
||||||
|
// JSON aus der Property auslesen
|
||||||
|
$json = $this->ReadPropertyString("LeistungsStufen");
|
||||||
|
$leistungsStufen = json_decode($json, true);
|
||||||
|
|
||||||
|
if (is_array($leistungsStufen)) {
|
||||||
|
foreach ($leistungsStufen as $stufe) {
|
||||||
|
$this->leistungArray[] = $stufe['Leistung'] ?? 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Array sortieren (Bubble Sort)
|
||||||
|
$len = count($this->leistungArray);
|
||||||
|
for ($i = 0; $i < $len - 1; $i++) {
|
||||||
|
for ($j = 0; $j < $len - $i - 1; $j++) {
|
||||||
|
if ($this->leistungArray[$j] > $this->leistungArray[$j + 1]) {
|
||||||
|
$temp = $this->leistungArray[$j];
|
||||||
|
$this->leistungArray[$j] = $this->leistungArray[$j + 1];
|
||||||
|
$this->leistungArray[$j + 1] = $temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Methode zum Setzen des aktuellen Stromverbrauchs
|
||||||
|
public function SetAktuelle_Leistung(int $power)
|
||||||
|
{
|
||||||
|
// Lade sicherheitshalber das aktuelle LeistungArray
|
||||||
|
$this->LadeUndSortiereLeistungen();
|
||||||
|
|
||||||
|
// Schleife über alle Leistungsstufen
|
||||||
|
foreach ($this->leistungArray as $leistung) {
|
||||||
|
$kontaktID = $this->GetKontaktIDZuLeistung($leistung);
|
||||||
|
|
||||||
|
// Prüfen, ob Variable existiert und gültige ID
|
||||||
|
if ($kontaktID > 0 && IPS_VariableExists($kontaktID)) {
|
||||||
|
// Setze TRUE für die aktuelle Leistungsstufe, FALSE für alle anderen
|
||||||
|
SetValue($kontaktID, ($leistung === $power));
|
||||||
|
} else {
|
||||||
|
if ($kontaktID > 0) {
|
||||||
|
IPS_LogMessage("ERROR", "KontaktID $kontaktID existiert nicht oder ist ungültig!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Prüfe auf Änderung der Power 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private function GetKontaktIDZuLeistung(int $leistung): int
|
||||||
|
{
|
||||||
|
$json = $this->ReadPropertyString("LeistungsStufen");
|
||||||
|
$leistungsStufen = json_decode($json, true);
|
||||||
|
|
||||||
|
if (is_array($leistungsStufen)) {
|
||||||
|
foreach ($leistungsStufen as $stufe) {
|
||||||
|
if (($stufe['Leistung'] ?? 0) == $leistung) {
|
||||||
|
return $stufe['Schaltkontakt_Stufe'] ?? 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Methode zum Abrufen der aktuellen Daten
|
||||||
|
public function GetCurrentData(bool $Peak)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->LadeUndSortiereLeistungen();
|
||||||
|
$boilertemperatur_glätten = $this->ReadPropertyBoolean("Puffertemperatur_glätten");
|
||||||
|
if ($boilertemperatur_glätten) {
|
||||||
|
// Wenn Glättung aktiviert ist, führe das Glätten durch
|
||||||
|
$boilerFuehlerPT1ID = $this->ReadPropertyInteger("Pufferfuehler_PT1");
|
||||||
|
|
||||||
|
if (IPS_VariableExists($boilerFuehlerPT1ID)) {
|
||||||
|
$boilerPT1 = GetValue($boilerFuehlerPT1ID);
|
||||||
|
} else {
|
||||||
|
$boilerPT1 = 0.0; // Standardwert
|
||||||
|
}
|
||||||
|
|
||||||
|
$boilerTempID = $this->GetIDForIdent("Boilertemperatur");
|
||||||
|
if (IPS_VariableExists($boilerTempID)) {
|
||||||
|
$boilerTemp = $this->GetValue("Boilertemperatur");
|
||||||
|
} else {
|
||||||
|
$boilerTemp = 0.0; // Standardwert
|
||||||
|
}
|
||||||
|
|
||||||
|
// PT
|
||||||
|
$time_constant= $this->ReadPropertyInteger("ZeitKonstante");
|
||||||
|
$delta_t = 5; // Zeitdifferenz zwischen den Messungen (30 Sekunden)
|
||||||
|
$alpha = $delta_t / ($time_constant + $delta_t);
|
||||||
|
$newBoilerTemp = $boilerTemp + $alpha * ($boilerPT1 - $boilerTemp);
|
||||||
|
$this->SetValue("Puffertemperatur", $newBoilerTemp);
|
||||||
|
} else {
|
||||||
|
// Wenn Glättung nicht aktiviert ist, setze die Boilertemperatur direkt auf den Wert des Boilerfühlers
|
||||||
|
$boilerFuehlerPT1ID = $this->ReadPropertyInteger("Pufferfuehler_PT1");
|
||||||
|
|
||||||
|
if (IPS_VariableExists($boilerFuehlerPT1ID)) {
|
||||||
|
$boilerPT1 = GetValue($boilerFuehlerPT1ID);
|
||||||
|
} else {
|
||||||
|
$boilerPT1 = 0.0; // Standardwert
|
||||||
|
}
|
||||||
|
// Setze Boilertemperatur direkt auf den Wert des Boilerfühlers
|
||||||
|
$this->SetValue("Puffertemperatur", $boilerPT1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$at = GetValue($this->ReadPropertyInteger("Aussentemp"));
|
||||||
|
$this->SetValue("Aussentemperatur", $at);
|
||||||
|
$m = $this->GetValue("Steigung");
|
||||||
|
$minVT = $this->ReadPropertyInteger("MinVT_Temp"); // z.B. 20
|
||||||
|
$maxVT = $this->ReadPropertyInteger("MaxVT_Temp"); // z.B. 80
|
||||||
|
$maxAT = $this->ReadPropertyInteger("MaxAT_Temp"); // z.B. 20
|
||||||
|
$minAT = $this->ReadPropertyInteger("MinAT_Temp"); // z.B. 0
|
||||||
|
$m = ($maxVT - $minVT) / ($minAT - $maxAT);
|
||||||
|
$this->SetValue("Steigung", $m);
|
||||||
|
if ($at < $minAT){
|
||||||
|
$VT = $maxVT;
|
||||||
|
} elseif ($at > $maxAT){
|
||||||
|
$VT = $minVT;
|
||||||
|
} else {
|
||||||
|
$VT = $m * $at + $maxVT;
|
||||||
|
}
|
||||||
|
$this->SetValue("Maximaltemperatur", $VT );
|
||||||
|
$boilerTemp = $this->GetValue("Puffertemperatur");
|
||||||
|
$hyst = $this->GetValue("Hysterese");
|
||||||
|
|
||||||
|
if($VT < $boilerTemp){
|
||||||
|
$this->SetValue("Hysterese", false );
|
||||||
|
}elseif($VT-5 >= $boilerTemp){
|
||||||
|
$this->SetValue("Hysterese", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
IPS_LogMessage("LeistungArray_Get", json_encode($this->leistungArray));
|
||||||
|
|
||||||
|
if ($Peak) {
|
||||||
|
$this->SetValue( "PowerSteps", json_encode([0]) );
|
||||||
|
} else {
|
||||||
|
if ($boilerTemp < $VT && $hyst== true) {
|
||||||
|
$this->SetValue("PowerSteps", json_encode($this->leistungArray));
|
||||||
|
} elseif ($boilerTemp > $VT - 5 && $hyst== false) {
|
||||||
|
$this->SetValue("PowerSteps", json_encode([0]));
|
||||||
|
} else {
|
||||||
|
$this->SetValue("PowerSteps", json_encode([0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
67
Pufferspeicher_def/README.md
Normal file
67
Pufferspeicher_def/README.md
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
# Manager_1
|
||||||
|
Beschreibung des Moduls.
|
||||||
|
|
||||||
|
### Inhaltsverzeichnis
|
||||||
|
|
||||||
|
1. [Funktionsumfang](#1-funktionsumfang)
|
||||||
|
2. [Voraussetzungen](#2-voraussetzungen)
|
||||||
|
3. [Software-Installation](#3-software-installation)
|
||||||
|
4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon)
|
||||||
|
5. [Statusvariablen und Profile](#5-statusvariablen-und-profile)
|
||||||
|
6. [WebFront](#6-webfront)
|
||||||
|
7. [PHP-Befehlsreferenz](#7-php-befehlsreferenz)
|
||||||
|
|
||||||
|
### 1. Funktionsumfang
|
||||||
|
|
||||||
|
*
|
||||||
|
|
||||||
|
### 2. Voraussetzungen
|
||||||
|
|
||||||
|
- IP-Symcon ab Version 7.1
|
||||||
|
|
||||||
|
### 3. Software-Installation
|
||||||
|
|
||||||
|
* Über den Module Store das 'Manager_1'-Modul installieren.
|
||||||
|
* Alternativ über das Module Control folgende URL hinzufügen
|
||||||
|
|
||||||
|
### 4. Einrichten der Instanzen in IP-Symcon
|
||||||
|
|
||||||
|
Unter 'Instanz hinzufügen' kann das 'Manager_1'-Modul mithilfe des Schnellfilters gefunden werden.
|
||||||
|
- Weitere Informationen zum Hinzufügen von Instanzen in der [Dokumentation der Instanzen](https://www.symcon.de/service/dokumentation/konzepte/instanzen/#Instanz_hinzufügen)
|
||||||
|
|
||||||
|
__Konfigurationsseite__:
|
||||||
|
|
||||||
|
Name | Beschreibung
|
||||||
|
-------- | ------------------
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
||||||
|
### 5. Statusvariablen und Profile
|
||||||
|
|
||||||
|
Die Statusvariablen/Kategorien werden automatisch angelegt. Das Löschen einzelner kann zu Fehlfunktionen führen.
|
||||||
|
|
||||||
|
#### Statusvariablen
|
||||||
|
|
||||||
|
Name | Typ | Beschreibung
|
||||||
|
------ | ------- | ------------
|
||||||
|
| |
|
||||||
|
| |
|
||||||
|
|
||||||
|
#### Profile
|
||||||
|
|
||||||
|
Name | Typ
|
||||||
|
------ | -------
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
||||||
|
### 6. WebFront
|
||||||
|
|
||||||
|
Die Funktionalität, die das Modul im WebFront bietet.
|
||||||
|
|
||||||
|
### 7. PHP-Befehlsreferenz
|
||||||
|
|
||||||
|
`boolean GEF_BeispielFunktion(integer $InstanzID);`
|
||||||
|
Erklärung der Funktion.
|
||||||
|
|
||||||
|
Beispiel:
|
||||||
|
`GEF_BeispielFunktion(12345);`
|
||||||
5
Pufferspeicher_def/form.json
Normal file
5
Pufferspeicher_def/form.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"elements": [
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
||||||
12
Pufferspeicher_def/module.json
Normal file
12
Pufferspeicher_def/module.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"id": "{987DD1AD-810D-23F0-3AE9-7349FED4A1DA}",
|
||||||
|
"name": "Pufferspeicher_def",
|
||||||
|
"type": 3,
|
||||||
|
"vendor": "Belevo AG",
|
||||||
|
"aliases": [],
|
||||||
|
"parentRequirements": [],
|
||||||
|
"childRequirements": [],
|
||||||
|
"implemented": [],
|
||||||
|
"prefix": "GEF",
|
||||||
|
"url": ""
|
||||||
|
}
|
||||||
14
Pufferspeicher_def/module.php
Normal file
14
Pufferspeicher_def/module.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
<?php
|
||||||
|
class Pufferspeicher_def extends IPSModule
|
||||||
|
{
|
||||||
|
public function Create()
|
||||||
|
{
|
||||||
|
parent::Create();
|
||||||
|
}
|
||||||
|
public function ApplyChanges()
|
||||||
|
{
|
||||||
|
parent::ApplyChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
160
temp_head.txt
Normal file
160
temp_head.txt
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
include_once __DIR__ . '/libs/vendor/autoload.php'; // TCPDF via Composer
|
||||||
|
|
||||||
|
class Abrechnung extends IPSModule
|
||||||
|
{
|
||||||
|
public function Create()
|
||||||
|
{
|
||||||
|
parent::Create();
|
||||||
|
|
||||||
|
// Eigenschaften
|
||||||
|
$this->RegisterPropertyString('Users', '[]');
|
||||||
|
$this->RegisterPropertyString('PowerMeters', '[]');
|
||||||
|
$this->RegisterPropertyString('WaterMeters', '[]');
|
||||||
|
$this->RegisterPropertyString('Tariffs', '[]');
|
||||||
|
|
||||||
|
// Variablen
|
||||||
|
$this->RegisterVariableInteger('FromDate', 'Startdatum', '~UnixTimestamp', 1);
|
||||||
|
$this->RegisterVariableInteger('ToDate', 'Enddatum', '~UnixTimestamp', 2);
|
||||||
|
$this->RegisterVariableString('LastResult', 'Letzte Abrechnung', '', 3);
|
||||||
|
$this->EnableAction('FromDate');
|
||||||
|
$this->EnableAction('ToDate');
|
||||||
|
|
||||||
|
// Abrechnungs-Button
|
||||||
|
$this->RegisterScript('StartBilling', 'Abrechnung starten', "<?php IPS_RequestAction(" . $this->InstanceID . ", 'StartBilling', ''); ?>");
|
||||||
|
|
||||||
|
// 🧾 Media-Objekt für PDF-Ergebnis
|
||||||
|
$this->RegisterMediaDocument('InvoicePDF', 'Letzte Rechnung', 'pdf');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ApplyChanges()
|
||||||
|
{
|
||||||
|
parent::ApplyChanges();
|
||||||
|
IPS_LogMessage('Abrechnung', 'Modul geladen');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function RegisterMediaDocument($Ident, $Name, $Extension, $Position = 0)
|
||||||
|
{
|
||||||
|
$mid = @IPS_GetObjectIDByIdent($Ident, $this->InstanceID);
|
||||||
|
if ($mid === false) {
|
||||||
|
$mid = IPS_CreateMedia(5); // 5 = Document
|
||||||
|
IPS_SetParent($mid, $this->InstanceID);
|
||||||
|
IPS_SetIdent($mid, $Ident);
|
||||||
|
IPS_SetName($mid, $Name);
|
||||||
|
IPS_SetPosition($mid, $Position);
|
||||||
|
IPS_SetMediaFile($mid, 'media/' . $mid . '.' . $Extension, false);
|
||||||
|
IPS_LogMessage('Abrechnung', 'Media-Datei erstellt: media/' . $mid . '.' . $Extension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function RequestAction($Ident, $Value)
|
||||||
|
{
|
||||||
|
IPS_LogMessage('Abrechnung', "RequestAction: $Ident");
|
||||||
|
|
||||||
|
switch ($Ident) {
|
||||||
|
case 'FromDate':
|
||||||
|
case 'ToDate':
|
||||||
|
SetValue($this->GetIDForIdent($Ident), $Value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'StartBilling':
|
||||||
|
IPS_LogMessage('Abrechnung', 'Starte Abrechnung...');
|
||||||
|
try {
|
||||||
|
$pdfContent = $this->GenerateInvoices();
|
||||||
|
if ($pdfContent === false) {
|
||||||
|
IPS_LogMessage('Abrechnung', '❌ GenerateInvoices() lieferte false zurück');
|
||||||
|
echo "❌ Fehler bei der PDF-Erstellung (GenerateInvoices)";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($pdfContent === null) {
|
||||||
|
IPS_LogMessage('Abrechnung', '❌ GenerateInvoices() gab null zurück');
|
||||||
|
echo "❌ Fehler bei der PDF-Erstellung (leer)";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (strlen($pdfContent) < 100) {
|
||||||
|
IPS_LogMessage('Abrechnung', '❌ PDF-Inhalt zu kurz: ' . strlen($pdfContent));
|
||||||
|
echo "❌ Fehler bei der PDF-Erstellung (leeres PDF)";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mediaID = $this->GetIDForIdent('InvoicePDF');
|
||||||
|
if (!$mediaID) {
|
||||||
|
IPS_LogMessage('Abrechnung', '❌ Media-ID nicht gefunden');
|
||||||
|
echo "❌ Kein Media-Objekt vorhanden";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPS_SetMediaContent($mediaID, base64_encode($pdfContent));
|
||||||
|
SetValue($this->GetIDForIdent('LastResult'), 'Abrechnung vom ' . date('d.m.Y H:i'));
|
||||||
|
IPS_LogMessage('Abrechnung', '✅ Abrechnung erfolgreich gespeichert (' . strlen($pdfContent) . ' Bytes)');
|
||||||
|
echo "✅ PDF erfolgreich erstellt.";
|
||||||
|
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
IPS_LogMessage('Abrechnung', '💥 Exception in StartBilling: ' . $e->getMessage());
|
||||||
|
echo "❌ Ausnahmefehler: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ====================== PDF-Logik ======================
|
||||||
|
|
||||||
|
public function GenerateInvoices()
|
||||||
|
{
|
||||||
|
$from = GetValue($this->GetIDForIdent('FromDate'));
|
||||||
|
$to = GetValue($this->GetIDForIdent('ToDate'));
|
||||||
|
|
||||||
|
IPS_LogMessage('Abrechnung', '🕒 Starte GenerateInvoices()');
|
||||||
|
IPS_LogMessage('Abrechnung', 'Zeitraum von ' . date('d.m.Y H:i', $from) . ' bis ' . date('d.m.Y H:i', $to));
|
||||||
|
|
||||||
|
$users = json_decode($this->ReadPropertyString('Users'), true);
|
||||||
|
$power = json_decode($this->ReadPropertyString('PowerMeters'), true);
|
||||||
|
$water = json_decode($this->ReadPropertyString('WaterMeters'), true);
|
||||||
|
$tariffs = json_decode($this->ReadPropertyString('Tariffs'), true);
|
||||||
|
|
||||||
|
if (!class_exists('TCPDF')) {
|
||||||
|
IPS_LogMessage('Abrechnung', '❌ TCPDF fehlt – prüfe libs/vendor/autoload.php');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
|
||||||
|
$pdf->SetCreator('IPSymcon Abrechnung');
|
||||||
|
$pdf->SetMargins(15, 15, 15);
|
||||||
|
$pdf->SetAutoPageBreak(true, 20);
|
||||||
|
$pdf->SetFont('dejavusans', '', 10);
|
||||||
|
|
||||||
|
foreach ($users as $user) {
|
||||||
|
IPS_LogMessage('Abrechnung', '→ Erstelle Seite für Benutzer: ' . $user['name']);
|
||||||
|
$pdf->AddPage();
|
||||||
|
|
||||||
|
// 🔽 Hier fügst du den neuen HTML-Block ein:
|
||||||
|
$html = "
|
||||||
|
<h2>Rechnung für {$user['name']}</h2>
|
||||||
|
<p>{$user['address']}<br>{$user['city']}</p>
|
||||||
|
<table border='1' cellpadding='2' style='font-size:8px;'>
|
||||||
|
<tr style='background-color:#e0e0e0;'>
|
||||||
|
<th>Zähler</th>
|
||||||
|
<th>Typ</th>
|
||||||
|
<th>Startzeit</th>
|
||||||
|
<th>Endzeit</th>
|
||||||
|
<th>Zählerstand Start</th>
|
||||||
|
<th>Zählerstand Ende</th>
|
||||||
|
<th>Verbrauch</th>
|
||||||
|
<th>Tarif (Rp)</th>
|
||||||
|
<th>Kosten (CHF)</th>
|
||||||
|
</tr>
|
||||||
|
";
|
||||||
|
|
||||||
|
$total = 0.0;
|
||||||
|
foreach ($power as $m) {
|
||||||
|
if ($m['user_id'] != $user['id']) continue;
|
||||||
|
$cost = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, 'Strombezug');
|
||||||
|
$html .= $cost['row'];
|
||||||
|
$total += $cost['value'];
|
||||||
|
}
|
||||||
|
foreach ($water as $m) {
|
||||||
|
if ($m['user_id'] != $user['id']) continue;
|
||||||
190
temp_mid.txt
Normal file
190
temp_mid.txt
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
$type = $m['meter_type'] ?? 'Warmwasser';
|
||||||
|
$cost = $this->AddMeterToPDFRow($m, $tariffs, $from, $to, $type);
|
||||||
|
$html .= $cost['row'];
|
||||||
|
$total += $cost['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$html .= "</table><h3>Gesamtsumme: " . number_format($total, 2) . " CHF</h3>";
|
||||||
|
$pdf->writeHTML($html);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
IPS_LogMessage('Abrechnung', '✅ PDF-Daten fertiggestellt');
|
||||||
|
return $pdf->Output('Abrechnung.pdf', 'S');
|
||||||
|
|
||||||
|
} catch (Throwable $e) {
|
||||||
|
IPS_LogMessage('Abrechnung', '💥 Exception in TCPDF: ' . $e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function AddMeterToPDF($pdf, $meter, $tariffs, $from, $to, $type)
|
||||||
|
{
|
||||||
|
$start = $this->GetValueAt($meter['var_consumption'], $from);
|
||||||
|
$end = $this->GetValueAt($meter['var_consumption'], $to);
|
||||||
|
if ($start === null || $end === null) return 0;
|
||||||
|
|
||||||
|
$diff = max(0, $end - $start);
|
||||||
|
$tariffRp = $this->GetTariff($tariffs, $type, $from, $to);
|
||||||
|
$cost = ($tariffRp / 100) * $diff;
|
||||||
|
|
||||||
|
$pdf->writeHTML("
|
||||||
|
<tr>
|
||||||
|
<td>{$meter['name']}</td>
|
||||||
|
<td>$type</td>
|
||||||
|
<td>$start</td>
|
||||||
|
<td>$end</td>
|
||||||
|
<td>$diff</td>
|
||||||
|
<td>$tariffRp</td>
|
||||||
|
<td>" . number_format($cost, 2) . "</td>
|
||||||
|
</tr>", false, false, false, false, '');
|
||||||
|
|
||||||
|
return $cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetTariff(array $tariffs, string $type, int $from, int $to): float
|
||||||
|
{
|
||||||
|
foreach ($tariffs as $t) {
|
||||||
|
$start = strtotime($t['start']);
|
||||||
|
$end = strtotime($t['end']);
|
||||||
|
if ($from >= $start && $to <= $end && strtolower($t['unit_type']) == strtolower($type)) {
|
||||||
|
return floatval($t['price']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Kein passender Tarif gefunden
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetValueAt(int $varId, int $timestamp, bool $nearestAfter = true)
|
||||||
|
{
|
||||||
|
$archiveID = @IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0];
|
||||||
|
if (!$archiveID || !IPS_VariableExists($varId)) {
|
||||||
|
IPS_LogMessage('Abrechnung', "❌ Variable $varId oder Archiv $archiveID nicht gefunden");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$maxDays = 365; // maximal 1 Jahr suchen
|
||||||
|
$stepDays = 30; // in 30-Tage-Blöcken durchsuchen
|
||||||
|
$valueFound = null;
|
||||||
|
|
||||||
|
if ($nearestAfter) {
|
||||||
|
// 🔹 Suche den ersten Wert NACH dem gewünschten Zeitpunkt
|
||||||
|
for ($offset = 0; $offset < $maxDays; $offset += $stepDays) {
|
||||||
|
$from = $timestamp + $offset * 86400;
|
||||||
|
$to = $from + $stepDays * 86400;
|
||||||
|
$values = @AC_GetLoggedValues($archiveID, $varId, $from, $to, 0);
|
||||||
|
if (!empty($values)) {
|
||||||
|
// ersten Wert nach Timestamp nehmen
|
||||||
|
foreach ($values as $v) {
|
||||||
|
if ($v['TimeStamp'] >= $timestamp) {
|
||||||
|
$valueFound = floatval($v['Value']);
|
||||||
|
break 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 🔹 Suche den letzten Wert VOR dem gewünschten Zeitpunkt
|
||||||
|
for ($offset = 0; $offset < $maxDays; $offset += $stepDays) {
|
||||||
|
$from = $timestamp - ($offset + $stepDays) * 86400;
|
||||||
|
$to = $timestamp - $offset * 86400;
|
||||||
|
$values = @AC_GetLoggedValues($archiveID, $varId, $from, $to, 0);
|
||||||
|
if (!empty($values)) {
|
||||||
|
// letzten Wert vor Timestamp nehmen
|
||||||
|
$last = null;
|
||||||
|
foreach ($values as $v) {
|
||||||
|
if ($v['TimeStamp'] <= $timestamp) {
|
||||||
|
$last = $v;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($last !== null) {
|
||||||
|
$valueFound = floatval($last['Value']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 Falls nichts im Archiv: aktuellen Variablenwert nehmen
|
||||||
|
if ($valueFound === null) {
|
||||||
|
$fallback = floatval(GetValue($varId));
|
||||||
|
IPS_LogMessage('Abrechnung', "⚠ Kein Archivwert für $varId gefunden – nutze aktuellen Wert ($fallback)");
|
||||||
|
return $fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $valueFound;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function AddMeterToPDFRow($meter, $tariffs, $from, $to, $type)
|
||||||
|
{
|
||||||
|
$rows = '';
|
||||||
|
$totalCost = 0.0;
|
||||||
|
$varId = $meter['var_consumption'];
|
||||||
|
|
||||||
|
IPS_LogMessage('Abrechnung', "🔧 [AddMeterToPDFRow] Starte für '{$meter['name']}' (Typ: {$type}) von " . date('d.m.Y H:i', $from) . " bis " . date('d.m.Y H:i', $to));
|
||||||
|
|
||||||
|
if (!IPS_VariableExists($varId)) {
|
||||||
|
IPS_LogMessage('Abrechnung', "❌ Variable {$varId} für {$meter['name']} nicht gefunden");
|
||||||
|
return ['row' => '', 'value' => 0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zeitzone setzen, um strtotime()-Abweichungen zu vermeiden
|
||||||
|
date_default_timezone_set('Europe/Zurich');
|
||||||
|
|
||||||
|
// 1️⃣ Relevante Tarife nach Typ filtern
|
||||||
|
$filteredTariffs = array_filter($tariffs, function ($t) use ($type) {
|
||||||
|
return strtolower(trim($t['unit_type'] ?? '')) === strtolower(trim($type));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (empty($filteredTariffs)) {
|
||||||
|
IPS_LogMessage('Abrechnung', "⚠ Keine passenden Tarife für {$type} gefunden");
|
||||||
|
return ['row' => '', 'value' => 0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2️⃣ Zeitstempel konvertieren, JSON-Objekte erkennen & sortieren
|
||||||
|
foreach ($filteredTariffs as &$t) {
|
||||||
|
// JSON-Fix: Start/Ende evtl. verschachtelt
|
||||||
|
if (is_string($t['start']) && str_starts_with(trim($t['start']), '{')) {
|
||||||
|
$s = json_decode($t['start'], true);
|
||||||
|
if (is_array($s)) {
|
||||||
|
$t['start'] = sprintf('%04d-%02d-%02d 00:00:00', $s['year'], $s['month'], $s['day']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_string($t['end']) && str_starts_with(trim($t['end']), '{')) {
|
||||||
|
$e = json_decode($t['end'], true);
|
||||||
|
if (is_array($e)) {
|
||||||
|
$t['end'] = sprintf('%04d-%02d-%02d 23:59:59', $e['year'], $e['month'], $e['day']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$t['start_ts'] = is_numeric($t['start']) ? intval($t['start']) : strtotime($t['start']);
|
||||||
|
$t['end_ts'] = is_numeric($t['end']) ? intval($t['end']) : strtotime($t['end']);
|
||||||
|
|
||||||
|
if (!$t['start_ts'] || !$t['end_ts']) {
|
||||||
|
IPS_LogMessage('Abrechnung', "⚠ Ungültiger Tarifzeitraum: " . json_encode($t));
|
||||||
|
} else {
|
||||||
|
IPS_LogMessage('Abrechnung', sprintf(
|
||||||
|
" 🕓 Tarif gültig von %s bis %s @ %.3f Rp",
|
||||||
|
date('d.m.Y H:i', $t['start_ts']),
|
||||||
|
date('d.m.Y H:i', $t['end_ts']),
|
||||||
|
floatval($t['price'])
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($t);
|
||||||
|
usort($filteredTariffs, fn($a, $b) => $a['start_ts'] <=> $b['start_ts']);
|
||||||
|
|
||||||
|
// 3️⃣ Abrechnungslogik
|
||||||
|
$currentStart = $from;
|
||||||
|
$segmentIndex = 1;
|
||||||
|
|
||||||
|
while ($currentStart < $to) {
|
||||||
|
IPS_LogMessage('Abrechnung', "➡️ Segment {$segmentIndex} Startzeit: " . date('d.m.Y H:i', $currentStart));
|
||||||
|
|
||||||
|
// 🔹 Aktiven Tarif bestimmen (FIX: <= auch am Ende erlaubt)
|
||||||
|
$activeTariff = null;
|
||||||
106
temp_mid2.txt
Normal file
106
temp_mid2.txt
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
foreach ($filteredTariffs as $t) {
|
||||||
|
$startTs = intval($t['start_ts']);
|
||||||
|
$endTs = intval($t['end_ts']);
|
||||||
|
if ($startTs === 0 || $endTs === 0) continue;
|
||||||
|
|
||||||
|
if ($startTs <= $currentStart && $currentStart <= $endTs) {
|
||||||
|
$activeTariff = $t;
|
||||||
|
IPS_LogMessage('Abrechnung', sprintf(
|
||||||
|
" ✅ Tarif erkannt: %.2f Rp gültig %s → %s",
|
||||||
|
floatval($t['price']),
|
||||||
|
date('d.m.Y H:i', $startTs),
|
||||||
|
date('d.m.Y H:i', $endTs)
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 Falls kein aktiver Tarif → 0 Rp
|
||||||
|
if (!$activeTariff) {
|
||||||
|
IPS_LogMessage('Abrechnung', "⚠ Kein Tarif aktiv bei " . date('d.m.Y H:i', $currentStart) . " → 0 Rp");
|
||||||
|
$activeTariff = [
|
||||||
|
'start_ts' => $currentStart,
|
||||||
|
'end_ts' => $to,
|
||||||
|
'price' => 0.0,
|
||||||
|
'unit_type'=> $type
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$tariffEnd = intval($activeTariff['end_ts']);
|
||||||
|
$tariffPrice = floatval($activeTariff['price']);
|
||||||
|
$tariffLabel = number_format($tariffPrice, 2, ',', '');
|
||||||
|
|
||||||
|
// 🔹 Start- & Endwerte aus Archiv
|
||||||
|
$startValue = $this->GetValueAt($varId, $currentStart, true);
|
||||||
|
if ($startValue === null) {
|
||||||
|
IPS_LogMessage('Abrechnung', "⚠ Kein Startwert für " . date('d.m.Y H:i', $currentStart));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$segmentEnd = ($tariffEnd < $to) ? $tariffEnd : $to;
|
||||||
|
$endValue = $this->GetValueAt($varId, $segmentEnd, true);
|
||||||
|
if ($endValue === null) {
|
||||||
|
IPS_LogMessage('Abrechnung', "⚠ Kein Endwert für " . date('d.m.Y H:i', $segmentEnd));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 Verbrauch & Kosten
|
||||||
|
$verbrauch = max(0, $endValue - $startValue);
|
||||||
|
$kosten = round(($tariffPrice / 100) * $verbrauch, 2);
|
||||||
|
$totalCost += $kosten;
|
||||||
|
|
||||||
|
IPS_LogMessage('Abrechnung', sprintf(
|
||||||
|
" 📊 Segment %d: %.3f → %.3f (Δ=%.3f) | Tarif=%.3f Rp | Kosten=%.2f CHF",
|
||||||
|
$segmentIndex, $startValue, $endValue, $verbrauch, $tariffPrice, $kosten
|
||||||
|
));
|
||||||
|
|
||||||
|
// 🔹 Tabellenzeile
|
||||||
|
$rows .= "
|
||||||
|
<tr>
|
||||||
|
<td>{$meter['name']}</td>
|
||||||
|
<td>{$type}</td>
|
||||||
|
<td>" . date('d.m.Y H:i', $currentStart) . "</td>
|
||||||
|
<td>" . date('d.m.Y H:i', $segmentEnd) . "</td>
|
||||||
|
<td>" . number_format($startValue, 2) . "</td>
|
||||||
|
<td>" . number_format($endValue, 2) . "</td>
|
||||||
|
<td>" . number_format($verbrauch, 2) . "</td>
|
||||||
|
<td>{$tariffLabel}</td>
|
||||||
|
<td>" . number_format($kosten, 2) . "</td>
|
||||||
|
</tr>";
|
||||||
|
|
||||||
|
// 🔹 Neuen Startpunkt setzen (FIX: +1 Sekunde nach Tarifende)
|
||||||
|
if ($tariffEnd < $to) {
|
||||||
|
$currentStart = $tariffEnd + 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$segmentIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback, falls keine Segmente erzeugt wurden
|
||||||
|
if ($rows === '') {
|
||||||
|
IPS_LogMessage('Abrechnung', "⚠ Keine Segmente erzeugt, Fallback auf Gesamtzeitraum");
|
||||||
|
$startValue = $this->GetValueAt($varId, $from, false);
|
||||||
|
$endValue = $this->GetValueAt($varId, $to, true);
|
||||||
|
$verbrauch = max(0, $endValue - $startValue);
|
||||||
|
$rows = "
|
||||||
|
<tr>
|
||||||
|
<td>{$meter['name']}</td>
|
||||||
|
<td>{$type}</td>
|
||||||
|
<td>" . date('d.m.Y H:i', $from) . "</td>
|
||||||
|
<td>" . date('d.m.Y H:i', $to) . "</td>
|
||||||
|
<td>" . number_format($startValue, 2) . "</td>
|
||||||
|
<td>" . number_format($endValue, 2) . "</td>
|
||||||
|
<td>" . number_format($verbrauch, 2) . "</td>
|
||||||
|
<td>0</td>
|
||||||
|
<td>0.00</td>
|
||||||
|
</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
IPS_LogMessage('Abrechnung', sprintf("✅ [AddMeterToPDFRow] Fertig: %.2f CHF total, %d Segmente", $totalCost, $segmentIndex - 1));
|
||||||
|
|
||||||
|
return ['row' => $rows, 'value' => $totalCost];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user