Refactoring
This commit is contained in:
@@ -1,62 +1,67 @@
|
|||||||
{
|
{
|
||||||
"elements": [
|
"elements":[
|
||||||
{
|
{
|
||||||
"type": "Label",
|
"type":"Label",
|
||||||
"caption": "Influx Punkte"
|
"caption":"Influx Punkte"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "Select",
|
"type":"Select",
|
||||||
"name": "InfluxJaNein",
|
"name":"InfluxJaNein",
|
||||||
"caption": "Influx Aufzeichnen Ja oder Nein",
|
"caption":"Influx Aufzeichnen Ja oder Nein",
|
||||||
"options": [
|
"options":[
|
||||||
{ "caption": "Ja", "value": true },
|
{
|
||||||
{ "caption": "Nein", "value": false }
|
"caption":"Ja",
|
||||||
]
|
"value":true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "ValidationTextBox",
|
"caption":"Nein",
|
||||||
"name": "Anlagenummer",
|
"value":false
|
||||||
"caption": "Influxadresse",
|
}
|
||||||
"suffix": "",
|
]
|
||||||
"validate": "^An_\\d{4}$"
|
},
|
||||||
},
|
{
|
||||||
{
|
"type":"ValidationTextBox",
|
||||||
"type": "ValidationTextBox",
|
"name":"Anlagenummer",
|
||||||
"name": "Gerätenummer",
|
"caption":"Influxadresse",
|
||||||
"caption": "Gerätenummer"
|
"suffix":"",
|
||||||
},
|
"validate":"^An_\\d{4}$"
|
||||||
{
|
},
|
||||||
"type": "ValidationTextBox",
|
{
|
||||||
"name": "Ortschaft",
|
"type":"ValidationTextBox",
|
||||||
"caption": "Ortschaft"
|
"name":"Gerätenummer",
|
||||||
},
|
"caption":"Gerätenummer"
|
||||||
{
|
},
|
||||||
"type": "List",
|
{
|
||||||
"name": "ZusatzVariablen",
|
"type":"ValidationTextBox",
|
||||||
"caption": "Zusätzliche Datenpunkte für Influxaufzeichnung",
|
"name":"Ortschaft",
|
||||||
"add": true,
|
"caption":"Ortschaft"
|
||||||
"delete": true,
|
},
|
||||||
"columns": [
|
{
|
||||||
{
|
"type":"List",
|
||||||
|
"name":"ZusatzVariablen",
|
||||||
"caption": "Influx Name",
|
"caption":"Zusätzliche Datenpunkte für Influxaufzeichnung",
|
||||||
"name": "Variablenname",
|
"add":true,
|
||||||
"width": "200px",
|
"delete":true,
|
||||||
"add": "",
|
"columns":[
|
||||||
"edit": {
|
{
|
||||||
"type": "ValidationTextBox"
|
"caption":"Influx Name",
|
||||||
}
|
"name":"Variablenname",
|
||||||
},
|
"width":"200px",
|
||||||
{
|
"add":"",
|
||||||
"caption": "Datenpunkt",
|
"edit":{
|
||||||
"name": "Variable",
|
"type":"ValidationTextBox"
|
||||||
"width": "300px",
|
|
||||||
"add": 0,
|
|
||||||
"edit": {
|
|
||||||
"type": "SelectVariable"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
}
|
{
|
||||||
|
"caption":"Datenpunkt",
|
||||||
|
"name":"Variable",
|
||||||
|
"width":"300px",
|
||||||
|
"add":0,
|
||||||
|
"edit":{
|
||||||
|
"type":"SelectVariable"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"translations": {
|
|
||||||
"de": {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,30 +2,38 @@
|
|||||||
|
|
||||||
class Belevo_Server_Kommunikation extends IPSModule
|
class Belevo_Server_Kommunikation extends IPSModule
|
||||||
{
|
{
|
||||||
|
|
||||||
public function Create()
|
public function Create()
|
||||||
{
|
{
|
||||||
// Die Standard-Create() Methode aufrufen
|
// Die Standard-Create() Methode aufrufen
|
||||||
parent::Create();
|
parent::Create();
|
||||||
|
|
||||||
// Registrierung der Eigenschaften
|
// Registrierung der Eigenschaften
|
||||||
$this->RegisterPropertyString("BaseURL", "https://brain.belevo.ch/storedata");
|
$this->RegisterPropertyString(
|
||||||
|
"BaseURL",
|
||||||
|
"https://brain.belevo.ch/storedata"
|
||||||
|
);
|
||||||
$this->RegisterPropertyString("Anlagenummer", "0");
|
$this->RegisterPropertyString("Anlagenummer", "0");
|
||||||
$this->RegisterPropertyBoolean("InfluxJaNein", false);
|
$this->RegisterPropertyBoolean("InfluxJaNein", false);
|
||||||
|
|
||||||
// JSON-String für Zusatzvariablen
|
// JSON-String für Zusatzvariablen
|
||||||
$this->RegisterPropertyString("ZusatzVariablen", json_encode([]));// Bezeichnung der Liste
|
$this->RegisterPropertyString("ZusatzVariablen", json_encode([])); // Bezeichnung der Liste
|
||||||
$this->RegisterPropertyString("Variable","0"); // Datenpunkt kann im Syncom ausgewählt werden
|
$this->RegisterPropertyString("Variable", "0"); // Datenpunkt kann im Syncom ausgewählt werden
|
||||||
$this->RegisterPropertyString("Variablenname","0"); // Name für Influxaufzeichnung
|
$this->RegisterPropertyString("Variablenname", "0"); // Name für Influxaufzeichnung
|
||||||
$this->RegisterPropertyString("Gerätenummer","0");
|
$this->RegisterPropertyString("Gerätenummer", "0");
|
||||||
$this->RegisterPropertyString("Ortschaft","0");
|
$this->RegisterPropertyString("Ortschaft", "0");
|
||||||
|
|
||||||
$this->RegisterVariableInteger("Wolkenwarscheinlichkeit", "Wolkenwarscheinlichkeit");
|
$this->RegisterVariableInteger(
|
||||||
|
"Wolkenwarscheinlichkeit",
|
||||||
|
"Wolkenwarscheinlichkeit"
|
||||||
|
);
|
||||||
$this->RegisterVariableInteger("Temperatur", "Temperatur");
|
$this->RegisterVariableInteger("Temperatur", "Temperatur");
|
||||||
|
|
||||||
|
|
||||||
// Timer registrieren
|
// Timer registrieren
|
||||||
$this->RegisterTimer("Timer_Influx", 0, 'IPS_RequestAction(' . $this->InstanceID . ', "GetAction", "");');
|
$this->RegisterTimer(
|
||||||
|
"Timer_Influx",
|
||||||
|
0,
|
||||||
|
"IPS_RequestAction(" . $this->InstanceID . ', "GetAction", "");'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges()
|
public function ApplyChanges()
|
||||||
@@ -39,9 +47,6 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
// Timer auf 5 Minuten setzen
|
// Timer auf 5 Minuten setzen
|
||||||
$this->SetTimerInterval("Timer_Influx", 300000); // Alle 5 Minuten -> 5*60*1000=300000
|
$this->SetTimerInterval("Timer_Influx", 300000); // Alle 5 Minuten -> 5*60*1000=300000
|
||||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Influx Ja");
|
IPS_LogMessage("Belevo_Server_Kommunikation", "Influx Ja");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Timer stoppen
|
// Timer stoppen
|
||||||
$this->SetTimerInterval("Timer_Influx", 0);
|
$this->SetTimerInterval("Timer_Influx", 0);
|
||||||
@@ -49,14 +54,17 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWetter($bn, $pw, $loc) {
|
public function getWetter($bn, $pw, $loc)
|
||||||
|
{
|
||||||
// URL mit Parametern zusammenstellen
|
// URL mit Parametern zusammenstellen
|
||||||
$url = "https://brain.belevo.ch/v2wetter?loc=" . urlencode($loc) . "&nr=" . urlencode($bn);
|
$url =
|
||||||
|
"https://brain.belevo.ch/v2wetter?loc=" .
|
||||||
|
urlencode($loc) .
|
||||||
|
"&nr=" .
|
||||||
|
urlencode($bn);
|
||||||
|
|
||||||
// HTTP-Anfrage-Header einstellen
|
// HTTP-Anfrage-Header einstellen
|
||||||
$headers = [
|
$headers = ["id: $pw"];
|
||||||
"id: $pw"
|
|
||||||
];
|
|
||||||
|
|
||||||
// cURL-Initialisierung
|
// cURL-Initialisierung
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
@@ -72,10 +80,15 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
$data = json_decode($response, true);
|
$data = json_decode($response, true);
|
||||||
|
|
||||||
// Überprüfen, ob die benötigten Felder vorhanden sind und zurückgeben
|
// Überprüfen, ob die benötigten Felder vorhanden sind und zurückgeben
|
||||||
if (isset($data['forecast']['forecastday'][0]['hour'][5]['temp_c']) && isset($data['forecast']['forecastday'][0]['hour'][8]['cloud'])) {
|
if (
|
||||||
|
isset($data["forecast"]["forecastday"][0]["hour"][5]["temp_c"]) &&
|
||||||
|
isset($data["forecast"]["forecastday"][0]["hour"][8]["cloud"])
|
||||||
|
) {
|
||||||
return [
|
return [
|
||||||
'temp' => $data['forecast']['forecastday'][0]['hour'][5]['temp_c'],
|
"temp" =>
|
||||||
'cloud' => $data['forecast']['forecastday'][0]['hour'][8]['cloud']
|
$data["forecast"]["forecastday"][0]["hour"][5]["temp_c"],
|
||||||
|
"cloud" =>
|
||||||
|
$data["forecast"]["forecastday"][0]["hour"][8]["cloud"],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,45 +99,50 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
private function ProcessZusatzVariablen()
|
private function ProcessZusatzVariablen()
|
||||||
{
|
{
|
||||||
// Abrufen der ZusatzVariablen-Liste
|
// Abrufen der ZusatzVariablen-Liste
|
||||||
$zusatzVariablen = json_decode($this->ReadPropertyString("ZusatzVariablen"), true); // JSON decodieren
|
$zusatzVariablen = json_decode(
|
||||||
|
$this->ReadPropertyString("ZusatzVariablen"),
|
||||||
|
true
|
||||||
|
); // JSON decodieren
|
||||||
|
|
||||||
// Array für die Ausgabe erstellen
|
// Array für die Ausgabe erstellen
|
||||||
$output = array();
|
$output = [];
|
||||||
|
|
||||||
// Verarbeitung der Variablen
|
// Verarbeitung der Variablen
|
||||||
if (!empty($zusatzVariablen)) {
|
if (!empty($zusatzVariablen)) {
|
||||||
foreach ($zusatzVariablen as $variable) {
|
foreach ($zusatzVariablen as $variable) {
|
||||||
// Überprüfen, ob der Variablenname gesetzt ist
|
// Überprüfen, ob der Variablenname gesetzt ist
|
||||||
if (isset($variable['Variablenname'])) {
|
if (isset($variable["Variablenname"])) {
|
||||||
$variablenname = $variable['Variablenname'];
|
$variablenname = $variable["Variablenname"];
|
||||||
} else {
|
} else {
|
||||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Variablenname nicht gesetzt für die Variable: " . json_encode($variable));
|
IPS_LogMessage(
|
||||||
|
"Belevo_Server_Kommunikation",
|
||||||
|
"Variablenname nicht gesetzt für die Variable: " .
|
||||||
|
json_encode($variable)
|
||||||
|
);
|
||||||
continue; // Mit der nächsten Variable fortfahren
|
continue; // Mit der nächsten Variable fortfahren
|
||||||
}
|
}
|
||||||
|
|
||||||
$variableID = $variable['Variable'];
|
$variableID = $variable["Variable"];
|
||||||
|
|
||||||
// Überprüfen, ob die Variable existiert
|
// Überprüfen, ob die Variable existiert
|
||||||
if (IPS_VariableExists($variableID)) {
|
if (IPS_VariableExists($variableID)) {
|
||||||
$wert = GetValue($variableID); // Den aktuellen Wert der Zusatzvariable abrufen
|
$wert = GetValue($variableID); // Den aktuellen Wert der Zusatzvariable abrufen
|
||||||
|
|
||||||
|
|
||||||
// Wert dem Variablenname zuweisen
|
// Wert dem Variablenname zuweisen
|
||||||
$output[$variablenname] = $wert;
|
$output[$variablenname] = $wert;
|
||||||
} else {
|
} else {
|
||||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Variable mit ID $variableID existiert nicht.");
|
IPS_LogMessage(
|
||||||
|
"Belevo_Server_Kommunikation",
|
||||||
|
"Variable mit ID $variableID existiert nicht."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Wenn gewünscht, kannst du das JSON zurückgeben oder speichern
|
// Wenn gewünscht, kannst du das JSON zurückgeben oder speichern
|
||||||
return json_encode($output);
|
return json_encode($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function RequestAction($Ident, $Value)
|
public function RequestAction($Ident, $Value)
|
||||||
{
|
{
|
||||||
switch ($Ident) {
|
switch ($Ident) {
|
||||||
@@ -136,7 +154,8 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetAction() {
|
public function GetAction()
|
||||||
|
{
|
||||||
$output = $this->ProcessZusatzVariablen();
|
$output = $this->ProcessZusatzVariablen();
|
||||||
$json = $this->MakeJson($output);
|
$json = $this->MakeJson($output);
|
||||||
// Verarbeite die Zusatzvariablen
|
// Verarbeite die Zusatzvariablen
|
||||||
@@ -145,20 +164,30 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
|
|
||||||
$anlagenummer = $this->ReadPropertyString("Anlagenummer");
|
$anlagenummer = $this->ReadPropertyString("Anlagenummer");
|
||||||
|
|
||||||
$answer = $this->getWetter($anlagenummer, $this->ReadPropertyString("Gerätenummer"), $this->ReadPropertyString("Ortschaft"));
|
$answer = $this->getWetter(
|
||||||
|
$anlagenummer,
|
||||||
|
$this->ReadPropertyString("Gerätenummer"),
|
||||||
|
$this->ReadPropertyString("Ortschaft")
|
||||||
|
);
|
||||||
|
|
||||||
//$this->SetValue("Temperatur", $answer['temp']);
|
//$this->SetValue("Temperatur", $answer['temp']);
|
||||||
//$this->SetValue("Wolkenwarscheinlichkeit", $answer['cloud']);
|
//$this->SetValue("Wolkenwarscheinlichkeit", $answer['cloud']);
|
||||||
if (isset($answer['temp'])) {
|
if (isset($answer["temp"])) {
|
||||||
$this->SetValue("Temperatur", $answer['temp']);
|
$this->SetValue("Temperatur", $answer["temp"]);
|
||||||
} else {
|
} else {
|
||||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Temperatur-Wert ist nicht vorhanden.");
|
IPS_LogMessage(
|
||||||
|
"Belevo_Server_Kommunikation",
|
||||||
|
"Temperatur-Wert ist nicht vorhanden."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($answer['cloud'])) {
|
if (isset($answer["cloud"])) {
|
||||||
$this->SetValue("Wolkenwarscheinlichkeit", $answer['cloud']);
|
$this->SetValue("Wolkenwarscheinlichkeit", $answer["cloud"]);
|
||||||
} else {
|
} else {
|
||||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Wolkenwarscheinlichkeit-Wert ist nicht vorhanden.");
|
IPS_LogMessage(
|
||||||
|
"Belevo_Server_Kommunikation",
|
||||||
|
"Wolkenwarscheinlichkeit-Wert ist nicht vorhanden."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($json)) {
|
if (!empty($json)) {
|
||||||
@@ -166,80 +195,77 @@ class Belevo_Server_Kommunikation extends IPSModule
|
|||||||
$fullURL = $baseURL;
|
$fullURL = $baseURL;
|
||||||
$this->SendJsonToInfluxDB($fullURL, $json);
|
$this->SendJsonToInfluxDB($fullURL, $json);
|
||||||
} else {
|
} else {
|
||||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Keine Aufzeichnung im Influx: Anlagenummer oder JSON-Daten fehlen->GetAction()");
|
IPS_LogMessage(
|
||||||
|
"Belevo_Server_Kommunikation",
|
||||||
|
"Keine Aufzeichnung im Influx: Anlagenummer oder JSON-Daten fehlen"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Werte in ein Array packen
|
public function MakeJson($json)
|
||||||
public function MakeJson($json)
|
{
|
||||||
{
|
$an_nummer = $this->ReadPropertyString("Anlagenummer"); // Anlagenummer lesen
|
||||||
$an_nummer = $this->ReadPropertyString("Anlagenummer"); // Anlagenummer lesen
|
$InfluxJaNein = $this->ReadPropertyBoolean("InfluxJaNein");
|
||||||
$InfluxJaNein = $this->ReadPropertyBoolean("InfluxJaNein");
|
|
||||||
|
|
||||||
// Werte in ein Array packen
|
// Werte in ein Array packen
|
||||||
$influxData = array(
|
$influxData = [
|
||||||
"Value" => array(
|
"Value" => [
|
||||||
"InfluxAllowed" => $InfluxJaNein // Setze InfluxAllowed
|
"InfluxAllowed" => $InfluxJaNein, // Setze InfluxAllowed
|
||||||
),
|
],
|
||||||
"Parameter" => array(
|
"Parameter" => [
|
||||||
"Influxadr" => $an_nummer
|
"Influxadr" => $an_nummer,
|
||||||
),
|
],
|
||||||
"Tracker" => $json // Initialisiere Tracker als leeres Array
|
"Tracker" => $json, // Initialisiere Tracker als leeres Array
|
||||||
);
|
];
|
||||||
|
|
||||||
|
// Array in JSON konvertieren
|
||||||
|
$json = json_encode($influxData);
|
||||||
|
|
||||||
|
// JSON zurückgeben oder weiterverarbeiten
|
||||||
// Array in JSON konvertieren
|
return $json;
|
||||||
$json = json_encode($influxData);
|
|
||||||
|
|
||||||
|
|
||||||
// JSON zurückgeben oder weiterverarbeiten
|
|
||||||
return $json;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function SendJsonToInfluxDB($url, $jsonData) {
|
|
||||||
$pw = $this->ReadPropertyString("Gerätenummer");
|
|
||||||
if (empty($pw)) {
|
|
||||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Fehler: Gerätenummer ist leer.");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function SendJsonToInfluxDB($url, $jsonData)
|
||||||
|
{
|
||||||
|
$pw = $this->ReadPropertyString("Gerätenummer");
|
||||||
|
if (empty($pw)) {
|
||||||
|
IPS_LogMessage(
|
||||||
|
"Belevo_Server_Kommunikation",
|
||||||
|
"Fehler: Gerätenummer ist leer."
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cURL Initialisieren
|
||||||
|
$curl = curl_init();
|
||||||
|
// Optionen für cURL-Request definieren
|
||||||
|
curl_setopt_array($curl, [
|
||||||
|
CURLOPT_URL => $url,
|
||||||
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_POST => true, // POST-Methode verwenden
|
||||||
|
CURLOPT_HTTPHEADER => [
|
||||||
|
"Content-Type: application/json", // Header für JSON-Daten setzen
|
||||||
|
"Accept: application/json",
|
||||||
|
"id:" . $pw,
|
||||||
|
],
|
||||||
|
CURLOPT_POSTFIELDS => $jsonData, // JSON-Daten als POST-Feld senden
|
||||||
|
]);
|
||||||
|
|
||||||
|
// cURL-Request ausführen
|
||||||
|
$result = curl_exec($curl);
|
||||||
|
|
||||||
// cURL Initialisieren
|
$error = curl_error($curl);
|
||||||
$curl = curl_init();
|
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
// Optionen für cURL-Request definieren
|
// cURL beenden
|
||||||
curl_setopt_array($curl, [
|
curl_close($curl);
|
||||||
CURLOPT_URL => $url,
|
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
|
||||||
CURLOPT_POST => true, // POST-Methode verwenden
|
|
||||||
CURLOPT_HTTPHEADER => [
|
|
||||||
'Content-Type: application/json', // Header für JSON-Daten setzen
|
|
||||||
'Accept: application/json',
|
|
||||||
'id:'.$pw
|
|
||||||
],
|
|
||||||
CURLOPT_POSTFIELDS => $jsonData // JSON-Daten als POST-Feld senden
|
|
||||||
]);
|
|
||||||
|
|
||||||
// cURL-Request ausführen
|
if ($error) {
|
||||||
$result = curl_exec($curl);
|
IPS_LogMessage(
|
||||||
|
"Belevo_Server_Kommunikation",
|
||||||
|
"Fehler beim Senden an Influx: " . $error
|
||||||
$error = curl_error($curl);
|
);
|
||||||
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
}
|
||||||
// cURL beenden
|
|
||||||
curl_close($curl);
|
|
||||||
|
|
||||||
if ($error) {
|
|
||||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Fehler beim Senden an Influx: " . $error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"translations": {
|
|
||||||
"de": {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
class Boiler_2_Stufig_Mit_Fueler extends IPSModule
|
||||||
|
{
|
||||||
public function Create() {
|
public function Create()
|
||||||
|
{
|
||||||
parent::Create();
|
parent::Create();
|
||||||
|
|
||||||
// Prioritäten
|
// Prioritäten
|
||||||
@@ -26,9 +27,9 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
|||||||
$this->RegisterPropertyInteger("Boilertemperatur", 0);
|
$this->RegisterPropertyInteger("Boilertemperatur", 0);
|
||||||
|
|
||||||
// Boiler spezifische Variablen
|
// Boiler spezifische Variablen
|
||||||
$this->RegisterVariableInteger("Boilermintemp", "Boilermintemp", "", 45);
|
$this->RegisterVariableInteger("Boilermintemp","Boilermintemp","",45);
|
||||||
$this->RegisterVariableInteger("Boilermaxtemp", "Boilermaxtemp", "", 60);
|
$this->RegisterVariableInteger("Boilermaxtemp","Boilermaxtemp","",60);
|
||||||
$this->RegisterVariableInteger("Boilerlegiotemp", "Boilerlegiotemp", "", 65);
|
$this->RegisterVariableInteger("Boilerlegiotemp","Boilerlegiotemp","",65);
|
||||||
$this->RegisterVariableInteger("LegioCounter", "LegioCounter", "", 0);
|
$this->RegisterVariableInteger("LegioCounter", "LegioCounter", "", 0);
|
||||||
|
|
||||||
// Schaltkontakte
|
// Schaltkontakte
|
||||||
@@ -39,12 +40,14 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
|||||||
$this->SetValue("Idle", true);
|
$this->SetValue("Idle", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges() {
|
public function ApplyChanges()
|
||||||
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aktionen verarbeiten
|
// Aktionen verarbeiten
|
||||||
public function RequestAction($Ident, $Value) {
|
public function RequestAction($Ident, $Value)
|
||||||
|
{
|
||||||
switch ($Ident) {
|
switch ($Ident) {
|
||||||
case "SetCurrentPower":
|
case "SetCurrentPower":
|
||||||
$this->SetCurrentPower($Value);
|
$this->SetCurrentPower($Value);
|
||||||
@@ -57,12 +60,15 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Methode zum Setzen des aktuellen Stromverbrauchs
|
// Methode zum Setzen des aktuellen Stromverbrauchs
|
||||||
public function SetCurrentPower(int $power) {
|
public function SetCurrentPower(int $power)
|
||||||
|
{
|
||||||
// Schalte Kontakt Teillast und Vollast entsprechend der Power-Einstellung
|
// Schalte Kontakt Teillast und Vollast entsprechend der Power-Einstellung
|
||||||
if ($power == $this->ReadPropertyInteger("BoilerLeistungVolllast")) {
|
if ($power == $this->ReadPropertyInteger("BoilerLeistungVolllast")) {
|
||||||
SetValue($this->ReadPropertyInteger("Kontakt_Volllast"), true);
|
SetValue($this->ReadPropertyInteger("Kontakt_Volllast"), true);
|
||||||
SetValue($this->ReadPropertyInteger("Kontakt_Teillast"), false);
|
SetValue($this->ReadPropertyInteger("Kontakt_Teillast"), false);
|
||||||
} elseif ($power == $this->ReadPropertyInteger("BoilerLeistungTeillast")) {
|
} elseif (
|
||||||
|
$power == $this->ReadPropertyInteger("BoilerLeistungTeillast")
|
||||||
|
) {
|
||||||
SetValue($this->ReadPropertyInteger("Kontakt_Volllast"), false);
|
SetValue($this->ReadPropertyInteger("Kontakt_Volllast"), false);
|
||||||
SetValue($this->ReadPropertyInteger("Kontakt_Teillast"), true);
|
SetValue($this->ReadPropertyInteger("Kontakt_Teillast"), true);
|
||||||
} else {
|
} else {
|
||||||
@@ -74,7 +80,10 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
|||||||
$lastPower = GetValue($this->GetIDForIdent("CurrentPower"));
|
$lastPower = GetValue($this->GetIDForIdent("CurrentPower"));
|
||||||
if ($power != $lastPower) {
|
if ($power != $lastPower) {
|
||||||
$this->SetValue("Idle", false);
|
$this->SetValue("Idle", false);
|
||||||
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
|
$this->SetValue(
|
||||||
|
"IdleCounter",
|
||||||
|
$this->ReadPropertyInteger("IdleCounterMax")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setze die neue CurrentPower
|
// Setze die neue CurrentPower
|
||||||
@@ -84,10 +93,9 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
|||||||
$this->ProcessIdleCounter();
|
$this->ProcessIdleCounter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Methode zum Abrufen der aktuellen Daten
|
// Methode zum Abrufen der aktuellen Daten
|
||||||
public function GetCurrentData(bool $Peak) {
|
public function GetCurrentData(bool $Peak)
|
||||||
|
{
|
||||||
$LegioCounter = $this->GetValue("LegioCounter");
|
$LegioCounter = $this->GetValue("LegioCounter");
|
||||||
|
|
||||||
$boilerTemp = GetValue($this->ReadPropertyInteger("Boilertemperatur"));
|
$boilerTemp = GetValue($this->ReadPropertyInteger("Boilertemperatur"));
|
||||||
@@ -97,69 +105,73 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
|||||||
$teilLeistung = $this->ReadPropertyInteger("BoilerLeistungTeillast");
|
$teilLeistung = $this->ReadPropertyInteger("BoilerLeistungTeillast");
|
||||||
$vollLeistung = $this->ReadPropertyInteger("BoilerLeistungVolllast");
|
$vollLeistung = $this->ReadPropertyInteger("BoilerLeistungVolllast");
|
||||||
|
|
||||||
$AktuelleVollast = GetValue($this->ReadPropertyInteger("Kontakt_Volllast"));
|
$AktuelleVollast = GetValue(
|
||||||
$AktuelleTeillast = GetValue($this->ReadPropertyInteger("Kontakt_Teillast"));
|
$this->ReadPropertyInteger("Kontakt_Volllast")
|
||||||
|
);
|
||||||
|
$AktuelleTeillast = GetValue(
|
||||||
|
$this->ReadPropertyInteger("Kontakt_Teillast")
|
||||||
|
);
|
||||||
|
|
||||||
if($boilerTemp>$LegioTemp){
|
if ($boilerTemp > $LegioTemp) {
|
||||||
$LegioCounter = 0;
|
$LegioCounter = 0;
|
||||||
IPS_LogMessage("im1", $LegioCounter);
|
} else {
|
||||||
|
$LegioCounter = $LegioCounter + 1;
|
||||||
}else{
|
|
||||||
$LegioCounter = $LegioCounter + 1;
|
|
||||||
IPS_LogMessage("im2", $LegioCounter);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if($LegioCounter > 69120){
|
if ($LegioCounter > 69120) {
|
||||||
$maxTemp = $LegioTemp;
|
$maxTemp = $LegioTemp;
|
||||||
IPS_LogMessage("im3", $LegioCounter);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if(($LegioCounter>120960) && ($this->ist_nachts())){
|
if ($LegioCounter > 120960 && $this->ist_nachts()) {
|
||||||
$minTemp = $LegioTemp;
|
$minTemp = $LegioTemp;
|
||||||
IPS_LogMessage("im4", $LegioCounter);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->SetValue("LegioCounter", $LegioCounter);
|
$this->SetValue("LegioCounter", $LegioCounter);
|
||||||
|
|
||||||
|
|
||||||
if ($Peak) {
|
if ($Peak) {
|
||||||
if ($boilerTemp < $minTemp) {
|
if ($boilerTemp < $minTemp) {
|
||||||
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
|
$this->SetValue(
|
||||||
|
"PowerSteps",
|
||||||
} elseif ($boilerTemp < ($minTemp + 5) && ($AktuelleVollast || $AktuelleTeillast)) {
|
json_encode([0, $teilLeistung, $vollLeistung])
|
||||||
|
);
|
||||||
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
|
} elseif (
|
||||||
}
|
$boilerTemp < $minTemp + 5 &&
|
||||||
else {
|
($AktuelleVollast || $AktuelleTeillast)
|
||||||
|
) {
|
||||||
|
$this->SetValue(
|
||||||
|
"PowerSteps",
|
||||||
|
json_encode([0, $teilLeistung, $vollLeistung])
|
||||||
|
);
|
||||||
|
} else {
|
||||||
$this->SetValue("PowerSteps", json_encode([0]));
|
$this->SetValue("PowerSteps", json_encode([0]));
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($boilerTemp < $minTemp) {
|
if ($boilerTemp < $minTemp) {
|
||||||
$this->SetValue("PowerSteps", json_encode([$vollLeistung]));
|
$this->SetValue("PowerSteps", json_encode([$vollLeistung]));
|
||||||
|
} elseif (
|
||||||
} elseif ($boilerTemp < ($minTemp + 5) && ($AktuelleVollast || $AktuelleTeillast)) {
|
$boilerTemp < $minTemp + 5 &&
|
||||||
|
($AktuelleVollast || $AktuelleTeillast)
|
||||||
|
) {
|
||||||
$this->SetValue("PowerSteps", json_encode([$vollLeistung]));
|
$this->SetValue("PowerSteps", json_encode([$vollLeistung]));
|
||||||
|
} elseif ($boilerTemp < $maxTemp - 5) {
|
||||||
}
|
$this->SetValue(
|
||||||
elseif ($boilerTemp < ($maxTemp-5)) {
|
"PowerSteps",
|
||||||
|
json_encode([0, $teilLeistung, $vollLeistung])
|
||||||
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
|
);
|
||||||
}
|
} elseif (
|
||||||
elseif ($boilerTemp < ($maxTemp) && ($AktuelleVollast || $AktuelleTeillast)) {
|
$boilerTemp < $maxTemp &&
|
||||||
|
($AktuelleVollast || $AktuelleTeillast)
|
||||||
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
|
) {
|
||||||
}
|
$this->SetValue(
|
||||||
else {
|
"PowerSteps",
|
||||||
|
json_encode([0, $teilLeistung, $vollLeistung])
|
||||||
|
);
|
||||||
|
} else {
|
||||||
$this->SetValue("PowerSteps", json_encode([0]));
|
$this->SetValue("PowerSteps", json_encode([0]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function ProcessIdleCounter() {
|
private function ProcessIdleCounter()
|
||||||
|
{
|
||||||
// IdleCounter auslesen und verarbeiten
|
// IdleCounter auslesen und verarbeiten
|
||||||
$idleCounter = $this->GetValue("IdleCounter");
|
$idleCounter = $this->GetValue("IdleCounter");
|
||||||
if ($idleCounter > 0) {
|
if ($idleCounter > 0) {
|
||||||
@@ -170,11 +182,15 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function CheckIdle($power) {
|
private function CheckIdle($power)
|
||||||
|
{
|
||||||
$lastpower = GetValue("CurrentPower");
|
$lastpower = GetValue("CurrentPower");
|
||||||
if ($lastpower != GetValue("CurrentPower")) {
|
if ($lastpower != GetValue("CurrentPower")) {
|
||||||
$this->SetValue("Idle", false);
|
$this->SetValue("Idle", false);
|
||||||
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
|
$this->SetValue(
|
||||||
|
"IdleCounter",
|
||||||
|
$this->ReadPropertyInteger("IdleCounterMax")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// IdleCounter auslesen und verarbeiten
|
// IdleCounter auslesen und verarbeiten
|
||||||
$idleCounter = $this->GetValue("IdleCounter");
|
$idleCounter = $this->GetValue("IdleCounter");
|
||||||
@@ -186,13 +202,13 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function ist_nachts()
|
||||||
|
{
|
||||||
|
date_default_timezone_set("Europe/Berlin"); // Setze hier deine Zeitzone
|
||||||
|
|
||||||
private function ist_nachts() {
|
$aktuelle_zeit = strtotime(date("H:i")); // Aktuelle Zeit in Stunden und Minuten umwandeln
|
||||||
date_default_timezone_set('Europe/Berlin'); // Setze hier deine Zeitzone
|
$start_nacht = strtotime("22:00"); // Startzeit der Nacht (22 Uhr)
|
||||||
|
$ende_nacht = strtotime("07:00"); // Endzeit der Nacht (7 Uhr)
|
||||||
$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) {
|
if ($aktuelle_zeit >= $start_nacht || $aktuelle_zeit < $ende_nacht) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
{
|
|
||||||
"translations": {
|
|
||||||
"de": {
|
|
||||||
"Translation 1": "Übersetzung 1",
|
|
||||||
"Translation 2": "Übersetzung 2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,52 +2,53 @@
|
|||||||
|
|
||||||
class CC100_HW extends IPSModule
|
class CC100_HW extends IPSModule
|
||||||
{
|
{
|
||||||
private $DigOutPID = '/sys/kernel/dout_drv/DOUT_DATA';
|
private $DigOutPID = "/sys/kernel/dout_drv/DOUT_DATA";
|
||||||
private $PT1PID = '/sys/bus/iio/devices/iio:device2/in_voltage13_raw';
|
private $PT1PID = "/sys/bus/iio/devices/iio:device2/in_voltage13_raw";
|
||||||
private $PT2PID = '/sys/bus/iio/devices/iio:device2/in_voltage1_raw';
|
private $PT2PID = "/sys/bus/iio/devices/iio:device2/in_voltage1_raw";
|
||||||
private $waitingTime = 1; // Waiting time (in ms) for a new attempt to write a digital output (if file is blocked)
|
private $DIN_FILE = "/sys/bus/iio/devices/iio:device2/in_voltage1_raw";
|
||||||
private $maxTime = 5000; // Max time (in ms) for the writing process
|
private $waitingTime = 1; // Waiting time (in ms) for a new attempt to write a digital output (if file is blocked)
|
||||||
|
private $maxTime = 5000; // Max time (in ms) for the writing process
|
||||||
|
|
||||||
public function Create()
|
public function Create()
|
||||||
{
|
{
|
||||||
parent::Create();
|
parent::Create();
|
||||||
$this->RegisterPropertyString('FilePath', $this->DigOutPID);
|
$this->RegisterPropertyString("FilePath", $this->DigOutPID);
|
||||||
$this->RegisterVariableBoolean('Bit1', 'DO 1', '~Switch', 1);
|
$this->RegisterVariableBoolean("Bit1", "DO 1", "~Switch", 1);
|
||||||
$this->RegisterVariableBoolean('Bit2', 'DO 2', '~Switch', 2);
|
$this->RegisterVariableBoolean("Bit2", "DO 2", "~Switch", 2);
|
||||||
$this->RegisterVariableBoolean('Bit3', 'DO 3', '~Switch', 3);
|
$this->RegisterVariableBoolean("Bit3", "DO 3", "~Switch", 3);
|
||||||
$this->RegisterVariableBoolean('Bit4', 'DO 4', '~Switch', 4);
|
$this->RegisterVariableBoolean("Bit4", "DO 4", "~Switch", 4);
|
||||||
|
|
||||||
$this->RegisterVariableBoolean('DI1', 'DI1');
|
|
||||||
$this->RegisterVariableBoolean('DI2', 'DI2');
|
|
||||||
$this->RegisterVariableBoolean('DI3', 'DI3');
|
|
||||||
$this->RegisterVariableBoolean('DI4', 'DI4');
|
|
||||||
$this->RegisterVariableBoolean('DI5', 'DI5');
|
|
||||||
$this->RegisterVariableBoolean('DI6', 'DI6');
|
|
||||||
$this->RegisterVariableBoolean('DI7', 'DI7');
|
|
||||||
$this->RegisterVariableBoolean('DI8', 'DI8');
|
|
||||||
|
|
||||||
|
$this->RegisterVariableBoolean("DI1", "DI1");
|
||||||
|
$this->RegisterVariableBoolean("DI2", "DI2");
|
||||||
|
$this->RegisterVariableBoolean("DI3", "DI3");
|
||||||
|
$this->RegisterVariableBoolean("DI4", "DI4");
|
||||||
|
$this->RegisterVariableBoolean("DI5", "DI5");
|
||||||
|
$this->RegisterVariableBoolean("DI6", "DI6");
|
||||||
|
$this->RegisterVariableBoolean("DI7", "DI7");
|
||||||
|
$this->RegisterVariableBoolean("DI8", "DI8");
|
||||||
|
|
||||||
$this->RegisterVariableFloat('PT1', 'PT1 Temperatur', '~Temperature', 5);
|
$this->RegisterVariableFloat('PT1', 'PT1 Temperatur', '~Temperature', 5);
|
||||||
$this->RegisterVariableFloat('PT2', 'PT2 Temperatur', '~Temperature', 6);
|
$this->RegisterVariableFloat('PT2', 'PT2 Temperatur', '~Temperature', 6);
|
||||||
$this->EnableAction('Bit1');
|
$this->EnableAction("Bit1");
|
||||||
$this->EnableAction('Bit2');
|
$this->EnableAction("Bit2");
|
||||||
$this->EnableAction('Bit3');
|
$this->EnableAction("Bit3");
|
||||||
$this->EnableAction('Bit4');
|
$this->EnableAction("Bit4");
|
||||||
|
|
||||||
|
// Timer für PT1 und PT2 einrichten
|
||||||
// Timer für PT1 und PT2 einrichten
|
// Timer für PT1 und PT2 einrichten
|
||||||
$this->RegisterTimer("ReadPTValues", 30000, 'IPS_RequestAction(' . $this->InstanceID . ', "DOUT_ReadPTValues", "");');
|
$this->RegisterTimer("ReadPTValues", 30000, 'IPS_RequestAction(' . $this->InstanceID . ', "DOUT_ReadPTValues", "");');
|
||||||
$this->RegisterTimer("WriteBits", 2000, 'IPS_RequestAction(' . $this->InstanceID . ', "UpdateFile", "");');
|
$this->RegisterTimer("WriteBits", 2000, 'IPS_RequestAction(' . $this->InstanceID . ', "UpdateFile", "");');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges()
|
public function ApplyChanges()
|
||||||
{
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
// Timer aktivieren
|
// Timer aktivieren
|
||||||
$this->SetTimerInterval('ReadPTValues', 30000);
|
$this->SetTimerInterval("ReadPTValues", 30000);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function RequestAction($Ident, $Value) {
|
public function RequestAction($Ident, $Value)
|
||||||
|
{
|
||||||
switch ($Ident) {
|
switch ($Ident) {
|
||||||
case "DOUT_ReadPTValues":
|
case "DOUT_ReadPTValues":
|
||||||
$this->DOUT_ReadPTValues();
|
$this->DOUT_ReadPTValues();
|
||||||
@@ -66,81 +67,88 @@ class CC100_HW extends IPSModule
|
|||||||
$this->TryWriteFile($starttime);
|
$this->TryWriteFile($starttime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function readAndConvertToBools($filePath)
|
private function readAndConvertToBools($filePath)
|
||||||
{
|
{
|
||||||
|
// Inhalt der Datei auslesen
|
||||||
|
$content = @file_get_contents($filePath);
|
||||||
|
|
||||||
|
if ($content === false) {
|
||||||
|
throw new Exception("Fehler beim Lesen der Datei $filePath.");
|
||||||
|
}
|
||||||
|
|
||||||
// Inhalt der Datei auslesen
|
// Die gelesene Zahl bereinigen (Leerzeichen oder Zeilenumbrüche entfernen)
|
||||||
$content = @file_get_contents($filePath);
|
$number = trim($content);
|
||||||
|
|
||||||
if ($content === false) {
|
// Sicherstellen, dass die Zahl gültig ist
|
||||||
throw new Exception("Fehler beim Lesen der Datei $filePath.");
|
if (!ctype_digit($number)) {
|
||||||
|
throw new Exception(
|
||||||
|
"Der Inhalt der Datei ist keine gültige Zahl: $number"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Die Zahl in einen Integer umwandeln
|
||||||
|
$intValue = (int) $number;
|
||||||
|
|
||||||
|
// Sicherstellen, dass die Zahl zwischen 0 und 255 liegt
|
||||||
|
if ($intValue < 0 || $intValue > 255) {
|
||||||
|
throw new Exception(
|
||||||
|
"Die Zahl muss zwischen 0 und 255 liegen: $intValue"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// In einen 8-Bit-Binärstring umwandeln
|
||||||
|
$binaryString = str_pad(decbin($intValue), 8, "0", STR_PAD_LEFT);
|
||||||
|
|
||||||
|
// Binärwerte in ein Array von booleschen Werten umwandeln
|
||||||
|
$boolValues = array_map(
|
||||||
|
fn($bit) => $bit === "1",
|
||||||
|
str_split($binaryString)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->SetValue("DI1", $boolValues[7]);
|
||||||
|
$this->SetValue("DI2", $boolValues[6]);
|
||||||
|
$this->SetValue("DI3", $boolValues[5]);
|
||||||
|
$this->SetValue("DI4", $boolValues[4]);
|
||||||
|
$this->SetValue("DI5", $boolValues[3]);
|
||||||
|
$this->SetValue("DI6", $boolValues[2]);
|
||||||
|
$this->SetValue("DI7", $boolValues[1]);
|
||||||
|
$this->SetValue("DI8", $boolValues[0]);
|
||||||
|
return $boolValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Die gelesene Zahl bereinigen (Leerzeichen oder Zeilenumbrüche entfernen)
|
|
||||||
$number = trim($content);
|
|
||||||
|
|
||||||
// Sicherstellen, dass die Zahl gültig ist
|
|
||||||
if (!ctype_digit($number)) {
|
|
||||||
throw new Exception("Der Inhalt der Datei ist keine gültige Zahl: $number");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Die Zahl in einen Integer umwandeln
|
|
||||||
$intValue = (int)$number;
|
|
||||||
|
|
||||||
// Sicherstellen, dass die Zahl zwischen 0 und 255 liegt
|
|
||||||
if ($intValue < 0 || $intValue > 255) {
|
|
||||||
throw new Exception("Die Zahl muss zwischen 0 und 255 liegen: $intValue");
|
|
||||||
}
|
|
||||||
|
|
||||||
// In einen 8-Bit-Binärstring umwandeln
|
|
||||||
$binaryString = str_pad(decbin($intValue), 8, "0", STR_PAD_LEFT);
|
|
||||||
|
|
||||||
// Binärwerte in ein Array von booleschen Werten umwandeln
|
|
||||||
$boolValues = array_map(fn($bit) => $bit === "1", str_split($binaryString));
|
|
||||||
|
|
||||||
$this->SetValue("DI1", $boolValues[7]);
|
|
||||||
$this->SetValue("DI2", $boolValues[6]);
|
|
||||||
$this->SetValue("DI3", $boolValues[5]);
|
|
||||||
$this->SetValue("DI4", $boolValues[4]);
|
|
||||||
$this->SetValue("DI5", $boolValues[3]);
|
|
||||||
$this->SetValue("DI6", $boolValues[2]);
|
|
||||||
$this->SetValue("DI7", $boolValues[1]);
|
|
||||||
$this->SetValue("DI8", $boolValues[0]);
|
|
||||||
return $boolValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function TryWriteFile($starttime)
|
private function TryWriteFile($starttime)
|
||||||
{
|
{
|
||||||
$this->readAndConvertToBools("/sys/devices/platform/soc/44009000.spi/spi_master/spi0/spi0.0/din");
|
$this->readAndConvertToBools($DIN_FILE);
|
||||||
|
|
||||||
$currentTime = microtime(true) * 1000;
|
$currentTime = microtime(true) * 1000;
|
||||||
if (($currentTime - $starttime) <= $this->maxTime) {
|
if ($currentTime - $starttime <= $this->maxTime) {
|
||||||
$file = $this->ReadPropertyString('FilePath');
|
$file = $this->ReadPropertyString("FilePath");
|
||||||
if (is_writable($file)) {
|
if (is_writable($file)) {
|
||||||
$bit1 = GetValueBoolean($this->GetIDForIdent('Bit1'));
|
$bit1 = GetValueBoolean($this->GetIDForIdent("Bit1"));
|
||||||
$bit2 = GetValueBoolean($this->GetIDForIdent('Bit2'));
|
$bit2 = GetValueBoolean($this->GetIDForIdent("Bit2"));
|
||||||
$bit3 = GetValueBoolean($this->GetIDForIdent('Bit3'));
|
$bit3 = GetValueBoolean($this->GetIDForIdent("Bit3"));
|
||||||
$bit4 = GetValueBoolean($this->GetIDForIdent('Bit4'));
|
$bit4 = GetValueBoolean($this->GetIDForIdent("Bit4"));
|
||||||
|
|
||||||
$value = ($bit4 ? 8 : 0) + ($bit3 ? 4 : 0) + ($bit2 ? 2 : 0) + ($bit1 ? 1 : 0);
|
$value =
|
||||||
|
($bit4 ? 8 : 0) +
|
||||||
|
($bit3 ? 4 : 0) +
|
||||||
|
($bit2 ? 2 : 0) +
|
||||||
|
($bit1 ? 1 : 0);
|
||||||
|
|
||||||
if (@file_put_contents($file, $value) === false) {
|
if (@file_put_contents($file, $value) === false) {
|
||||||
IPS_LogMessage("DOUTModule", "Fehler: Datei $file konnte nicht beschrieben werden. Möglicherweise gesperrt.");
|
|
||||||
usleep($this->waitingTime * 1000);
|
usleep($this->waitingTime * 1000);
|
||||||
$this->TryWriteFile($starttime);
|
$this->TryWriteFile($starttime);
|
||||||
} else {
|
|
||||||
IPS_LogMessage("DOUTModule", "Wert $value erfolgreich in die Datei $file geschrieben.");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IPS_LogMessage("DOUTModule", "Fehler: Datei $file ist nicht schreibbar.");
|
|
||||||
usleep($this->waitingTime * 1000);
|
usleep($this->waitingTime * 1000);
|
||||||
$this->TryWriteFile($starttime);
|
$this->TryWriteFile($starttime);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IPS_LogMessage("DOUTModule", "Fehler: Schreibvorgang für Datei $file hat zu lange gedauert.");
|
IPS_LogMessage(
|
||||||
|
"DOUTModule",
|
||||||
|
"Fehler: Schreibvorgang für Datei $file hat zu lange gedauert."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,8 +157,8 @@ class CC100_HW extends IPSModule
|
|||||||
$pt1Value = $this->ReadPTValue($this->PT1PID);
|
$pt1Value = $this->ReadPTValue($this->PT1PID);
|
||||||
$pt2Value = $this->ReadPTValue($this->PT2PID);
|
$pt2Value = $this->ReadPTValue($this->PT2PID);
|
||||||
|
|
||||||
SetValue($this->GetIDForIdent('PT1'), $pt1Value);
|
SetValue($this->GetIDForIdent("PT1"), $pt1Value);
|
||||||
SetValue($this->GetIDForIdent('PT2'), $pt2Value);
|
SetValue($this->GetIDForIdent("PT2"), $pt2Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function ReadPTValue($file)
|
private function ReadPTValue($file)
|
||||||
@@ -160,21 +168,35 @@ class CC100_HW extends IPSModule
|
|||||||
if ($data !== false) {
|
if ($data !== false) {
|
||||||
$data = intval($data);
|
$data = intval($data);
|
||||||
$scale = 0;
|
$scale = 0;
|
||||||
if ($data >= 600 && $data < 3600) { $scale = 37;}
|
if ($data >= 600 && $data < 3600) {
|
||||||
else if ($data >= 3600 && $data < 6700) { $scale = 43;}
|
$scale = 37;
|
||||||
else if ($data >= 6700 && $data < 9750) { $scale = 45;}
|
} elseif ($data >= 3600 && $data < 6700) {
|
||||||
else if ($data >= 9750 && $data < 12740) { $scale = 49;}
|
$scale = 43;
|
||||||
else if ($data >= 12740 && $data < 15700) { $scale = 50.6;}
|
} elseif ($data >= 6700 && $data < 9750) {
|
||||||
else if ($data >= 15700 && $data < 21000) { $scale = 52.4;}
|
$scale = 45;
|
||||||
else if ($data > 21000) { $scale = 53.7;}
|
} elseif ($data >= 9750 && $data < 12740) {
|
||||||
|
$scale = 49;
|
||||||
|
} elseif ($data >= 12740 && $data < 15700) {
|
||||||
|
$scale = 50.6;
|
||||||
|
} elseif ($data >= 15700 && $data < 21000) {
|
||||||
|
$scale = 52.4;
|
||||||
|
} elseif ($data > 21000) {
|
||||||
|
$scale = 53.7;
|
||||||
|
}
|
||||||
|
|
||||||
$numb = $data / $scale - 200;
|
$numb = $data / $scale - 200;
|
||||||
return round($numb, 1);
|
return round($numb, 1);
|
||||||
} else {
|
} else {
|
||||||
IPS_LogMessage("DOUTModule", "Fehler: Datei $file konnte nicht gelesen werden.");
|
IPS_LogMessage(
|
||||||
|
"DOUTModule",
|
||||||
|
"Fehler: Datei $file konnte nicht gelesen werden."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
IPS_LogMessage("DOUTModule", "Fehler: Datei $file existiert nicht.");
|
IPS_LogMessage(
|
||||||
|
"DOUTModule",
|
||||||
|
"Fehler: Datei $file existiert nicht."
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"translations": {
|
|
||||||
"de": {
|
|
||||||
"Translation 1": "Übersetzung 1",
|
|
||||||
"Translation 2": "Übersetzung 2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,492 +1,497 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class Ladestation_Universal extends IPSModule {
|
class Ladestation_Universal extends IPSModule
|
||||||
|
{
|
||||||
|
public function Create()
|
||||||
|
{
|
||||||
|
parent::Create();
|
||||||
|
|
||||||
public function Create() {
|
// Prioritäten
|
||||||
parent::Create();
|
$this->RegisterVariableInteger("LockPrio", "LockPrio");
|
||||||
|
$this->RegisterVariableInteger("UserPrio", "UserPrio");
|
||||||
|
|
||||||
// Prioritäten
|
// Energiehandling
|
||||||
$this->RegisterVariableInteger("LockPrio", "LockPrio");
|
$this->RegisterVariableBoolean("Idle", "Idle", "", 0);
|
||||||
$this->RegisterVariableInteger("UserPrio", "UserPrio");
|
$this->RegisterVariableInteger("CurrentPower", "CurrentPower", "", 0);
|
||||||
|
$this->RegisterVariableFloat("UsedEnergy", "UsedEnergy", "", 0);
|
||||||
|
$this->RegisterVariableString("PowerSteps", "PowerSteps"); // PowerSteps-Variable registrieren
|
||||||
|
|
||||||
// Energiehandling
|
// Trägheit
|
||||||
$this->RegisterVariableBoolean("Idle", "Idle", "", 0);
|
$this->RegisterPropertyInteger("IdleCounterMax", 2);
|
||||||
$this->RegisterVariableInteger("CurrentPower", "CurrentPower", "", 0);
|
$this->RegisterVariableInteger("IdleCounter", "IdleCounter", "", 0);
|
||||||
$this->RegisterVariableFloat("UsedEnergy", "UsedEnergy", "", 0);
|
$this->SetValue("IdleCounter", 0);
|
||||||
$this->RegisterVariableString("PowerSteps", "PowerSteps"); // PowerSteps-Variable registrieren
|
|
||||||
|
|
||||||
// Trägheit
|
// Properties registrieren
|
||||||
$this->RegisterPropertyInteger("IdleCounterMax", 2);
|
$this->RegisterPropertyInteger("MinLeistung", 3600);
|
||||||
$this->RegisterVariableInteger("IdleCounter", "IdleCounter", "", 0);
|
$this->RegisterPropertyInteger("MaxLeistung", 11000);
|
||||||
$this->SetValue("IdleCounter", 0);
|
|
||||||
|
|
||||||
// Properties registrieren
|
$this->RegisterPropertyInteger("MinLeistung_1ph", 1400);
|
||||||
$this->RegisterPropertyInteger("MinLeistung", 3600);
|
$this->RegisterPropertyInteger("MaxLeistung_1ph", 7800);
|
||||||
$this->RegisterPropertyInteger("MaxLeistung", 11000);
|
$this->RegisterPropertyString("IP_Adresse", "0.0.0.0");
|
||||||
|
|
||||||
$this->RegisterPropertyInteger("MinLeistung_1ph", 1400);
|
$this->RegisterVariableBoolean("Ladebereit", "Ladebereit", "~Switch", 11);
|
||||||
$this->RegisterPropertyInteger("MaxLeistung_1ph", 7800);
|
$this->RegisterVariableBoolean("Solarladen", "Solarladen", "~Switch", 11);
|
||||||
$this->RegisterPropertyString("IP_Adresse", "0.0.0.0");
|
$this->RegisterVariableInteger("Fahrzeugstatus", "Fahrzeugstatus", "", 0);
|
||||||
|
$this->RegisterVariableInteger("Lademodus", "Lademodus", "", 0);
|
||||||
|
$this->RegisterVariableFloat("Ladeleistung_Effektiv", "Ladeleistung_Effektiv", "", 0);
|
||||||
|
|
||||||
$this->RegisterVariableBoolean("Ladebereit", "Ladebereit", "~Switch", 11);
|
$this->RegisterVariableBoolean("Peak", "Peak", "", 0);
|
||||||
$this->RegisterVariableBoolean("Solarladen", "Solarladen", "~Switch", 11);
|
|
||||||
$this->RegisterVariableInteger("Fahrzeugstatus", "Fahrzeugstatus", "", 0);
|
|
||||||
$this->RegisterVariableInteger("Lademodus", "Lademodus", "", 0);
|
|
||||||
$this->RegisterVariableFloat("Ladeleistung_Effektiv", "Ladeleistung_Effektiv", "", 0);
|
|
||||||
|
|
||||||
|
$this->RegisterVariableInteger("Ladestrom", "Ladestrom");
|
||||||
|
$this->RegisterVariableInteger("Ladeleistung", "Ladeleistung");
|
||||||
|
|
||||||
|
// Initialisieren
|
||||||
$this->RegisterVariableBoolean("Peak", "Peak", "", 0);
|
$this->SetValue("Idle", true);
|
||||||
|
|
||||||
$this->RegisterVariableInteger("Ladestrom", "Ladestrom");
|
|
||||||
$this->RegisterVariableInteger("Ladeleistung", "Ladeleistung");
|
|
||||||
|
|
||||||
// Initialisieren
|
|
||||||
$this->SetValue("Idle", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ApplyChanges() {
|
|
||||||
parent::ApplyChanges();
|
|
||||||
// Zusätzliche Anpassungen nach Bedarf
|
|
||||||
}
|
|
||||||
|
|
||||||
// Aktionen verarbeiten
|
|
||||||
public function RequestAction($Ident, $Value) {
|
|
||||||
switch ($Ident) {
|
|
||||||
case "SetCurrentPower":
|
|
||||||
$this->SetCurrentPower($Value);
|
|
||||||
break;
|
|
||||||
case "GetCurrentData":
|
|
||||||
$powerSteps = $this->GetCurrentData($Value);
|
|
||||||
return $powerSteps;
|
|
||||||
default:
|
|
||||||
throw new Exception("Invalid Ident");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public function SetCurrentPower(int $power) {
|
public function ApplyChanges()
|
||||||
$internalPower = GetValue($this->GetIDForIdent("CurrentPower"));
|
{
|
||||||
// Aktuelle Leistungsvorgabe setzen
|
parent::ApplyChanges();
|
||||||
SetValue($this->GetIDForIdent("CurrentPower"), $power);
|
// Zusätzliche Anpassungen nach Bedarf
|
||||||
if ($power != $internalPower) {
|
}
|
||||||
// Setze die interne Leistungsvorgabe
|
|
||||||
|
|
||||||
// Idle für 4 Zyklen auf false setzen
|
// Aktionen verarbeiten
|
||||||
SetValue($this->GetIDForIdent("Idle"), false);
|
public function RequestAction($Ident, $Value)
|
||||||
SetValue($this->GetIDForIdent("IdleCounter"), $this->ReadPropertyInteger("IdleCounterMax"));
|
{
|
||||||
} else {
|
switch ($Ident) {
|
||||||
// IdleCallCounter herunterzählen, wenn power == interne Leistungsvorgabe
|
case "SetCurrentPower":
|
||||||
$idleCounter = GetValue($this->GetIDForIdent("IdleCounter"));
|
$this->SetCurrentPower($Value);
|
||||||
if ($idleCounter > 0) {
|
break;
|
||||||
$idleCounter--;
|
case "GetCurrentData":
|
||||||
SetValue($this->GetIDForIdent("IdleCounter"), $idleCounter);
|
$powerSteps = $this->GetCurrentData($Value);
|
||||||
if ($idleCounter == 0) {
|
return $powerSteps;
|
||||||
SetValue($this->GetIDForIdent("Idle"), true);
|
default:
|
||||||
}
|
throw new Exception("Invalid Ident");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function SetCurrentPower(int $power)
|
||||||
|
{
|
||||||
|
$internalPower = GetValue($this->GetIDForIdent("CurrentPower"));
|
||||||
|
// Aktuelle Leistungsvorgabe setzen
|
||||||
|
SetValue($this->GetIDForIdent("CurrentPower"), $power);
|
||||||
|
if ($power != $internalPower) {
|
||||||
|
// Setze die interne Leistungsvorgabe
|
||||||
|
|
||||||
|
// Idle für 4 Zyklen auf false setzen
|
||||||
// Ladeleistung setzen
|
SetValue($this->GetIDForIdent("Idle"), false);
|
||||||
$peak = GetValue($this->GetIDForIdent("Peak"));
|
SetValue(
|
||||||
$solarladen = GetValue($this->GetIDForIdent("Solarladen"));
|
$this->GetIDForIdent("IdleCounter"),
|
||||||
$Ladebereit = GetValue($this->GetIDForIdent("Ladebereit"));
|
$this->ReadPropertyInteger("IdleCounterMax")
|
||||||
if(!$Ladebereit){
|
);
|
||||||
|
|
||||||
$this->sendPowerToStation(0);
|
|
||||||
SetValue($this->GetIDForIdent("Ladeleistung"), 0);
|
|
||||||
SetValue($this->GetIDForIdent("Ladestrom"), 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
elseif (!$peak && !$solarladen) {
|
|
||||||
// Wenn weder Peak noch Solarladen aktiv sind, setze Ladeleistung auf MaxLeistung
|
|
||||||
SetValue($this->GetIDForIdent("Ladeleistung"), $this->ReadPropertyInteger("MaxLeistung"));
|
|
||||||
|
|
||||||
if(GetValue($this->GetIDForIdent("Lademodus"))==0){
|
|
||||||
|
|
||||||
SetValue($this->GetIDForIdent("Ladestrom"), $this->ReadPropertyInteger("MaxLeistung_1ph") / 240);
|
|
||||||
$this->sendPowerToStation($this->ReadPropertyInteger("MaxLeistung_1ph"));
|
|
||||||
|
|
||||||
}elseif(GetValue($this->GetIDForIdent("Lademodus"))==1){
|
|
||||||
|
|
||||||
SetValue($this->GetIDForIdent("Ladestrom"), $this->ReadPropertyInteger("MaxLeistung") / 400 / sqrt(3));
|
|
||||||
$this->sendPowerToStation($this->ReadPropertyInteger("MaxLeistung"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Ansonsten setze Ladeleistung auf die aktuelle Leistungsvorgabe (CurrentPower)
|
|
||||||
SetValue($this->GetIDForIdent("Ladeleistung"), $power);
|
|
||||||
|
|
||||||
if(GetValue($this->GetIDForIdent("Lademodus"))==0){
|
|
||||||
|
|
||||||
SetValue($this->GetIDForIdent("Ladestrom"), $power / 240);
|
|
||||||
|
|
||||||
}elseif(GetValue($this->GetIDForIdent("Lademodus"))==1){
|
|
||||||
|
|
||||||
SetValue($this->GetIDForIdent("Ladestrom"), $power / 400 / sqrt(3));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->sendPowerToStation($power);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Methode zum Abrufen der aktuellen Daten
|
|
||||||
public function GetCurrentData(bool $Peak) {
|
|
||||||
// Aktuelle Properties abrufen
|
|
||||||
$ladebereit = GetValue($this->GetIDForIdent("Ladebereit"));
|
|
||||||
$solarladen = GetValue($this->GetIDForIdent("Solarladen"));
|
|
||||||
|
|
||||||
|
|
||||||
if(GetValue($this->GetIDForIdent("Lademodus"))==0){
|
|
||||||
|
|
||||||
$minLeistung = $this->ReadPropertyInteger("MinLeistung_1ph");
|
|
||||||
$maxLeistung = $this->ReadPropertyInteger("MaxLeistung_1ph");
|
|
||||||
|
|
||||||
}elseif(GetValue($this->GetIDForIdent("Lademodus"))==1){
|
|
||||||
|
|
||||||
$minLeistung = $this->ReadPropertyInteger("MinLeistung");
|
|
||||||
$maxLeistung = $this->ReadPropertyInteger("MaxLeistung");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$ch = curl_init();
|
|
||||||
|
|
||||||
// Setze die URL
|
|
||||||
curl_setopt($ch, CURLOPT_URL, "http://" . $this->ReadPropertyString("IP_Adresse") . "/api/status");
|
|
||||||
|
|
||||||
// Setze die Option, die Antwort als String zurückzugeben
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
|
|
||||||
// Führe die Anfrage aus und speichere die Antwort
|
|
||||||
$response = curl_exec($ch);
|
|
||||||
|
|
||||||
// Schließe cURL
|
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
// Überprüfe, ob die Antwort nicht leer ist
|
|
||||||
if ($response) {
|
|
||||||
// Dekodiere die JSON-Antwort
|
|
||||||
$data = json_decode($response, true);
|
|
||||||
|
|
||||||
// Überprüfe, ob das JSON-Dekodieren erfolgreich war und der Schlüssel "car" existiert
|
|
||||||
if (json_last_error() === JSON_ERROR_NONE && isset($data['car'])) {
|
|
||||||
// Speichere den Wert von "car" in der Variable $status
|
|
||||||
|
|
||||||
|
|
||||||
SetValue($this->GetIDForIdent("Ladeleistung_Effektiv"), $data['nrg'][11]);
|
|
||||||
|
|
||||||
SetValue($this->GetIDForIdent("Fahrzeugstatus"), $data['car']);
|
|
||||||
|
|
||||||
|
|
||||||
if($data['nrg'][6]>1 && $data['car']==2){
|
|
||||||
SetValue($this->GetIDForIdent("Lademodus"), 1);
|
|
||||||
|
|
||||||
}elseif($data['nrg'][6]<=1 && $data['car']==2){
|
|
||||||
SetValue($this->GetIDForIdent("Lademodus"), 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Peak-Wert speichern
|
|
||||||
$this->SetValue("Peak", $Peak);
|
|
||||||
|
|
||||||
// Array für die Powersteps initialisieren
|
|
||||||
$powerSteps = [0];
|
|
||||||
|
|
||||||
if(GetValue($this->GetIDForIdent("Fahrzeugstatus"))!=1){
|
|
||||||
// Konfiguration des powerSteps-Arrays basierend auf den Properties
|
|
||||||
if (!$ladebereit) {
|
|
||||||
$powerSteps = [0];
|
|
||||||
|
|
||||||
} elseif (!$Peak && !$solarladen) {
|
|
||||||
|
|
||||||
$powerSteps = [$maxLeistung];
|
|
||||||
} elseif (!$Peak && $solarladen) {
|
|
||||||
$powerSteps = array_merge($powerSteps, $this->getRangeLimits($minLeistung, $maxLeistung, GetValue($this->GetIDForIdent("Lademodus"))));
|
|
||||||
|
|
||||||
} elseif ($solarladen && $Peak) {
|
|
||||||
$powerSteps = [0];
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$powerSteps += $this->getRangeLimits($minLeistung, $maxLeistung, GetValue($this->GetIDForIdent("Lademodus")));
|
// IdleCallCounter herunterzählen, wenn power == interne Leistungsvorgabe
|
||||||
|
$idleCounter = GetValue($this->GetIDForIdent("IdleCounter"));
|
||||||
|
if ($idleCounter > 0) {
|
||||||
|
$idleCounter--;
|
||||||
|
SetValue($this->GetIDForIdent("IdleCounter"), $idleCounter);
|
||||||
|
if ($idleCounter == 0) {
|
||||||
|
SetValue($this->GetIDForIdent("Idle"), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ladeleistung setzen
|
||||||
|
$peak = GetValue($this->GetIDForIdent("Peak"));
|
||||||
|
$solarladen = GetValue($this->GetIDForIdent("Solarladen"));
|
||||||
|
$Ladebereit = GetValue($this->GetIDForIdent("Ladebereit"));
|
||||||
|
if (!$Ladebereit) {
|
||||||
|
$this->sendPowerToStation(0);
|
||||||
|
SetValue($this->GetIDForIdent("Ladeleistung"), 0);
|
||||||
|
SetValue($this->GetIDForIdent("Ladestrom"), 0);
|
||||||
|
} elseif (!$peak && !$solarladen) {
|
||||||
|
// Wenn weder Peak noch Solarladen aktiv sind, setze Ladeleistung auf MaxLeistung
|
||||||
|
SetValue(
|
||||||
|
$this->GetIDForIdent("Ladeleistung"),
|
||||||
|
$this->ReadPropertyInteger("MaxLeistung")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GetValue($this->GetIDForIdent("Lademodus")) == 0) {
|
||||||
|
SetValue(
|
||||||
|
$this->GetIDForIdent("Ladestrom"),
|
||||||
|
$this->ReadPropertyInteger("MaxLeistung_1ph") / 240
|
||||||
|
);
|
||||||
|
$this->sendPowerToStation(
|
||||||
|
$this->ReadPropertyInteger("MaxLeistung_1ph")
|
||||||
|
);
|
||||||
|
} elseif (GetValue($this->GetIDForIdent("Lademodus")) == 1) {
|
||||||
|
SetValue(
|
||||||
|
$this->GetIDForIdent("Ladestrom"),
|
||||||
|
$this->ReadPropertyInteger("MaxLeistung") / 400 / sqrt(3)
|
||||||
|
);
|
||||||
|
$this->sendPowerToStation(
|
||||||
|
$this->ReadPropertyInteger("MaxLeistung")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Ansonsten setze Ladeleistung auf die aktuelle Leistungsvorgabe (CurrentPower)
|
||||||
|
SetValue($this->GetIDForIdent("Ladeleistung"), $power);
|
||||||
|
|
||||||
|
if (GetValue($this->GetIDForIdent("Lademodus")) == 0) {
|
||||||
|
SetValue($this->GetIDForIdent("Ladestrom"), $power / 240);
|
||||||
|
} elseif (GetValue($this->GetIDForIdent("Lademodus")) == 1) {
|
||||||
|
SetValue(
|
||||||
|
$this->GetIDForIdent("Ladestrom"),
|
||||||
|
$power / 400 / sqrt(3)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->sendPowerToStation($power);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// PowerSteps in der RegisterVariable speichern
|
|
||||||
SetValue($this->GetIDForIdent("PowerSteps"), json_encode($powerSteps));
|
|
||||||
|
|
||||||
// Rückgabe der Powersteps
|
// Methode zum Abrufen der aktuellen Daten
|
||||||
return $powerSteps;
|
public function GetCurrentData(bool $Peak)
|
||||||
}
|
{
|
||||||
|
// Aktuelle Properties abrufen
|
||||||
|
$ladebereit = GetValue($this->GetIDForIdent("Ladebereit"));
|
||||||
|
$solarladen = GetValue($this->GetIDForIdent("Solarladen"));
|
||||||
|
|
||||||
|
if (GetValue($this->GetIDForIdent("Lademodus")) == 0) {
|
||||||
|
$minLeistung = $this->ReadPropertyInteger("MinLeistung_1ph");
|
||||||
|
$maxLeistung = $this->ReadPropertyInteger("MaxLeistung_1ph");
|
||||||
|
} elseif (GetValue($this->GetIDForIdent("Lademodus")) == 1) {
|
||||||
|
$minLeistung = $this->ReadPropertyInteger("MinLeistung");
|
||||||
|
$maxLeistung = $this->ReadPropertyInteger("MaxLeistung");
|
||||||
|
}
|
||||||
|
|
||||||
public function sendPowerToStation($value) {
|
$ch = curl_init();
|
||||||
// Base URL
|
|
||||||
$baseUrl = "http://" . $this->ReadPropertyString("IP_Adresse") . "/api/set?";
|
|
||||||
IPS_LogMessage("Ladestation", "Aufgerufene ip" . $baseUrl);
|
|
||||||
$value = $this->convertPowerToCurrent($value, GetValue($this->GetIDForIdent("Lademodus")));
|
|
||||||
// Initialize a cURL session
|
|
||||||
$ch = curl_init();
|
|
||||||
|
|
||||||
// If value is 0, make a single request
|
// Setze die URL
|
||||||
if ($value == 0) {
|
curl_setopt(
|
||||||
$url = $baseUrl . "frc=1";
|
$ch,
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
CURLOPT_URL,
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
"http://" . $this->ReadPropertyString("IP_Adresse") . "/api/status"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Setze die Option, die Antwort als String zurückzugeben
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
|
||||||
|
// Führe die Anfrage aus und speichere die Antwort
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
curl_close($ch);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For value between 1 and 32, make two requests
|
// Schließe cURL
|
||||||
else if ($value >= 1 && $value <= 32) {
|
|
||||||
// First request
|
|
||||||
$url1 = $baseUrl . "frc=2";
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $url1);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
||||||
$response1 = curl_exec($ch);
|
|
||||||
|
|
||||||
// Check for errors
|
|
||||||
if (curl_errno($ch)) {
|
|
||||||
curl_close($ch);
|
|
||||||
return 'Error:' . curl_error($ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Second request
|
|
||||||
$url2 = $baseUrl . "amp=$value";
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $url2);
|
|
||||||
$response2 = curl_exec($ch);
|
|
||||||
|
|
||||||
// Check for errors
|
|
||||||
if (curl_errno($ch)) {
|
|
||||||
curl_close($ch);
|
|
||||||
return 'Error:' . curl_error($ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close cURL session
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
// Return responses
|
// Überprüfe, ob die Antwort nicht leer ist
|
||||||
return [$response1, $response2];
|
if ($response) {
|
||||||
|
// Dekodiere die JSON-Antwort
|
||||||
|
$data = json_decode($response, true);
|
||||||
|
|
||||||
|
// Überprüfe, ob das JSON-Dekodieren erfolgreich war und der Schlüssel "car" existiert
|
||||||
|
if (json_last_error() === JSON_ERROR_NONE && isset($data["car"])) {
|
||||||
|
// Speichere den Wert von "car" in der Variable $status
|
||||||
|
|
||||||
|
SetValue(
|
||||||
|
$this->GetIDForIdent("Ladeleistung_Effektiv"),
|
||||||
|
$data["nrg"][11]
|
||||||
|
);
|
||||||
|
|
||||||
|
SetValue($this->GetIDForIdent("Fahrzeugstatus"), $data["car"]);
|
||||||
|
|
||||||
|
if ($data["nrg"][6] > 1 && $data["car"] == 2) {
|
||||||
|
SetValue($this->GetIDForIdent("Lademodus"), 1);
|
||||||
|
} elseif ($data["nrg"][6] <= 1 && $data["car"] == 2) {
|
||||||
|
SetValue($this->GetIDForIdent("Lademodus"), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Peak-Wert speichern
|
||||||
|
$this->SetValue("Peak", $Peak);
|
||||||
|
|
||||||
|
// Array für die Powersteps initialisieren
|
||||||
|
$powerSteps = [0];
|
||||||
|
|
||||||
|
if (GetValue($this->GetIDForIdent("Fahrzeugstatus")) != 1) {
|
||||||
|
// Konfiguration des powerSteps-Arrays basierend auf den Properties
|
||||||
|
if (!$ladebereit) {
|
||||||
|
$powerSteps = [0];
|
||||||
|
} elseif (!$Peak && !$solarladen) {
|
||||||
|
$powerSteps = [$maxLeistung];
|
||||||
|
} elseif (!$Peak && $solarladen) {
|
||||||
|
$powerSteps = array_merge(
|
||||||
|
$powerSteps,
|
||||||
|
$this->getRangeLimits(
|
||||||
|
$minLeistung,
|
||||||
|
$maxLeistung,
|
||||||
|
GetValue($this->GetIDForIdent("Lademodus"))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} elseif ($solarladen && $Peak) {
|
||||||
|
$powerSteps = [0];
|
||||||
|
} else {
|
||||||
|
$powerSteps += $this->getRangeLimits(
|
||||||
|
$minLeistung,
|
||||||
|
$maxLeistung,
|
||||||
|
GetValue($this->GetIDForIdent("Lademodus"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// PowerSteps in der RegisterVariable speichern
|
||||||
|
SetValue($this->GetIDForIdent("PowerSteps"), json_encode($powerSteps));
|
||||||
|
|
||||||
|
// Rückgabe der Powersteps
|
||||||
|
return $powerSteps;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If value is out of range
|
public function sendPowerToStation($value)
|
||||||
else {
|
{
|
||||||
return "Invalid value. Must be between 0 and 32.";
|
// Base URL
|
||||||
}
|
$baseUrl =
|
||||||
}
|
"http://" . $this->ReadPropertyString("IP_Adresse") . "/api/set?";
|
||||||
|
IPS_LogMessage("Ladestation", "Aufgerufene ip" . $baseUrl);
|
||||||
|
$value = $this->convertPowerToCurrent(
|
||||||
|
$value,
|
||||||
|
GetValue($this->GetIDForIdent("Lademodus"))
|
||||||
|
);
|
||||||
|
// Initialize a cURL session
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
public function convertPowerToCurrent($value, $Lademodus) {
|
// If value is 0, make a single request
|
||||||
|
|
||||||
if($Lademodus==1){
|
|
||||||
if ($value == 0) {
|
if ($value == 0) {
|
||||||
return 0;
|
$url = $baseUrl . "frc=1";
|
||||||
} elseif ($value == 4150) {
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
return 6;
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
} elseif ($value == 4850) {
|
$response = curl_exec($ch);
|
||||||
return 7;
|
curl_close($ch);
|
||||||
} elseif ($value == 5550) {
|
return $response;
|
||||||
return 8;
|
}
|
||||||
} elseif ($value == 6250) {
|
|
||||||
return 9;
|
|
||||||
} elseif ($value == 6950) {
|
|
||||||
return 10;
|
|
||||||
} elseif ($value == 7600) {
|
|
||||||
return 11;
|
|
||||||
} elseif ($value == 8300) {
|
|
||||||
return 12;
|
|
||||||
} elseif ($value == 9000) {
|
|
||||||
return 13;
|
|
||||||
} elseif ($value == 9700) {
|
|
||||||
return 14;
|
|
||||||
} elseif ($value == 10300) {
|
|
||||||
return 15;
|
|
||||||
} elseif ($value == 11000) {
|
|
||||||
return 16;
|
|
||||||
} elseif ($value == 11750) {
|
|
||||||
return 17;
|
|
||||||
} elseif ($value == 12450) {
|
|
||||||
return 18;
|
|
||||||
} elseif ($value == 13150) {
|
|
||||||
return 19;
|
|
||||||
} elseif ($value == 13850) {
|
|
||||||
return 20;
|
|
||||||
} elseif ($value == 14550) {
|
|
||||||
return 21;
|
|
||||||
} elseif ($value == 15250) {
|
|
||||||
return 22;
|
|
||||||
} elseif ($value == 15900) {
|
|
||||||
return 23;
|
|
||||||
} elseif ($value == 16600) {
|
|
||||||
return 24;
|
|
||||||
} elseif ($value == 17300) {
|
|
||||||
return 25;
|
|
||||||
} elseif ($value == 18000) {
|
|
||||||
return 26;
|
|
||||||
} elseif ($value == 18700) {
|
|
||||||
return 27;
|
|
||||||
} elseif ($value == 19400) {
|
|
||||||
return 28;
|
|
||||||
} elseif ($value == 20100) {
|
|
||||||
return 29;
|
|
||||||
} elseif ($value == 20800) {
|
|
||||||
return 30;
|
|
||||||
} elseif ($value == 21500) {
|
|
||||||
return 31;
|
|
||||||
} elseif ($value >= 22000) {
|
|
||||||
return 32;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}elseif($Lademodus==0){
|
// For value between 1 and 32, make two requests
|
||||||
if ($value == 0) {
|
elseif ($value >= 1 && $value <= 32) {
|
||||||
|
// First request
|
||||||
|
$url1 = $baseUrl . "frc=2";
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url1);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
$response1 = curl_exec($ch);
|
||||||
|
|
||||||
|
// Check for errors
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
curl_close($ch);
|
||||||
|
return "Error:" . curl_error($ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second request
|
||||||
|
$url2 = $baseUrl . "amp=$value";
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $url2);
|
||||||
|
$response2 = curl_exec($ch);
|
||||||
|
|
||||||
|
// Check for errors
|
||||||
|
if (curl_errno($ch)) {
|
||||||
|
curl_close($ch);
|
||||||
|
return "Error:" . curl_error($ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close cURL session
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
// Return responses
|
||||||
|
return [$response1, $response2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// If value is out of range
|
||||||
|
else {
|
||||||
|
return "Invalid value. Must be between 0 and 32.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function convertPowerToCurrent($value, $Lademodus)
|
||||||
|
{
|
||||||
|
if ($Lademodus == 1) {
|
||||||
|
if ($value == 0) {
|
||||||
|
return 0;
|
||||||
|
} elseif ($value == 4150) {
|
||||||
|
return 6;
|
||||||
|
} elseif ($value == 4850) {
|
||||||
|
return 7;
|
||||||
|
} elseif ($value == 5550) {
|
||||||
|
return 8;
|
||||||
|
} elseif ($value == 6250) {
|
||||||
|
return 9;
|
||||||
|
} elseif ($value == 6950) {
|
||||||
|
return 10;
|
||||||
|
} elseif ($value == 7600) {
|
||||||
|
return 11;
|
||||||
|
} elseif ($value == 8300) {
|
||||||
|
return 12;
|
||||||
|
} elseif ($value == 9000) {
|
||||||
|
return 13;
|
||||||
|
} elseif ($value == 9700) {
|
||||||
|
return 14;
|
||||||
|
} elseif ($value == 10300) {
|
||||||
|
return 15;
|
||||||
|
} elseif ($value == 11000) {
|
||||||
|
return 16;
|
||||||
|
} elseif ($value == 11750) {
|
||||||
|
return 17;
|
||||||
|
} elseif ($value == 12450) {
|
||||||
|
return 18;
|
||||||
|
} elseif ($value == 13150) {
|
||||||
|
return 19;
|
||||||
|
} elseif ($value == 13850) {
|
||||||
|
return 20;
|
||||||
|
} elseif ($value == 14550) {
|
||||||
|
return 21;
|
||||||
|
} elseif ($value == 15250) {
|
||||||
|
return 22;
|
||||||
|
} elseif ($value == 15900) {
|
||||||
|
return 23;
|
||||||
|
} elseif ($value == 16600) {
|
||||||
|
return 24;
|
||||||
|
} elseif ($value == 17300) {
|
||||||
|
return 25;
|
||||||
|
} elseif ($value == 18000) {
|
||||||
|
return 26;
|
||||||
|
} elseif ($value == 18700) {
|
||||||
|
return 27;
|
||||||
|
} elseif ($value == 19400) {
|
||||||
|
return 28;
|
||||||
|
} elseif ($value == 20100) {
|
||||||
|
return 29;
|
||||||
|
} elseif ($value == 20800) {
|
||||||
|
return 30;
|
||||||
|
} elseif ($value == 21500) {
|
||||||
|
return 31;
|
||||||
|
} elseif ($value >= 22000) {
|
||||||
|
return 32;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
} elseif ($Lademodus == 0) {
|
||||||
|
if ($value == 0) {
|
||||||
|
return 0;
|
||||||
|
} elseif ($value == 1450) {
|
||||||
|
return 6;
|
||||||
|
} elseif ($value == 1690) {
|
||||||
|
return 7;
|
||||||
|
} elseif ($value == 1930) {
|
||||||
|
return 8;
|
||||||
|
} elseif ($value == 2170) {
|
||||||
|
return 9;
|
||||||
|
} elseif ($value == 2410) {
|
||||||
|
return 10;
|
||||||
|
} elseif ($value == 2650) {
|
||||||
|
return 11;
|
||||||
|
} elseif ($value == 2890) {
|
||||||
|
return 12;
|
||||||
|
} elseif ($value == 3130) {
|
||||||
|
return 13;
|
||||||
|
} elseif ($value == 3370) {
|
||||||
|
return 14;
|
||||||
|
} elseif ($value == 3610) {
|
||||||
|
return 15;
|
||||||
|
} elseif ($value == 3850) {
|
||||||
|
return 16;
|
||||||
|
} elseif ($value == 4090) {
|
||||||
|
return 17;
|
||||||
|
} elseif ($value == 4330) {
|
||||||
|
return 18;
|
||||||
|
} elseif ($value == 4570) {
|
||||||
|
return 19;
|
||||||
|
} elseif ($value == 4810) {
|
||||||
|
return 20;
|
||||||
|
} elseif ($value == 5050) {
|
||||||
|
return 21;
|
||||||
|
} elseif ($value == 5290) {
|
||||||
|
return 22;
|
||||||
|
} elseif ($value == 5530) {
|
||||||
|
return 23;
|
||||||
|
} elseif ($value == 5770) {
|
||||||
|
return 24;
|
||||||
|
} elseif ($value == 6010) {
|
||||||
|
return 25;
|
||||||
|
} elseif ($value == 6250) {
|
||||||
|
return 26;
|
||||||
|
} elseif ($value == 6490) {
|
||||||
|
return 27;
|
||||||
|
} elseif ($value == 6730) {
|
||||||
|
return 28;
|
||||||
|
} elseif ($value == 6970) {
|
||||||
|
return 29;
|
||||||
|
} elseif ($value == 7210) {
|
||||||
|
return 30;
|
||||||
|
} elseif ($value == 7450) {
|
||||||
|
return 31;
|
||||||
|
} elseif ($value >= 7690) {
|
||||||
|
return 32;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} elseif ($value == 1450) {
|
|
||||||
return 6;
|
|
||||||
} elseif ($value == 1690) {
|
|
||||||
return 7;
|
|
||||||
} elseif ($value == 1930) {
|
|
||||||
return 8;
|
|
||||||
} elseif ($value == 2170) {
|
|
||||||
return 9;
|
|
||||||
} elseif ($value == 2410) {
|
|
||||||
return 10;
|
|
||||||
} elseif ($value == 2650) {
|
|
||||||
return 11;
|
|
||||||
} elseif ($value == 2890) {
|
|
||||||
return 12;
|
|
||||||
} elseif ($value == 3130) {
|
|
||||||
return 13;
|
|
||||||
} elseif ($value == 3370) {
|
|
||||||
return 14;
|
|
||||||
} elseif ($value == 3610) {
|
|
||||||
return 15;
|
|
||||||
} elseif ($value == 3850) {
|
|
||||||
return 16;
|
|
||||||
} elseif ($value == 4090) {
|
|
||||||
return 17;
|
|
||||||
} elseif ($value == 4330) {
|
|
||||||
return 18;
|
|
||||||
} elseif ($value == 4570) {
|
|
||||||
return 19;
|
|
||||||
} elseif ($value == 4810) {
|
|
||||||
return 20;
|
|
||||||
} elseif ($value == 5050) {
|
|
||||||
return 21;
|
|
||||||
} elseif ($value == 5290) {
|
|
||||||
return 22;
|
|
||||||
} elseif ($value == 5530) {
|
|
||||||
return 23;
|
|
||||||
} elseif ($value == 5770) {
|
|
||||||
return 24;
|
|
||||||
} elseif ($value == 6010) {
|
|
||||||
return 25;
|
|
||||||
} elseif ($value == 6250) {
|
|
||||||
return 26;
|
|
||||||
} elseif ($value == 6490) {
|
|
||||||
return 27;
|
|
||||||
} elseif ($value == 6730) {
|
|
||||||
return 28;
|
|
||||||
} elseif ($value == 6970) {
|
|
||||||
return 29;
|
|
||||||
} elseif ($value == 7210) {
|
|
||||||
return 30;
|
|
||||||
} elseif ($value == 7450) {
|
|
||||||
return 31;
|
|
||||||
} elseif ($value >= 7690) {
|
|
||||||
return 32;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRangeLimits($min, $max, $Lademodus) {
|
|
||||||
if($Lademodus==1){
|
|
||||||
$limits = [
|
|
||||||
4150,
|
|
||||||
4850,
|
|
||||||
5550,
|
|
||||||
6250,
|
|
||||||
6950,
|
|
||||||
7600,
|
|
||||||
8300,
|
|
||||||
9000,
|
|
||||||
9700,
|
|
||||||
10300,
|
|
||||||
11000,
|
|
||||||
11750,
|
|
||||||
12450,
|
|
||||||
13150,
|
|
||||||
13850,
|
|
||||||
14550,
|
|
||||||
15250,
|
|
||||||
15900,
|
|
||||||
16600,
|
|
||||||
17300,
|
|
||||||
18000,
|
|
||||||
18700,
|
|
||||||
19400,
|
|
||||||
20100,
|
|
||||||
20800,
|
|
||||||
21500,
|
|
||||||
22000
|
|
||||||
];}
|
|
||||||
elseif($Lademodus==0){
|
|
||||||
$limits = [
|
|
||||||
1450,
|
|
||||||
1690,
|
|
||||||
1930,
|
|
||||||
2170,
|
|
||||||
2410,
|
|
||||||
2650,
|
|
||||||
2890,
|
|
||||||
3130,
|
|
||||||
3370,
|
|
||||||
3610,
|
|
||||||
3850,
|
|
||||||
4090,
|
|
||||||
4330,
|
|
||||||
4570,
|
|
||||||
4810,
|
|
||||||
5050,
|
|
||||||
5290,
|
|
||||||
5530,
|
|
||||||
5770,
|
|
||||||
6010,
|
|
||||||
6250,
|
|
||||||
6490,
|
|
||||||
6730,
|
|
||||||
6970,
|
|
||||||
7210,
|
|
||||||
7450,
|
|
||||||
7690
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = [];
|
|
||||||
|
|
||||||
foreach ($limits as $limit) {
|
|
||||||
if ($limit >= $min && $limit <= $max) {
|
|
||||||
$result[] = $limit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
public function getRangeLimits($min, $max, $Lademodus)
|
||||||
}
|
{
|
||||||
|
if ($Lademodus == 1) {
|
||||||
|
$limits = [
|
||||||
|
4150,
|
||||||
|
4850,
|
||||||
|
5550,
|
||||||
|
6250,
|
||||||
|
6950,
|
||||||
|
7600,
|
||||||
|
8300,
|
||||||
|
9000,
|
||||||
|
9700,
|
||||||
|
10300,
|
||||||
|
11000,
|
||||||
|
11750,
|
||||||
|
12450,
|
||||||
|
13150,
|
||||||
|
13850,
|
||||||
|
14550,
|
||||||
|
15250,
|
||||||
|
15900,
|
||||||
|
16600,
|
||||||
|
17300,
|
||||||
|
18000,
|
||||||
|
18700,
|
||||||
|
19400,
|
||||||
|
20100,
|
||||||
|
20800,
|
||||||
|
21500,
|
||||||
|
22000,
|
||||||
|
];
|
||||||
|
} elseif ($Lademodus == 0) {
|
||||||
|
$limits = [
|
||||||
|
1450,
|
||||||
|
1690,
|
||||||
|
1930,
|
||||||
|
2170,
|
||||||
|
2410,
|
||||||
|
2650,
|
||||||
|
2890,
|
||||||
|
3130,
|
||||||
|
3370,
|
||||||
|
3610,
|
||||||
|
3850,
|
||||||
|
4090,
|
||||||
|
4330,
|
||||||
|
4570,
|
||||||
|
4810,
|
||||||
|
5050,
|
||||||
|
5290,
|
||||||
|
5530,
|
||||||
|
5770,
|
||||||
|
6010,
|
||||||
|
6250,
|
||||||
|
6490,
|
||||||
|
6730,
|
||||||
|
6970,
|
||||||
|
7210,
|
||||||
|
7450,
|
||||||
|
7690,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($limits as $limit) {
|
||||||
|
if ($limit >= $min && $limit <= $max) {
|
||||||
|
$result[] = $limit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"translations": {
|
|
||||||
"de": {
|
|
||||||
"Translation 1": "Übersetzung 1",
|
|
||||||
"Translation 2": "Übersetzung 2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,7 +13,13 @@ class Manager extends IPSModule
|
|||||||
$this->RegisterPropertyString("EnergyUserList", "[]");
|
$this->RegisterPropertyString("EnergyUserList", "[]");
|
||||||
|
|
||||||
// Timer registrieren
|
// Timer registrieren
|
||||||
$this->RegisterTimer("Timer_DistributeEnergy", 5000, 'IPS_RequestAction(' . $this->InstanceID . ', "DistributeEnergy", "");');
|
$this->RegisterTimer(
|
||||||
|
"Timer_DistributeEnergy",
|
||||||
|
5000,
|
||||||
|
"IPS_RequestAction(" .
|
||||||
|
$this->InstanceID .
|
||||||
|
', "DistributeEnergy", "");'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges()
|
public function ApplyChanges()
|
||||||
@@ -41,10 +47,11 @@ class Manager extends IPSModule
|
|||||||
public function DistributeEnergy()
|
public function DistributeEnergy()
|
||||||
{
|
{
|
||||||
// Systemvariablen abrufen
|
// Systemvariablen abrufen
|
||||||
$Netzbezug = GetValue($this->ReadPropertyInteger('Netzbezug'));
|
$Netzbezug = GetValue($this->ReadPropertyInteger("Netzbezug"));
|
||||||
$Peakleistung = $this->ReadPropertyInteger('Peakleistung');
|
$Peakleistung = $this->ReadPropertyInteger("Peakleistung");
|
||||||
$Ueberschussleistung = $this->ReadPropertyInteger('Ueberschussleistung');
|
$Ueberschussleistung = $this->ReadPropertyInteger(
|
||||||
|
"Ueberschussleistung"
|
||||||
|
);
|
||||||
|
|
||||||
// Fallunterscheidung
|
// Fallunterscheidung
|
||||||
if ($Netzbezug < ($Peakleistung - $Ueberschussleistung) / 2) {
|
if ($Netzbezug < ($Peakleistung - $Ueberschussleistung) / 2) {
|
||||||
@@ -66,8 +73,12 @@ class Manager extends IPSModule
|
|||||||
|
|
||||||
// Schleife, um IPS_RequestAction für alle Benutzer auszuführen
|
// Schleife, um IPS_RequestAction für alle Benutzer auszuführen
|
||||||
foreach ($energyUserList as $user) {
|
foreach ($energyUserList as $user) {
|
||||||
if (IPS_InstanceExists($user['EnergyUser'])) {
|
if (IPS_InstanceExists($user["EnergyUser"])) {
|
||||||
IPS_RequestAction($user['EnergyUser'], 'GetCurrentData', $getCurrentDataParam);
|
IPS_RequestAction(
|
||||||
|
$user["EnergyUser"],
|
||||||
|
"GetCurrentData",
|
||||||
|
$getCurrentDataParam
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,29 +87,29 @@ class Manager extends IPSModule
|
|||||||
$totalCurrentPower = 0; // Variable zur Summierung der CurrentPower Werte
|
$totalCurrentPower = 0; // Variable zur Summierung der CurrentPower Werte
|
||||||
|
|
||||||
foreach ($energyUserList as $user) {
|
foreach ($energyUserList as $user) {
|
||||||
if (!IPS_InstanceExists($user['EnergyUser'])) {
|
if (!IPS_InstanceExists($user["EnergyUser"])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Werte direkt von der EnergyUser-Instanz abrufen
|
// Werte direkt von der EnergyUser-Instanz abrufen
|
||||||
$currentPower = GetValue(IPS_GetObjectIDByIdent('CurrentPower', $user['EnergyUser']));
|
$currentPower = GetValue(IPS_GetObjectIDByIdent("CurrentPower", $user["EnergyUser"]));
|
||||||
$usedEnergy = GetValue(IPS_GetObjectIDByIdent('UsedEnergy', $user['EnergyUser']));
|
$usedEnergy = GetValue(IPS_GetObjectIDByIdent("UsedEnergy", $user["EnergyUser"]));
|
||||||
$userPrio = GetValue(IPS_GetObjectIDByIdent('UserPrio', $user['EnergyUser']));
|
$userPrio = GetValue(IPS_GetObjectIDByIdent("UserPrio", $user["EnergyUser"]));
|
||||||
$lockPrio = GetValue(IPS_GetObjectIDByIdent('LockPrio', $user['EnergyUser']));
|
$lockPrio = GetValue(IPS_GetObjectIDByIdent("LockPrio", $user["EnergyUser"]));
|
||||||
$idle = GetValue(IPS_GetObjectIDByIdent('Idle', $user['EnergyUser']));
|
$idle = GetValue(IPS_GetObjectIDByIdent("Idle", $user["EnergyUser"]));
|
||||||
$powerStepsJson = GetValue(IPS_GetObjectIDByIdent('PowerSteps', $user['EnergyUser']));
|
$powerStepsJson = GetValue(IPS_GetObjectIDByIdent("PowerSteps", $user["EnergyUser"]));
|
||||||
$powerSteps = json_decode($powerStepsJson, true);
|
$powerSteps = json_decode($powerStepsJson, true);
|
||||||
|
|
||||||
// EnergyUser-Daten zum gefilterten Array hinzufügen
|
// EnergyUser-Daten zum gefilterten Array hinzufügen
|
||||||
$filteredEnergyUsers[] = [
|
$filteredEnergyUsers[] = [
|
||||||
'EnergyUser' => $user['EnergyUser'],
|
"EnergyUser" => $user["EnergyUser"],
|
||||||
'InstanceID' => $user['EnergyUser'],
|
"InstanceID" => $user["EnergyUser"],
|
||||||
'CurrentPower' => $currentPower,
|
"CurrentPower" => $currentPower,
|
||||||
'UsedEnergy' => $usedEnergy,
|
"UsedEnergy" => $usedEnergy,
|
||||||
'UserPrio' => $userPrio,
|
"UserPrio" => $userPrio,
|
||||||
'LockPrio' => $lockPrio,
|
"LockPrio" => $lockPrio,
|
||||||
'Idle' => $idle,
|
"Idle" => $idle,
|
||||||
'PowerSteps' => $powerSteps, // PowerSteps direkt hier hinzufügen
|
"PowerSteps" => $powerSteps, // PowerSteps direkt hier hinzufügen
|
||||||
];
|
];
|
||||||
|
|
||||||
// Überprüfen, ob alle Benutzer Idle = true sind
|
// Überprüfen, ob alle Benutzer Idle = true sind
|
||||||
@@ -111,7 +122,6 @@ class Manager extends IPSModule
|
|||||||
}
|
}
|
||||||
$remainingPower += $totalCurrentPower;
|
$remainingPower += $totalCurrentPower;
|
||||||
|
|
||||||
|
|
||||||
if (empty($filteredEnergyUsers)) {
|
if (empty($filteredEnergyUsers)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -119,42 +129,51 @@ class Manager extends IPSModule
|
|||||||
// Wenn nicht alle Benutzer Idle = true sind, rufe SetCurrentPower mit CurrentPower Werten auf
|
// Wenn nicht alle Benutzer Idle = true sind, rufe SetCurrentPower mit CurrentPower Werten auf
|
||||||
if (!$allIdle) {
|
if (!$allIdle) {
|
||||||
foreach ($filteredEnergyUsers as $user) {
|
foreach ($filteredEnergyUsers as $user) {
|
||||||
IPS_RequestAction($user['InstanceID'], 'SetCurrentPower', $user['CurrentPower']);
|
IPS_RequestAction(
|
||||||
|
$user["InstanceID"],
|
||||||
|
"SetCurrentPower",
|
||||||
|
$user["CurrentPower"]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sortiere die EnergyUser nach Priorität basierend auf dem Parameter
|
// Sortiere die EnergyUser nach Priorität basierend auf dem Parameter
|
||||||
usort($filteredEnergyUsers, function ($a, $b) use ($getCurrentDataParam) {
|
usort($filteredEnergyUsers, function ($a, $b) use (
|
||||||
$primaryKey = $getCurrentDataParam ? 'LockPrio' : 'UserPrio';
|
$getCurrentDataParam
|
||||||
|
) {
|
||||||
|
$primaryKey = $getCurrentDataParam ? "LockPrio" : "UserPrio";
|
||||||
|
|
||||||
if ($a[$primaryKey] == $b[$primaryKey]) {
|
if ($a[$primaryKey] == $b[$primaryKey]) {
|
||||||
return $a['UsedEnergy'] <=> $b['UsedEnergy'];
|
return $a["UsedEnergy"] <=> $b["UsedEnergy"];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $a[$primaryKey] <=> $b[$primaryKey];
|
return $a[$primaryKey] <=> $b[$primaryKey];
|
||||||
});
|
});
|
||||||
|
|
||||||
// Primärschlüssel für die Priorität basierend auf dem Parameter auswählen
|
// Primärschlüssel für die Priorität basierend auf dem Parameter auswählen
|
||||||
$priorityKey = $getCurrentDataParam ? 'LockPrio' : 'UserPrio';
|
$priorityKey = $getCurrentDataParam ? "LockPrio" : "UserPrio";
|
||||||
|
|
||||||
// Schleife durch alle Prioritäten
|
// Schleife durch alle Prioritäten
|
||||||
$priorities = array_unique(array_column($filteredEnergyUsers, $priorityKey));
|
$priorities = array_unique(
|
||||||
|
array_column($filteredEnergyUsers, $priorityKey)
|
||||||
|
);
|
||||||
$groupedUsers = [];
|
$groupedUsers = [];
|
||||||
|
|
||||||
foreach ($priorities as $priority) {
|
foreach ($priorities as $priority) {
|
||||||
$groupedUsers[$priority] = array_filter($filteredEnergyUsers, function ($user) use ($priority, $priorityKey) {
|
$groupedUsers[$priority] = array_filter(
|
||||||
return $user[$priorityKey] == $priority;
|
$filteredEnergyUsers,
|
||||||
});
|
function ($user) use ($priority, $priorityKey) {
|
||||||
|
return $user[$priorityKey] == $priority;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
IPS_LogMessage("Manager", print_r($groupedUsers, true));
|
|
||||||
|
|
||||||
// Jetzt kannst du die Benutzer gruppenweise verarbeiten
|
// Jetzt kannst du die Benutzer gruppenweise verarbeiten
|
||||||
foreach ($groupedUsers as $priority => $users) {
|
foreach ($groupedUsers as $priority => $users) {
|
||||||
// EnergyUser mit gleicher Priorität sammeln
|
// EnergyUser mit gleicher Priorität sammeln
|
||||||
$samePriorityUsers = isset($groupedUsers[$priority]) ? $groupedUsers[$priority] : [];
|
$samePriorityUsers = isset($groupedUsers[$priority])
|
||||||
IPS_LogMessage("Manager", print_r($samePriorityUsers, true));
|
? $groupedUsers[$priority]
|
||||||
|
: [];
|
||||||
|
|
||||||
// Wenn keine EnergyUser mit gleicher Priorität vorhanden sind, überspringen
|
// Wenn keine EnergyUser mit gleicher Priorität vorhanden sind, überspringen
|
||||||
if (empty($samePriorityUsers)) {
|
if (empty($samePriorityUsers)) {
|
||||||
@@ -163,50 +182,56 @@ class Manager extends IPSModule
|
|||||||
$withZero = [];
|
$withZero = [];
|
||||||
$withoutZero = [];
|
$withoutZero = [];
|
||||||
// Verbraucher die nicht 0 Annhemen können, bekommen einfach den tiefsten wert
|
// Verbraucher die nicht 0 Annhemen können, bekommen einfach den tiefsten wert
|
||||||
foreach ($samePriorityUsers as $entry) {
|
foreach ($samePriorityUsers as $entry) {
|
||||||
if (in_array(0, $entry['PowerSteps'])) {
|
if (in_array(0, $entry["PowerSteps"])) {
|
||||||
$withZero[] = $entry;
|
$withZero[] = $entry;
|
||||||
} else {
|
} else {
|
||||||
$withoutZero[] = $entry;
|
$withoutZero[] = $entry;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Methode für alle im withoutZero-Array aufrufen
|
// Methode für alle im withoutZero-Array aufrufen
|
||||||
if (!empty($withoutZero)) {
|
if (!empty($withoutZero)) {
|
||||||
foreach ($withoutZero as $entry) {
|
foreach ($withoutZero as $entry) {
|
||||||
$instanceID = $entry['InstanceID'];
|
$instanceID = $entry["InstanceID"];
|
||||||
$minPowerStep = min($entry['PowerSteps']);
|
$minPowerStep = min($entry["PowerSteps"]);
|
||||||
|
|
||||||
// Simulierte Methode (Debug-Ausgabe)
|
// Simulierte Methode (Debug-Ausgabe)
|
||||||
IPS_RequestAction($instanceID, 'SetCurrentPower', $minPowerStep);
|
IPS_RequestAction(
|
||||||
$remainingPower -= $entry['CurrentPower'];
|
$instanceID,
|
||||||
|
"SetCurrentPower",
|
||||||
// Hier kann der tatsächliche Funktionsaufruf eingebaut werden
|
$minPowerStep
|
||||||
// IPS_RequestAction($instanceID, 'SetCurrentPower', $minPowerStep);
|
);
|
||||||
}}
|
$remainingPower -= $entry["CurrentPower"];
|
||||||
|
}
|
||||||
|
}
|
||||||
$samePriorityUsers = $withZero;
|
$samePriorityUsers = $withZero;
|
||||||
// Array für die verteilte Energie pro User erstellen
|
// Array für die verteilte Energie pro User erstellen
|
||||||
$userEnergyProv = [];
|
$userEnergyProv = [];
|
||||||
$userEnergyProv = array_fill_keys(array_column($samePriorityUsers, 'InstanceID'), 0); // Initialisierung für jeden Benutzer auf 0 setzen
|
$userEnergyProv = array_fill_keys(
|
||||||
IPS_LogMessage("userEnergyProv", print_r($userEnergyProv, true));
|
array_column($samePriorityUsers, "InstanceID"),
|
||||||
|
0
|
||||||
|
); // Initialisierung für jeden Benutzer auf 0 setzen
|
||||||
|
|
||||||
// Alle Schritte der Benutzer in einem Array sammeln
|
// Alle Schritte der Benutzer in einem Array sammeln
|
||||||
$allSteps = [];
|
$allSteps = [];
|
||||||
foreach ($samePriorityUsers as $user) {
|
foreach ($samePriorityUsers as $user) {
|
||||||
foreach ($user['PowerSteps'] as $step) {
|
foreach ($user["PowerSteps"] as $step) {
|
||||||
$allSteps[] = ['user' => $user['InstanceID'], 'step' => $step];
|
$allSteps[] = [
|
||||||
|
"user" => $user["InstanceID"],
|
||||||
|
"step" => $step,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IPS_LogMessage("allSteps", print_r($allSteps, true));
|
|
||||||
|
|
||||||
// Sortiere die Schritte nach Größe
|
// Sortiere die Schritte nach Größe
|
||||||
usort($allSteps, function ($a, $b) {
|
usort($allSteps, function ($a, $b) {
|
||||||
return $a['step'] <=> $b['step'];
|
return $a["step"] <=> $b["step"];
|
||||||
});
|
});
|
||||||
|
|
||||||
// Iteriere durch alle Schritte
|
// Iteriere durch alle Schritte
|
||||||
foreach ($allSteps as $entry) {
|
foreach ($allSteps as $entry) {
|
||||||
$user = $entry['user'];
|
$user = $entry["user"];
|
||||||
$powerstep = $entry['step'];
|
$powerstep = $entry["step"];
|
||||||
|
|
||||||
// Überprüfe, ob noch genügend verbleibende Energie für den nächsten Schritt vorhanden ist
|
// Überprüfe, ob noch genügend verbleibende Energie für den nächsten Schritt vorhanden ist
|
||||||
if ($remainingPower >= $powerstep - $userEnergyProv[$user]) {
|
if ($remainingPower >= $powerstep - $userEnergyProv[$user]) {
|
||||||
@@ -215,7 +240,6 @@ class Manager extends IPSModule
|
|||||||
$userEnergyProv[$user] = $powerstep;
|
$userEnergyProv[$user] = $powerstep;
|
||||||
} //else {
|
} //else {
|
||||||
// Wenn nicht genug Energie vorhanden ist, setze die verbleibende Energie
|
// Wenn nicht genug Energie vorhanden ist, setze die verbleibende Energie
|
||||||
// Test dieses break rauszunehmen ... break;
|
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,10 +247,12 @@ class Manager extends IPSModule
|
|||||||
foreach ($userEnergyProv as $userInstanceID => $energy) {
|
foreach ($userEnergyProv as $userInstanceID => $energy) {
|
||||||
$weui = min(
|
$weui = min(
|
||||||
array_column(
|
array_column(
|
||||||
array_filter($allSteps, function ($entry) use ($userInstanceID) {
|
array_filter($allSteps, function ($entry) use (
|
||||||
return $entry['user'] == $userInstanceID;
|
$userInstanceID
|
||||||
|
) {
|
||||||
|
return $entry["user"] == $userInstanceID;
|
||||||
}),
|
}),
|
||||||
'step'
|
"step"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -234,15 +260,14 @@ class Manager extends IPSModule
|
|||||||
|
|
||||||
// Methode SetCurrentPower für jeden EnergyUser aufrufen
|
// Methode SetCurrentPower für jeden EnergyUser aufrufen
|
||||||
if (IPS_InstanceExists($userInstanceID)) {
|
if (IPS_InstanceExists($userInstanceID)) {
|
||||||
IPS_RequestAction($userInstanceID, 'SetCurrentPower', $energy); // Annahme: SetCurrentPower wird über eine Aktionsanfrage ausgeführt
|
IPS_RequestAction(
|
||||||
|
$userInstanceID,
|
||||||
|
"SetCurrentPower",
|
||||||
|
$energy
|
||||||
|
); // Annahme: SetCurrentPower wird über eine Aktionsanfrage ausgeführt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug-Ausgabe des Endzustands
|
|
||||||
foreach ($filteredEnergyUsers as $user) {
|
|
||||||
IPS_LogMessage("Manager", "Final state for instance {$user['InstanceID']}: CurrentPower = {$user['CurrentPower']}, UsedEnergy = {$user['UsedEnergy']}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"translations": {
|
|
||||||
"de": {
|
|
||||||
"Translation 1": "Übersetzung 1",
|
|
||||||
"Translation 2": "Übersetzung 2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
class Verbraucher_1_Stufig extends IPSModule {
|
class Verbraucher_1_Stufig extends IPSModule
|
||||||
|
{
|
||||||
private $timerID;
|
private $timerID;
|
||||||
|
|
||||||
public function Create() {
|
public function Create()
|
||||||
|
{
|
||||||
parent::Create();
|
parent::Create();
|
||||||
|
|
||||||
// Prioritäten
|
// Prioritäten
|
||||||
@@ -33,20 +34,26 @@ class Verbraucher_1_Stufig extends IPSModule {
|
|||||||
$this->RegisterPropertyInteger("Schaltkontakt1", 0);
|
$this->RegisterPropertyInteger("Schaltkontakt1", 0);
|
||||||
|
|
||||||
// Timer für Zeit_Zwischen_Zustandswechseln
|
// Timer für Zeit_Zwischen_Zustandswechseln
|
||||||
$this->RegisterTimer("ZustandswechselTimer", 0, 'IPS_RequestAction(' . $this->InstanceID . ', "ResetPowerSteps", "");');
|
$this->RegisterTimer(
|
||||||
|
"ZustandswechselTimer",
|
||||||
|
0,
|
||||||
|
"IPS_RequestAction(" .
|
||||||
|
$this->InstanceID .
|
||||||
|
', "ResetPowerSteps", "");'
|
||||||
|
);
|
||||||
|
|
||||||
//Initialisieren
|
//Initialisieren
|
||||||
$this->SetValue("Idle", true);
|
$this->SetValue("Idle", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges() {
|
public function ApplyChanges()
|
||||||
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aktionen verarbeiten
|
// Aktionen verarbeiten
|
||||||
public function RequestAction($Ident, $Value) {
|
public function RequestAction($Ident, $Value)
|
||||||
|
{
|
||||||
switch ($Ident) {
|
switch ($Ident) {
|
||||||
case "SetCurrentPower":
|
case "SetCurrentPower":
|
||||||
$this->SetCurrentPower($Value);
|
$this->SetCurrentPower($Value);
|
||||||
@@ -62,25 +69,31 @@ class Verbraucher_1_Stufig extends IPSModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Methode zum Setzen der PowerSteps und Timer starten
|
// Methode zum Setzen der PowerSteps und Timer starten
|
||||||
public function SetTimerOn() {
|
public function SetTimerOn()
|
||||||
|
{
|
||||||
// Timer setzen, der nach "Zeit_Zwischen_Zustandswechseln" abläuft
|
// Timer setzen, der nach "Zeit_Zwischen_Zustandswechseln" abläuft
|
||||||
$zeitZwischenZustandswechseln = $this->ReadPropertyInteger("Zeit_Zwischen_Zustandswechseln");
|
$zeitZwischenZustandswechseln = $this->ReadPropertyInteger(
|
||||||
$this->SetTimerInterval("ZustandswechselTimer", $zeitZwischenZustandswechseln * 60000); // Timer in Millisekunden
|
"Zeit_Zwischen_Zustandswechseln"
|
||||||
IPS_LogMessage("Verbraucher", "In Set Methode");
|
);
|
||||||
|
$this->SetTimerInterval(
|
||||||
// Timer-Status auf true setzen
|
"ZustandswechselTimer",
|
||||||
$this->SetValue("IsTimerActive", true);
|
$zeitZwischenZustandswechseln * 60000
|
||||||
|
); // Timer in Millisekunden
|
||||||
|
IPS_LogMessage("Verbraucher", "In Set Methode");
|
||||||
|
|
||||||
|
// Timer-Status auf true setzen
|
||||||
|
$this->SetValue("IsTimerActive", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methode zum Zurücksetzen von PowerSteps nach Ablauf des Timers
|
// Methode zum Zurücksetzen von PowerSteps nach Ablauf des Timers
|
||||||
public function ResetPowerSteps() {
|
public function ResetPowerSteps()
|
||||||
|
{
|
||||||
// PowerSteps wieder auf den ursprünglichen Zustand setzen (wie vorherige Funktionalität)
|
// PowerSteps wieder auf den ursprünglichen Zustand setzen (wie vorherige Funktionalität)
|
||||||
$this->SetValue("PowerSteps", json_encode([$this->GetValue("CurrentPower")]));
|
$this->SetValue(
|
||||||
IPS_LogMessage("Verbraucher", "In Reset Methode");
|
"PowerSteps",
|
||||||
|
json_encode([$this->GetValue("CurrentPower")])
|
||||||
|
);
|
||||||
|
|
||||||
// Timer stoppen
|
// Timer stoppen
|
||||||
$this->SetTimerInterval("ZustandswechselTimer", 0);
|
$this->SetTimerInterval("ZustandswechselTimer", 0);
|
||||||
@@ -89,9 +102,10 @@ class Verbraucher_1_Stufig extends IPSModule {
|
|||||||
$this->SetValue("IsTimerActive", false);
|
$this->SetValue("IsTimerActive", false);
|
||||||
}
|
}
|
||||||
// Methode zum Setzen des aktuellen Stromverbrauchs
|
// Methode zum Setzen des aktuellen Stromverbrauchs
|
||||||
public function SetCurrentPower(float $power) {
|
public function SetCurrentPower(float $power)
|
||||||
|
{
|
||||||
$this->CheckIdle($power);
|
$this->CheckIdle($power);
|
||||||
if($this->GetValue("CurrentPower")!=$power){
|
if ($this->GetValue("CurrentPower") != $power) {
|
||||||
$this->SetTimerOn();
|
$this->SetTimerOn();
|
||||||
}
|
}
|
||||||
$this->SetValue("CurrentPower", $power);
|
$this->SetValue("CurrentPower", $power);
|
||||||
@@ -110,55 +124,71 @@ class Verbraucher_1_Stufig extends IPSModule {
|
|||||||
$currentStatus = GetValue($this->ReadPropertyInteger("Schaltkontakt1"));
|
$currentStatus = GetValue($this->ReadPropertyInteger("Schaltkontakt1"));
|
||||||
|
|
||||||
// Schaltkontaktstatus ändern
|
// Schaltkontaktstatus ändern
|
||||||
SetValue($this->ReadPropertyInteger("Schaltkontakt1"), $schaltkontaktStatus);
|
SetValue(
|
||||||
|
$this->ReadPropertyInteger("Schaltkontakt1"),
|
||||||
|
$schaltkontaktStatus
|
||||||
|
);
|
||||||
|
|
||||||
if($schaltkontaktStatus){
|
if ($schaltkontaktStatus) {
|
||||||
$this->SetValue("DailyOnTime", $this->GetValue("DailyOnTime") + 1);
|
$this->SetValue("DailyOnTime", $this->GetValue("DailyOnTime") + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methode zum Abrufen der aktuellen Daten
|
// Methode zum Abrufen der aktuellen Daten
|
||||||
public function GetCurrentData(bool $Peak) {
|
public function GetCurrentData(bool $Peak)
|
||||||
|
{
|
||||||
$IstNacht = $this->GetValue("IstNacht");
|
$IstNacht = $this->GetValue("IstNacht");
|
||||||
$NeuesIstNacht = $this->ist_nachts();
|
$NeuesIstNacht = $this->ist_nachts();
|
||||||
|
|
||||||
if($IstNacht == true && $NeuesIstNacht == false){
|
if ($IstNacht == true && $NeuesIstNacht == false) {
|
||||||
$this->SetValue("DailyOnTime", 0);
|
$this->SetValue("DailyOnTime", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->SetValue("IstNacht", $NeuesIstNacht);
|
$this->SetValue("IstNacht", $NeuesIstNacht);
|
||||||
|
|
||||||
$DailyOnTime = $this->GetValue("DailyOnTime");
|
$DailyOnTime = $this->GetValue("DailyOnTime");
|
||||||
$Mindestlaufzeit = $this->ReadPropertyInteger("Mindesttlaufzeit") * 60 * 12;
|
$Mindestlaufzeit =
|
||||||
|
$this->ReadPropertyInteger("Mindesttlaufzeit") * 60 * 12;
|
||||||
|
|
||||||
// Überprüfen, ob der Timer aktiv ist
|
// Überprüfen, ob der Timer aktiv ist
|
||||||
if($this->GetValue("IsTimerActive")) {
|
if ($this->GetValue("IsTimerActive")) {
|
||||||
// Timer ist aktiv, PowerSteps setzen
|
// Timer ist aktiv, PowerSteps setzen
|
||||||
$this->SetValue("PowerSteps", json_encode([$this->GetValue("CurrentPower")]));
|
$this->SetValue(
|
||||||
|
"PowerSteps",
|
||||||
|
json_encode([$this->GetValue("CurrentPower")])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// Wenn Nacht und Mindestlaufzeit nicht erreicht ist
|
// Wenn Nacht und Mindestlaufzeit nicht erreicht ist
|
||||||
else if($NeuesIstNacht && ($DailyOnTime < $Mindestlaufzeit)) {
|
elseif ($NeuesIstNacht && $DailyOnTime < $Mindestlaufzeit) {
|
||||||
if($Peak) {
|
if ($Peak) {
|
||||||
$this->SetValue("PowerSteps", json_encode([0, $this->ReadPropertyInteger("BoilerLeistung")]));
|
$this->SetValue(
|
||||||
|
"PowerSteps",
|
||||||
|
json_encode([
|
||||||
|
0,
|
||||||
|
$this->ReadPropertyInteger("BoilerLeistung"),
|
||||||
|
])
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->SetValue("PowerSteps", json_encode([$this->ReadPropertyInteger("BoilerLeistung")]));
|
$this->SetValue("PowerSteps",json_encode([$this->ReadPropertyInteger("BoilerLeistung")]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Andernfalls
|
// Andernfalls
|
||||||
else {
|
else {
|
||||||
if($Peak) {
|
if ($Peak) {
|
||||||
$this->SetValue("PowerSteps", json_encode([0]));
|
$this->SetValue("PowerSteps", json_encode([0]));
|
||||||
} else {
|
} else {
|
||||||
$this->SetValue("PowerSteps", json_encode([0, $this->ReadPropertyInteger("BoilerLeistung")]));
|
$this->SetValue("PowerSteps",json_encode([0,$this->ReadPropertyInteger("BoilerLeistung"),])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function CheckIdle($power){
|
public function CheckIdle($power)
|
||||||
|
{
|
||||||
$lastpower = GetValue($this->GetIDForIdent("CurrentPower"));
|
$lastpower = GetValue($this->GetIDForIdent("CurrentPower"));
|
||||||
if($lastpower != $power){
|
if ($lastpower != $power) {
|
||||||
$this->SetValue("Idle", false);
|
$this->SetValue("Idle", false);
|
||||||
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
|
$this->SetValue("IdleCounter",$this->ReadPropertyInteger("IdleCounterMax"));
|
||||||
}
|
}
|
||||||
// IdleCounter auslesen und verarbeiten
|
// IdleCounter auslesen und verarbeiten
|
||||||
$idleCounter = $this->GetValue("IdleCounter");
|
$idleCounter = $this->GetValue("IdleCounter");
|
||||||
@@ -170,12 +200,13 @@ class Verbraucher_1_Stufig extends IPSModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function ist_nachts() {
|
private function ist_nachts()
|
||||||
date_default_timezone_set('Europe/Berlin'); // Setze hier deine Zeitzone
|
{
|
||||||
|
date_default_timezone_set("Europe/Berlin"); // Setze hier deine Zeitzone
|
||||||
|
|
||||||
$aktuelle_zeit = strtotime(date('H:i')); // Aktuelle Zeit in Stunden und Minuten umwandeln
|
$aktuelle_zeit = strtotime(date("H:i")); // Aktuelle Zeit in Stunden und Minuten umwandeln
|
||||||
$start_nacht = strtotime('22:00'); // Startzeit der Nacht (22 Uhr)
|
$start_nacht = strtotime("22:00"); // Startzeit der Nacht (22 Uhr)
|
||||||
$ende_nacht = strtotime('07:00'); // Endzeit der Nacht (7 Uhr)
|
$ende_nacht = strtotime("07:00"); // Endzeit der Nacht (7 Uhr)
|
||||||
|
|
||||||
if ($aktuelle_zeit >= $start_nacht || $aktuelle_zeit < $ende_nacht) {
|
if ($aktuelle_zeit >= $start_nacht || $aktuelle_zeit < $ende_nacht) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
class WP_Steuerung extends IPSModule {
|
class WP_Steuerung extends IPSModule
|
||||||
|
{
|
||||||
|
public function Create()
|
||||||
public function Create() {
|
{
|
||||||
parent::Create();
|
parent::Create();
|
||||||
|
|
||||||
// Prioritäten
|
// Prioritäten
|
||||||
@@ -29,9 +29,6 @@ class WP_Steuerung extends IPSModule {
|
|||||||
$this->RegisterVariableBoolean("LetzterPeakwert", "LetzterPeakwert", "", false);
|
$this->RegisterVariableBoolean("LetzterPeakwert", "LetzterPeakwert", "", false);
|
||||||
$this->RegisterVariableBoolean("LetzterPeakwert_Aenderung", "LetzterPeakwert_Aenderung", "", false);
|
$this->RegisterVariableBoolean("LetzterPeakwert_Aenderung", "LetzterPeakwert_Aenderung", "", false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->RegisterPropertyInteger("WP_Leistung", 6000);
|
$this->RegisterPropertyInteger("WP_Leistung", 6000);
|
||||||
$this->RegisterPropertyInteger("Wolkenschwellwert", 60);
|
$this->RegisterPropertyInteger("Wolkenschwellwert", 60);
|
||||||
$this->RegisterPropertyInteger("Wolkenwert", 0);
|
$this->RegisterPropertyInteger("Wolkenwert", 0);
|
||||||
@@ -47,12 +44,14 @@ class WP_Steuerung extends IPSModule {
|
|||||||
$this->SetValue("Idle", true);
|
$this->SetValue("Idle", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ApplyChanges() {
|
public function ApplyChanges()
|
||||||
|
{
|
||||||
parent::ApplyChanges();
|
parent::ApplyChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aktionen verarbeiten
|
// Aktionen verarbeiten
|
||||||
public function RequestAction($Ident, $Value) {
|
public function RequestAction($Ident, $Value)
|
||||||
|
{
|
||||||
switch ($Ident) {
|
switch ($Ident) {
|
||||||
case "SetCurrentPower":
|
case "SetCurrentPower":
|
||||||
$this->SetCurrentPower($Value);
|
$this->SetCurrentPower($Value);
|
||||||
@@ -68,219 +67,214 @@ class WP_Steuerung extends IPSModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Methode zum Setzen des aktuellen Stromverbrauchs
|
// Methode zum Setzen des aktuellen Stromverbrauchs
|
||||||
public function SetCurrentPower(float $power) {
|
public function SetCurrentPower(float $power)
|
||||||
|
{
|
||||||
$sperrzei_abs = 60*60*(GetValue($this->ReadPropertyInteger("Aussentemperatur"))+10)/25*6;
|
$sperrzei_abs =
|
||||||
|
((60 *
|
||||||
if($sperrzei_abs>6*60*60){
|
60 *
|
||||||
$sperrzei_abs = 6*60*60;
|
(GetValue($this->ReadPropertyInteger("Aussentemperatur")) +
|
||||||
|
10)) /
|
||||||
|
25) *
|
||||||
|
6;
|
||||||
|
|
||||||
|
if ($sperrzei_abs > 6 * 60 * 60) {
|
||||||
|
$sperrzei_abs = 6 * 60 * 60;
|
||||||
}
|
}
|
||||||
if($this->ReadPropertyInteger("Wolkenschwellwert")<GetValue($this->ReadPropertyInteger("Wolkenwert")) || $sperrzei_abs < 0 ){
|
if (
|
||||||
|
$this->ReadPropertyInteger("Wolkenschwellwert") <
|
||||||
|
GetValue($this->ReadPropertyInteger("Wolkenwert")) ||
|
||||||
|
$sperrzei_abs < 0
|
||||||
|
) {
|
||||||
$sperrzei_abs = 0;
|
$sperrzei_abs = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
$sperrzeit = GetValue($this->ReadPropertyInteger("Referenzzeit"))%86400 - $sperrzei_abs;
|
$sperrzeit = (GetValue($this->ReadPropertyInteger("Referenzzeit")) % 86400) - $sperrzei_abs;
|
||||||
$entsperrzeit = GetValue($this->ReadPropertyInteger("Referenzzeit"))%86400;
|
$entsperrzeit = GetValue($this->ReadPropertyInteger("Referenzzeit")) % 86400;
|
||||||
$aktuellezeit = time()%86400;
|
$aktuellezeit = time() % 86400;
|
||||||
|
|
||||||
$this->CheckIdle($power);
|
$this->CheckIdle($power);
|
||||||
|
|
||||||
$its_lock_time = $this->GetValue("Sperrzeit");
|
$its_lock_time = $this->GetValue("Sperrzeit");
|
||||||
if($aktuellezeit > $sperrzeit && $aktuellezeit < $entsperrzeit && $this->GetValue("WP_Laufzeit_Zahler")>240){
|
if (
|
||||||
|
$aktuellezeit > $sperrzeit &&
|
||||||
|
$aktuellezeit < $entsperrzeit &&
|
||||||
|
$this->GetValue("WP_Laufzeit_Zahler") > 240
|
||||||
|
) {
|
||||||
$this->SetValue("Sperrzeit", true);
|
$this->SetValue("Sperrzeit", true);
|
||||||
|
} elseif ($this->GetValue("WP_Laufzeit_Zahler") > 240) {
|
||||||
}
|
|
||||||
elseif($this->GetValue("WP_Laufzeit_Zahler")>240){
|
|
||||||
$this->SetValue("Sperrzeit", false);
|
$this->SetValue("Sperrzeit", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$newlocktime = $this->GetValue("Sperrzeit");
|
$newlocktime = $this->GetValue("Sperrzeit");
|
||||||
|
|
||||||
|
if (
|
||||||
if($newlocktime == true && $its_lock_time==false && $this->GetValue("WP_Laufzeit_Zahler")>240){
|
$newlocktime == true &&
|
||||||
|
$its_lock_time == false &&
|
||||||
|
$this->GetValue("WP_Laufzeit_Zahler") > 240
|
||||||
|
) {
|
||||||
$this->SetValue("WP_Laufzeit_Zahler", 0);
|
$this->SetValue("WP_Laufzeit_Zahler", 0);
|
||||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), true);
|
SetValue($this->ReadPropertyInteger("Sperrkontakt"), true);
|
||||||
|
} elseif (
|
||||||
}
|
$newlocktime == false &&
|
||||||
|
$its_lock_time == true &&
|
||||||
elseif($newlocktime == false && $its_lock_time == true && $this->GetValue("WP_Laufzeit_Zahler")>240){
|
$this->GetValue("WP_Laufzeit_Zahler") > 240
|
||||||
|
) {
|
||||||
$this->SetValue("WP_Laufzeit_Zahler", 0);
|
$this->SetValue("WP_Laufzeit_Zahler", 0);
|
||||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||||
|
} elseif (
|
||||||
}
|
$this->GetValue("CurrentPower") != $power ||
|
||||||
|
($this->GetValue("WP_Laufzeit_Zahler") > 240 &&
|
||||||
|
$this->GetValue("LetzterPeakwert") !=
|
||||||
elseif($this->GetValue("CurrentPower")!=$power || ($this->GetValue("WP_Laufzeit_Zahler")>240 && ($this->GetValue("LetzterPeakwert") != $this->GetValue("LetzterPeakwert_Aenderung"))) ){
|
$this->GetValue("LetzterPeakwert_Aenderung"))
|
||||||
|
) {
|
||||||
$this->SetValue("WP_Laufzeit_Zahler", 0);
|
$this->SetValue("WP_Laufzeit_Zahler", 0);
|
||||||
|
|
||||||
$LastPeak = $this->GetValue("LetzterPeakwert");
|
$LastPeak = $this->GetValue("LetzterPeakwert");
|
||||||
$this->SetValue("LetzterPeakwert_Aenderung", $LastPeak);
|
$this->SetValue("LetzterPeakwert_Aenderung", $LastPeak);
|
||||||
$state = $this->GetValue("Zustand_WP");
|
$state = $this->GetValue("Zustand_WP");
|
||||||
|
|
||||||
if($state == 0){
|
if ($state == 0) {
|
||||||
|
|
||||||
$this->SetValue("Zustand_WP", 1);
|
$this->SetValue("Zustand_WP", 1);
|
||||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||||
|
} elseif ($state == 1) {
|
||||||
}elseif($state == 1) // Normalbetrieb
|
// Normalbetrieb
|
||||||
{
|
if (
|
||||||
if($LastPeak && $power == ($this->ReadPropertyInteger("WP_Leistung"))) {
|
$LastPeak &&
|
||||||
$this->SetValue("Zustand_WP", 1);
|
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||||
$this->SetValue("CurrentPower", $this->ReadPropertyInteger("WP_Leistung"));
|
) {
|
||||||
|
|
||||||
|
|
||||||
} elseif($LastPeak && $power == 0){
|
|
||||||
$this->SetValue("Zustand_WP", 2);
|
|
||||||
$this->SetValue("CurrentPower", 0);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
elseif($LastPeak == false && $power == ($this->ReadPropertyInteger("WP_Leistung"))){
|
|
||||||
$this->SetValue("Zustand_WP", 3);
|
|
||||||
$this->SetValue("CurrentPower", $this->ReadPropertyInteger("WP_Leistung"));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
elseif($LastPeak == false && $power == 0){
|
|
||||||
$this->SetValue("Zustand_WP", 1);
|
|
||||||
$this->SetValue("CurrentPower", 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}elseif($state == 2) // Sperre
|
|
||||||
{
|
|
||||||
if($LastPeak && $power == ($this->ReadPropertyInteger("WP_Leistung"))) {
|
|
||||||
$this->SetValue("Zustand_WP", 1);
|
|
||||||
$this->SetValue("CurrentPower", $this->ReadPropertyInteger("WP_Leistung"));
|
|
||||||
|
|
||||||
|
|
||||||
} elseif($LastPeak && $power == 0){
|
|
||||||
$this->SetValue("Zustand_WP", 2);
|
|
||||||
$this->SetValue("CurrentPower", 0);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
elseif($LastPeak == false && $power == ($this->ReadPropertyInteger("WP_Leistung"))){
|
|
||||||
$this->SetValue("Zustand_WP", 3);
|
|
||||||
$this->SetValue("CurrentPower", $this->ReadPropertyInteger("WP_Leistung"));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
elseif($LastPeak == false && $power == 0){
|
|
||||||
$this->SetValue("Zustand_WP", 1);
|
|
||||||
$this->SetValue("CurrentPower", 0);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}elseif($state == 3) // Erhöht
|
|
||||||
{
|
|
||||||
|
|
||||||
if($LastPeak && $power == ($this->ReadPropertyInteger("WP_Leistung"))) {
|
|
||||||
$this->SetValue("Zustand_WP", 1);
|
$this->SetValue("Zustand_WP", 1);
|
||||||
$this->SetValue("CurrentPower", $this->ReadPropertyInteger("WP_Leistung"));
|
$this->SetValue(
|
||||||
|
"CurrentPower",
|
||||||
} elseif($LastPeak && $power == 0){
|
$this->ReadPropertyInteger("WP_Leistung")
|
||||||
|
);
|
||||||
|
} elseif ($LastPeak && $power == 0) {
|
||||||
$this->SetValue("Zustand_WP", 2);
|
$this->SetValue("Zustand_WP", 2);
|
||||||
$this->SetValue("CurrentPower", 0);
|
$this->SetValue("CurrentPower", 0);
|
||||||
|
} elseif (
|
||||||
|
$LastPeak == false &&
|
||||||
}
|
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||||
elseif($LastPeak == false && $power == ($this->ReadPropertyInteger("WP_Leistung"))){
|
) {
|
||||||
$this->SetValue("Zustand_WP", 3);
|
$this->SetValue("Zustand_WP", 3);
|
||||||
$this->SetValue("CurrentPower", $this->ReadPropertyInteger("WP_Leistung"));
|
$this->SetValue(
|
||||||
|
"CurrentPower",
|
||||||
|
$this->ReadPropertyInteger("WP_Leistung")
|
||||||
}
|
);
|
||||||
elseif($LastPeak == false && $power == 0){
|
} elseif ($LastPeak == false && $power == 0) {
|
||||||
$this->SetValue("Zustand_WP", 1);
|
$this->SetValue("Zustand_WP", 1);
|
||||||
$this->SetValue("CurrentPower", 0);
|
$this->SetValue("CurrentPower", 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} elseif ($state == 2) {
|
||||||
|
// Sperre
|
||||||
|
if (
|
||||||
|
$LastPeak &&
|
||||||
|
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||||
|
) {
|
||||||
|
$this->SetValue("Zustand_WP", 1);
|
||||||
|
$this->SetValue(
|
||||||
|
"CurrentPower",
|
||||||
|
$this->ReadPropertyInteger("WP_Leistung")
|
||||||
|
);
|
||||||
|
} elseif ($LastPeak && $power == 0) {
|
||||||
|
$this->SetValue("Zustand_WP", 2);
|
||||||
|
$this->SetValue("CurrentPower", 0);
|
||||||
|
} elseif (
|
||||||
|
$LastPeak == false &&
|
||||||
|
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||||
|
) {
|
||||||
|
$this->SetValue("Zustand_WP", 3);
|
||||||
|
$this->SetValue(
|
||||||
|
"CurrentPower",
|
||||||
|
$this->ReadPropertyInteger("WP_Leistung")
|
||||||
|
);
|
||||||
|
} elseif ($LastPeak == false && $power == 0) {
|
||||||
|
$this->SetValue("Zustand_WP", 1);
|
||||||
|
$this->SetValue("CurrentPower", 0);
|
||||||
}
|
}
|
||||||
else{
|
} elseif ($state == 3) {
|
||||||
|
// Erhöht
|
||||||
|
if (
|
||||||
|
$LastPeak &&
|
||||||
|
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||||
|
) {
|
||||||
|
$this->SetValue("Zustand_WP", 1);
|
||||||
|
$this->SetValue(
|
||||||
|
"CurrentPower",
|
||||||
|
$this->ReadPropertyInteger("WP_Leistung")
|
||||||
|
);
|
||||||
|
} elseif ($LastPeak && $power == 0) {
|
||||||
|
$this->SetValue("Zustand_WP", 2);
|
||||||
|
$this->SetValue("CurrentPower", 0);
|
||||||
|
} elseif (
|
||||||
|
$LastPeak == false &&
|
||||||
|
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||||
|
) {
|
||||||
|
$this->SetValue("Zustand_WP", 3);
|
||||||
|
$this->SetValue(
|
||||||
|
"CurrentPower",
|
||||||
|
$this->ReadPropertyInteger("WP_Leistung")
|
||||||
|
);
|
||||||
|
} elseif ($LastPeak == false && $power == 0) {
|
||||||
|
$this->SetValue("Zustand_WP", 1);
|
||||||
|
$this->SetValue("CurrentPower", 0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
$this->SetValue("Zustand_WP", 1);
|
$this->SetValue("Zustand_WP", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$newState = $this->GetValue("Zustand_WP");
|
$newState = $this->GetValue("Zustand_WP");
|
||||||
|
|
||||||
if($newState == 0){
|
if ($newState == 0) {
|
||||||
|
|
||||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||||
|
} elseif ($newState == 1) {
|
||||||
}elseif($newState == 1){
|
|
||||||
|
|
||||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||||
|
} elseif ($newState == 2) {
|
||||||
}elseif($newState == 2){
|
|
||||||
|
|
||||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), true);
|
SetValue($this->ReadPropertyInteger("Sperrkontakt"), true);
|
||||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||||
|
} elseif ($newState == 3) {
|
||||||
}elseif($newState == 3){
|
|
||||||
|
|
||||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), true);
|
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), true);
|
||||||
|
} else {
|
||||||
}else{
|
|
||||||
|
|
||||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
}else{
|
|
||||||
|
|
||||||
$newCount = $this->GetValue("WP_Laufzeit_Zahler");
|
$newCount = $this->GetValue("WP_Laufzeit_Zahler");
|
||||||
$this->SetValue("WP_Laufzeit_Zahler", ($newCount +1));
|
$this->SetValue("WP_Laufzeit_Zahler", $newCount + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Methode zum Abrufen der aktuellen Daten
|
// Methode zum Abrufen der aktuellen Daten
|
||||||
public function GetCurrentData(bool $Peak) {
|
public function GetCurrentData(bool $Peak)
|
||||||
|
{
|
||||||
// tagessperrzeit berechnen
|
// tagessperrzeit berechnen
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->SetValue("LetzterPeakwert", $Peak);
|
$this->SetValue("LetzterPeakwert", $Peak);
|
||||||
|
|
||||||
|
|
||||||
if($this->GetValue("WP_Laufzeit_Zahler")<(20*12)){
|
if($this->GetValue("WP_Laufzeit_Zahler")<(20*12)){
|
||||||
|
|
||||||
$this->SetValue("PowerSteps", json_encode([$this->GetValue("CurrentPower")]));
|
$this->SetValue("PowerSteps", json_encode([$this->GetValue("CurrentPower")]));
|
||||||
|
|
||||||
}elseif($this->ReadPropertyBoolean("Schwellwert_Anwenden")==true && ($this->ReadPropertyInteger("Schwellwert")>GetValue($this->ReadPropertyInteger("WW_Temp"))) ){
|
}elseif($this->ReadPropertyBoolean("Schwellwert_Anwenden")==true && ($this->ReadPropertyInteger("Schwellwert")>GetValue($this->ReadPropertyInteger("WW_Temp"))) ){
|
||||||
|
|
||||||
|
|
||||||
$this->SetValue("PowerSteps", json_encode([$this->ReadPropertyInteger("WP_Leistung")]));
|
$this->SetValue("PowerSteps", json_encode([$this->ReadPropertyInteger("WP_Leistung")]));
|
||||||
}
|
}
|
||||||
|
|
||||||
else{
|
else{
|
||||||
|
|
||||||
$this->SetValue("PowerSteps", json_encode([0, $this->ReadPropertyInteger("WP_Leistung")]));
|
$this->SetValue("PowerSteps", json_encode([0, $this->ReadPropertyInteger("WP_Leistung")]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function CheckIdle($power){
|
public function CheckIdle($power)
|
||||||
|
{
|
||||||
$lastpower = GetValue($this->GetIDForIdent("CurrentPower"));
|
$lastpower = GetValue($this->GetIDForIdent("CurrentPower"));
|
||||||
if($lastpower != $power){
|
if ($lastpower != $power) {
|
||||||
$this->SetValue("Idle", false);
|
$this->SetValue("Idle", false);
|
||||||
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
|
$this->SetValue(
|
||||||
|
"IdleCounter",
|
||||||
|
$this->ReadPropertyInteger("IdleCounterMax")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// IdleCounter auslesen und verarbeiten
|
// IdleCounter auslesen und verarbeiten
|
||||||
$idleCounter = $this->GetValue("IdleCounter");
|
$idleCounter = $this->GetValue("IdleCounter");
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"compatibility": {
|
"compatibility": {
|
||||||
"version": "7.1"
|
"version": "7.1"
|
||||||
},
|
},
|
||||||
"version": "0.155",
|
"version": "0.156",
|
||||||
"build": 0,
|
"build": 0,
|
||||||
"date": 0
|
"date": 0
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user