Refactoring
This commit is contained in:
@@ -9,8 +9,14 @@
|
||||
"name":"InfluxJaNein",
|
||||
"caption":"Influx Aufzeichnen Ja oder Nein",
|
||||
"options":[
|
||||
{ "caption": "Ja", "value": true },
|
||||
{ "caption": "Nein", "value": false }
|
||||
{
|
||||
"caption":"Ja",
|
||||
"value":true
|
||||
},
|
||||
{
|
||||
"caption":"Nein",
|
||||
"value":false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -38,7 +44,6 @@
|
||||
"delete":true,
|
||||
"columns":[
|
||||
{
|
||||
|
||||
"caption":"Influx Name",
|
||||
"name":"Variablenname",
|
||||
"width":"200px",
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"translations": {
|
||||
"de": {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,16 @@
|
||||
|
||||
class Belevo_Server_Kommunikation extends IPSModule
|
||||
{
|
||||
|
||||
public function Create()
|
||||
{
|
||||
// Die Standard-Create() Methode aufrufen
|
||||
parent::Create();
|
||||
|
||||
// Registrierung der Eigenschaften
|
||||
$this->RegisterPropertyString("BaseURL", "https://brain.belevo.ch/storedata");
|
||||
$this->RegisterPropertyString(
|
||||
"BaseURL",
|
||||
"https://brain.belevo.ch/storedata"
|
||||
);
|
||||
$this->RegisterPropertyString("Anlagenummer", "0");
|
||||
$this->RegisterPropertyBoolean("InfluxJaNein", false);
|
||||
|
||||
@@ -20,12 +22,18 @@ class Belevo_Server_Kommunikation extends IPSModule
|
||||
$this->RegisterPropertyString("Gerätenummer", "0");
|
||||
$this->RegisterPropertyString("Ortschaft", "0");
|
||||
|
||||
$this->RegisterVariableInteger("Wolkenwarscheinlichkeit", "Wolkenwarscheinlichkeit");
|
||||
$this->RegisterVariableInteger(
|
||||
"Wolkenwarscheinlichkeit",
|
||||
"Wolkenwarscheinlichkeit"
|
||||
);
|
||||
$this->RegisterVariableInteger("Temperatur", "Temperatur");
|
||||
|
||||
|
||||
// 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()
|
||||
@@ -39,9 +47,6 @@ class Belevo_Server_Kommunikation extends IPSModule
|
||||
// Timer auf 5 Minuten setzen
|
||||
$this->SetTimerInterval("Timer_Influx", 300000); // Alle 5 Minuten -> 5*60*1000=300000
|
||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Influx Ja");
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
// Timer stoppen
|
||||
$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 = "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
|
||||
$headers = [
|
||||
"id: $pw"
|
||||
];
|
||||
$headers = ["id: $pw"];
|
||||
|
||||
// cURL-Initialisierung
|
||||
$ch = curl_init();
|
||||
@@ -72,10 +80,15 @@ class Belevo_Server_Kommunikation extends IPSModule
|
||||
$data = json_decode($response, true);
|
||||
|
||||
// Ü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 [
|
||||
'temp' => $data['forecast']['forecastday'][0]['hour'][5]['temp_c'],
|
||||
'cloud' => $data['forecast']['forecastday'][0]['hour'][8]['cloud']
|
||||
"temp" =>
|
||||
$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()
|
||||
{
|
||||
// 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
|
||||
$output = array();
|
||||
$output = [];
|
||||
|
||||
// Verarbeitung der Variablen
|
||||
if (!empty($zusatzVariablen)) {
|
||||
foreach ($zusatzVariablen as $variable) {
|
||||
// Überprüfen, ob der Variablenname gesetzt ist
|
||||
if (isset($variable['Variablenname'])) {
|
||||
$variablenname = $variable['Variablenname'];
|
||||
if (isset($variable["Variablenname"])) {
|
||||
$variablenname = $variable["Variablenname"];
|
||||
} 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
|
||||
}
|
||||
|
||||
$variableID = $variable['Variable'];
|
||||
$variableID = $variable["Variable"];
|
||||
|
||||
// Überprüfen, ob die Variable existiert
|
||||
if (IPS_VariableExists($variableID)) {
|
||||
$wert = GetValue($variableID); // Den aktuellen Wert der Zusatzvariable abrufen
|
||||
|
||||
|
||||
// Wert dem Variablenname zuweisen
|
||||
$output[$variablenname] = $wert;
|
||||
} 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
|
||||
return json_encode($output);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function RequestAction($Ident, $Value)
|
||||
{
|
||||
switch ($Ident) {
|
||||
@@ -136,7 +154,8 @@ class Belevo_Server_Kommunikation extends IPSModule
|
||||
}
|
||||
}
|
||||
|
||||
public function GetAction() {
|
||||
public function GetAction()
|
||||
{
|
||||
$output = $this->ProcessZusatzVariablen();
|
||||
$json = $this->MakeJson($output);
|
||||
// Verarbeite die Zusatzvariablen
|
||||
@@ -145,20 +164,30 @@ class Belevo_Server_Kommunikation extends IPSModule
|
||||
|
||||
$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("Wolkenwarscheinlichkeit", $answer['cloud']);
|
||||
if (isset($answer['temp'])) {
|
||||
$this->SetValue("Temperatur", $answer['temp']);
|
||||
if (isset($answer["temp"])) {
|
||||
$this->SetValue("Temperatur", $answer["temp"]);
|
||||
} 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'])) {
|
||||
$this->SetValue("Wolkenwarscheinlichkeit", $answer['cloud']);
|
||||
if (isset($answer["cloud"])) {
|
||||
$this->SetValue("Wolkenwarscheinlichkeit", $answer["cloud"]);
|
||||
} else {
|
||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Wolkenwarscheinlichkeit-Wert ist nicht vorhanden.");
|
||||
IPS_LogMessage(
|
||||
"Belevo_Server_Kommunikation",
|
||||
"Wolkenwarscheinlichkeit-Wert ist nicht vorhanden."
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($json)) {
|
||||
@@ -166,49 +195,47 @@ class Belevo_Server_Kommunikation extends IPSModule
|
||||
$fullURL = $baseURL;
|
||||
$this->SendJsonToInfluxDB($fullURL, $json);
|
||||
} 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)
|
||||
{
|
||||
$an_nummer = $this->ReadPropertyString("Anlagenummer"); // Anlagenummer lesen
|
||||
$InfluxJaNein = $this->ReadPropertyBoolean("InfluxJaNein");
|
||||
|
||||
// Werte in ein Array packen
|
||||
$influxData = array(
|
||||
"Value" => array(
|
||||
"InfluxAllowed" => $InfluxJaNein // Setze InfluxAllowed
|
||||
),
|
||||
"Parameter" => array(
|
||||
"Influxadr" => $an_nummer
|
||||
),
|
||||
"Tracker" => $json // Initialisiere Tracker als leeres Array
|
||||
);
|
||||
|
||||
|
||||
$influxData = [
|
||||
"Value" => [
|
||||
"InfluxAllowed" => $InfluxJaNein, // Setze InfluxAllowed
|
||||
],
|
||||
"Parameter" => [
|
||||
"Influxadr" => $an_nummer,
|
||||
],
|
||||
"Tracker" => $json, // Initialisiere Tracker als leeres Array
|
||||
];
|
||||
|
||||
// Array in JSON konvertieren
|
||||
$json = json_encode($influxData);
|
||||
|
||||
|
||||
// JSON zurückgeben oder weiterverarbeiten
|
||||
return $json;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function SendJsonToInfluxDB($url, $jsonData) {
|
||||
private function SendJsonToInfluxDB($url, $jsonData)
|
||||
{
|
||||
$pw = $this->ReadPropertyString("Gerätenummer");
|
||||
if (empty($pw)) {
|
||||
IPS_LogMessage("Belevo_Server_Kommunikation", "Fehler: Gerätenummer ist leer.");
|
||||
IPS_LogMessage(
|
||||
"Belevo_Server_Kommunikation",
|
||||
"Fehler: Gerätenummer ist leer."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// cURL Initialisieren
|
||||
$curl = curl_init();
|
||||
// Optionen für cURL-Request definieren
|
||||
@@ -217,29 +244,28 @@ private function SendJsonToInfluxDB($url, $jsonData) {
|
||||
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
|
||||
"Content-Type: application/json", // Header für JSON-Daten setzen
|
||||
"Accept: application/json",
|
||||
"id:" . $pw,
|
||||
],
|
||||
CURLOPT_POSTFIELDS => $jsonData // JSON-Daten als POST-Feld senden
|
||||
CURLOPT_POSTFIELDS => $jsonData, // JSON-Daten als POST-Feld senden
|
||||
]);
|
||||
|
||||
// cURL-Request ausführen
|
||||
$result = curl_exec($curl);
|
||||
|
||||
|
||||
$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);
|
||||
IPS_LogMessage(
|
||||
"Belevo_Server_Kommunikation",
|
||||
"Fehler beim Senden an Influx: " . $error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"translations": {
|
||||
"de": {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
||||
|
||||
public function Create() {
|
||||
class Boiler_2_Stufig_Mit_Fueler extends IPSModule
|
||||
{
|
||||
public function Create()
|
||||
{
|
||||
parent::Create();
|
||||
|
||||
// Prioritäten
|
||||
@@ -39,12 +40,14 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
||||
$this->SetValue("Idle", true);
|
||||
}
|
||||
|
||||
public function ApplyChanges() {
|
||||
public function ApplyChanges()
|
||||
{
|
||||
parent::ApplyChanges();
|
||||
}
|
||||
|
||||
// Aktionen verarbeiten
|
||||
public function RequestAction($Ident, $Value) {
|
||||
public function RequestAction($Ident, $Value)
|
||||
{
|
||||
switch ($Ident) {
|
||||
case "SetCurrentPower":
|
||||
$this->SetCurrentPower($Value);
|
||||
@@ -57,12 +60,15 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
||||
}
|
||||
|
||||
// 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
|
||||
if ($power == $this->ReadPropertyInteger("BoilerLeistungVolllast")) {
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Volllast"), true);
|
||||
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_Teillast"), true);
|
||||
} else {
|
||||
@@ -74,7 +80,10 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
||||
$lastPower = GetValue($this->GetIDForIdent("CurrentPower"));
|
||||
if ($power != $lastPower) {
|
||||
$this->SetValue("Idle", false);
|
||||
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
|
||||
$this->SetValue(
|
||||
"IdleCounter",
|
||||
$this->ReadPropertyInteger("IdleCounterMax")
|
||||
);
|
||||
}
|
||||
|
||||
// Setze die neue CurrentPower
|
||||
@@ -84,10 +93,9 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
||||
$this->ProcessIdleCounter();
|
||||
}
|
||||
|
||||
|
||||
// Methode zum Abrufen der aktuellen Daten
|
||||
public function GetCurrentData(bool $Peak) {
|
||||
|
||||
public function GetCurrentData(bool $Peak)
|
||||
{
|
||||
$LegioCounter = $this->GetValue("LegioCounter");
|
||||
|
||||
$boilerTemp = GetValue($this->ReadPropertyInteger("Boilertemperatur"));
|
||||
@@ -97,69 +105,73 @@ class Boiler_2_Stufig_Mit_Fueler extends IPSModule {
|
||||
$teilLeistung = $this->ReadPropertyInteger("BoilerLeistungTeillast");
|
||||
$vollLeistung = $this->ReadPropertyInteger("BoilerLeistungVolllast");
|
||||
|
||||
$AktuelleVollast = GetValue($this->ReadPropertyInteger("Kontakt_Volllast"));
|
||||
$AktuelleTeillast = GetValue($this->ReadPropertyInteger("Kontakt_Teillast"));
|
||||
$AktuelleVollast = GetValue(
|
||||
$this->ReadPropertyInteger("Kontakt_Volllast")
|
||||
);
|
||||
$AktuelleTeillast = GetValue(
|
||||
$this->ReadPropertyInteger("Kontakt_Teillast")
|
||||
);
|
||||
|
||||
if ($boilerTemp > $LegioTemp) {
|
||||
$LegioCounter = 0;
|
||||
IPS_LogMessage("im1", $LegioCounter);
|
||||
|
||||
} else {
|
||||
$LegioCounter = $LegioCounter + 1;
|
||||
IPS_LogMessage("im2", $LegioCounter);
|
||||
|
||||
}
|
||||
if ($LegioCounter > 69120) {
|
||||
$maxTemp = $LegioTemp;
|
||||
IPS_LogMessage("im3", $LegioCounter);
|
||||
|
||||
|
||||
}
|
||||
if(($LegioCounter>120960) && ($this->ist_nachts())){
|
||||
if ($LegioCounter > 120960 && $this->ist_nachts()) {
|
||||
$minTemp = $LegioTemp;
|
||||
IPS_LogMessage("im4", $LegioCounter);
|
||||
|
||||
}
|
||||
|
||||
$this->SetValue("LegioCounter", $LegioCounter);
|
||||
|
||||
|
||||
if ($Peak) {
|
||||
if ($boilerTemp < $minTemp) {
|
||||
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
|
||||
|
||||
} elseif ($boilerTemp < ($minTemp + 5) && ($AktuelleVollast || $AktuelleTeillast)) {
|
||||
|
||||
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
|
||||
}
|
||||
else {
|
||||
$this->SetValue(
|
||||
"PowerSteps",
|
||||
json_encode([0, $teilLeistung, $vollLeistung])
|
||||
);
|
||||
} elseif (
|
||||
$boilerTemp < $minTemp + 5 &&
|
||||
($AktuelleVollast || $AktuelleTeillast)
|
||||
) {
|
||||
$this->SetValue(
|
||||
"PowerSteps",
|
||||
json_encode([0, $teilLeistung, $vollLeistung])
|
||||
);
|
||||
} else {
|
||||
$this->SetValue("PowerSteps", json_encode([0]));
|
||||
|
||||
}
|
||||
} else {
|
||||
if ($boilerTemp < $minTemp) {
|
||||
$this->SetValue("PowerSteps", json_encode([$vollLeistung]));
|
||||
|
||||
} elseif ($boilerTemp < ($minTemp + 5) && ($AktuelleVollast || $AktuelleTeillast)) {
|
||||
} elseif (
|
||||
$boilerTemp < $minTemp + 5 &&
|
||||
($AktuelleVollast || $AktuelleTeillast)
|
||||
) {
|
||||
$this->SetValue("PowerSteps", json_encode([$vollLeistung]));
|
||||
|
||||
}
|
||||
elseif ($boilerTemp < ($maxTemp-5)) {
|
||||
|
||||
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
|
||||
}
|
||||
elseif ($boilerTemp < ($maxTemp) && ($AktuelleVollast || $AktuelleTeillast)) {
|
||||
|
||||
$this->SetValue("PowerSteps", json_encode([0, $teilLeistung, $vollLeistung]));
|
||||
}
|
||||
else {
|
||||
|
||||
} elseif ($boilerTemp < $maxTemp - 5) {
|
||||
$this->SetValue(
|
||||
"PowerSteps",
|
||||
json_encode([0, $teilLeistung, $vollLeistung])
|
||||
);
|
||||
} elseif (
|
||||
$boilerTemp < $maxTemp &&
|
||||
($AktuelleVollast || $AktuelleTeillast)
|
||||
) {
|
||||
$this->SetValue(
|
||||
"PowerSteps",
|
||||
json_encode([0, $teilLeistung, $vollLeistung])
|
||||
);
|
||||
} else {
|
||||
$this->SetValue("PowerSteps", json_encode([0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function ProcessIdleCounter() {
|
||||
private function ProcessIdleCounter()
|
||||
{
|
||||
// IdleCounter auslesen und verarbeiten
|
||||
$idleCounter = $this->GetValue("IdleCounter");
|
||||
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");
|
||||
if ($lastpower != GetValue("CurrentPower")) {
|
||||
$this->SetValue("Idle", false);
|
||||
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
|
||||
$this->SetValue(
|
||||
"IdleCounter",
|
||||
$this->ReadPropertyInteger("IdleCounterMax")
|
||||
);
|
||||
}
|
||||
// IdleCounter auslesen und verarbeiten
|
||||
$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() {
|
||||
date_default_timezone_set('Europe/Berlin'); // Setze hier deine Zeitzone
|
||||
|
||||
$aktuelle_zeit = strtotime(date('H:i')); // Aktuelle Zeit in Stunden und Minuten umwandeln
|
||||
$start_nacht = strtotime('22:00'); // Startzeit der Nacht (22 Uhr)
|
||||
$ende_nacht = strtotime('07:00'); // Endzeit der Nacht (7 Uhr)
|
||||
$aktuelle_zeit = strtotime(date("H:i")); // Aktuelle Zeit in Stunden und Minuten umwandeln
|
||||
$start_nacht = strtotime("22:00"); // Startzeit der Nacht (22 Uhr)
|
||||
$ende_nacht = strtotime("07:00"); // Endzeit der Nacht (7 Uhr)
|
||||
|
||||
if ($aktuelle_zeit >= $start_nacht || $aktuelle_zeit < $ende_nacht) {
|
||||
return true;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
{
|
||||
"translations": {
|
||||
"de": {
|
||||
"Translation 1": "Übersetzung 1",
|
||||
"Translation 2": "Übersetzung 2"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,52 +2,53 @@
|
||||
|
||||
class CC100_HW extends IPSModule
|
||||
{
|
||||
private $DigOutPID = '/sys/kernel/dout_drv/DOUT_DATA';
|
||||
private $PT1PID = '/sys/bus/iio/devices/iio:device2/in_voltage13_raw';
|
||||
private $PT2PID = '/sys/bus/iio/devices/iio:device2/in_voltage1_raw';
|
||||
private $DigOutPID = "/sys/kernel/dout_drv/DOUT_DATA";
|
||||
private $PT1PID = "/sys/bus/iio/devices/iio:device2/in_voltage13_raw";
|
||||
private $PT2PID = "/sys/bus/iio/devices/iio:device2/in_voltage1_raw";
|
||||
private $DIN_FILE = "/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 $maxTime = 5000; // Max time (in ms) for the writing process
|
||||
|
||||
public function Create()
|
||||
{
|
||||
parent::Create();
|
||||
$this->RegisterPropertyString('FilePath', $this->DigOutPID);
|
||||
$this->RegisterVariableBoolean('Bit1', 'DO 1', '~Switch', 1);
|
||||
$this->RegisterVariableBoolean('Bit2', 'DO 2', '~Switch', 2);
|
||||
$this->RegisterVariableBoolean('Bit3', 'DO 3', '~Switch', 3);
|
||||
$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->RegisterPropertyString("FilePath", $this->DigOutPID);
|
||||
$this->RegisterVariableBoolean("Bit1", "DO 1", "~Switch", 1);
|
||||
$this->RegisterVariableBoolean("Bit2", "DO 2", "~Switch", 2);
|
||||
$this->RegisterVariableBoolean("Bit3", "DO 3", "~Switch", 3);
|
||||
$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->RegisterVariableFloat('PT1', 'PT1 Temperatur', '~Temperature', 5);
|
||||
$this->RegisterVariableFloat('PT2', 'PT2 Temperatur', '~Temperature', 6);
|
||||
$this->EnableAction('Bit1');
|
||||
$this->EnableAction('Bit2');
|
||||
$this->EnableAction('Bit3');
|
||||
$this->EnableAction('Bit4');
|
||||
$this->EnableAction("Bit1");
|
||||
$this->EnableAction("Bit2");
|
||||
$this->EnableAction("Bit3");
|
||||
$this->EnableAction("Bit4");
|
||||
|
||||
// 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("WriteBits", 2000, 'IPS_RequestAction(' . $this->InstanceID . ', "UpdateFile", "");');
|
||||
|
||||
}
|
||||
|
||||
public function ApplyChanges()
|
||||
{
|
||||
parent::ApplyChanges();
|
||||
// Timer aktivieren
|
||||
$this->SetTimerInterval('ReadPTValues', 30000);
|
||||
$this->SetTimerInterval("ReadPTValues", 30000);
|
||||
}
|
||||
|
||||
public function RequestAction($Ident, $Value) {
|
||||
public function RequestAction($Ident, $Value)
|
||||
{
|
||||
switch ($Ident) {
|
||||
case "DOUT_ReadPTValues":
|
||||
$this->DOUT_ReadPTValues();
|
||||
@@ -66,11 +67,8 @@ class CC100_HW extends IPSModule
|
||||
$this->TryWriteFile($starttime);
|
||||
}
|
||||
|
||||
|
||||
private function readAndConvertToBools($filePath)
|
||||
{
|
||||
|
||||
|
||||
// Inhalt der Datei auslesen
|
||||
$content = @file_get_contents($filePath);
|
||||
|
||||
@@ -83,7 +81,9 @@ class CC100_HW extends IPSModule
|
||||
|
||||
// Sicherstellen, dass die Zahl gültig ist
|
||||
if (!ctype_digit($number)) {
|
||||
throw new Exception("Der Inhalt der Datei ist keine gültige Zahl: $number");
|
||||
throw new Exception(
|
||||
"Der Inhalt der Datei ist keine gültige Zahl: $number"
|
||||
);
|
||||
}
|
||||
|
||||
// Die Zahl in einen Integer umwandeln
|
||||
@@ -91,14 +91,19 @@ class CC100_HW extends IPSModule
|
||||
|
||||
// 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");
|
||||
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));
|
||||
$boolValues = array_map(
|
||||
fn($bit) => $bit === "1",
|
||||
str_split($binaryString)
|
||||
);
|
||||
|
||||
$this->SetValue("DI1", $boolValues[7]);
|
||||
$this->SetValue("DI2", $boolValues[6]);
|
||||
@@ -111,36 +116,39 @@ class CC100_HW extends IPSModule
|
||||
return $boolValues;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
if (($currentTime - $starttime) <= $this->maxTime) {
|
||||
$file = $this->ReadPropertyString('FilePath');
|
||||
if ($currentTime - $starttime <= $this->maxTime) {
|
||||
$file = $this->ReadPropertyString("FilePath");
|
||||
if (is_writable($file)) {
|
||||
$bit1 = GetValueBoolean($this->GetIDForIdent('Bit1'));
|
||||
$bit2 = GetValueBoolean($this->GetIDForIdent('Bit2'));
|
||||
$bit3 = GetValueBoolean($this->GetIDForIdent('Bit3'));
|
||||
$bit4 = GetValueBoolean($this->GetIDForIdent('Bit4'));
|
||||
$bit1 = GetValueBoolean($this->GetIDForIdent("Bit1"));
|
||||
$bit2 = GetValueBoolean($this->GetIDForIdent("Bit2"));
|
||||
$bit3 = GetValueBoolean($this->GetIDForIdent("Bit3"));
|
||||
$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) {
|
||||
IPS_LogMessage("DOUTModule", "Fehler: Datei $file konnte nicht beschrieben werden. Möglicherweise gesperrt.");
|
||||
usleep($this->waitingTime * 1000);
|
||||
$this->TryWriteFile($starttime);
|
||||
} else {
|
||||
IPS_LogMessage("DOUTModule", "Wert $value erfolgreich in die Datei $file geschrieben.");
|
||||
}
|
||||
} else {
|
||||
IPS_LogMessage("DOUTModule", "Fehler: Datei $file ist nicht schreibbar.");
|
||||
usleep($this->waitingTime * 1000);
|
||||
$this->TryWriteFile($starttime);
|
||||
}
|
||||
} else {
|
||||
IPS_LogMessage("DOUTModule", "Fehler: Schreibvorgang für Datei $file hat zu lange gedauert.");
|
||||
|
||||
usleep($this->waitingTime * 1000);
|
||||
$this->TryWriteFile($starttime);
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
$pt2Value = $this->ReadPTValue($this->PT2PID);
|
||||
|
||||
SetValue($this->GetIDForIdent('PT1'), $pt1Value);
|
||||
SetValue($this->GetIDForIdent('PT2'), $pt2Value);
|
||||
SetValue($this->GetIDForIdent("PT1"), $pt1Value);
|
||||
SetValue($this->GetIDForIdent("PT2"), $pt2Value);
|
||||
}
|
||||
|
||||
private function ReadPTValue($file)
|
||||
@@ -160,21 +168,35 @@ class CC100_HW extends IPSModule
|
||||
if ($data !== false) {
|
||||
$data = intval($data);
|
||||
$scale = 0;
|
||||
if ($data >= 600 && $data < 3600) { $scale = 37;}
|
||||
else if ($data >= 3600 && $data < 6700) { $scale = 43;}
|
||||
else if ($data >= 6700 && $data < 9750) { $scale = 45;}
|
||||
else if ($data >= 9750 && $data < 12740) { $scale = 49;}
|
||||
else if ($data >= 12740 && $data < 15700) { $scale = 50.6;}
|
||||
else if ($data >= 15700 && $data < 21000) { $scale = 52.4;}
|
||||
else if ($data > 21000) { $scale = 53.7;}
|
||||
if ($data >= 600 && $data < 3600) {
|
||||
$scale = 37;
|
||||
} elseif ($data >= 3600 && $data < 6700) {
|
||||
$scale = 43;
|
||||
} elseif ($data >= 6700 && $data < 9750) {
|
||||
$scale = 45;
|
||||
} 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;
|
||||
return round($numb, 1);
|
||||
} else {
|
||||
IPS_LogMessage("DOUTModule", "Fehler: Datei $file konnte nicht gelesen werden.");
|
||||
IPS_LogMessage(
|
||||
"DOUTModule",
|
||||
"Fehler: Datei $file konnte nicht gelesen werden."
|
||||
);
|
||||
}
|
||||
} else {
|
||||
IPS_LogMessage("DOUTModule", "Fehler: Datei $file existiert nicht.");
|
||||
IPS_LogMessage(
|
||||
"DOUTModule",
|
||||
"Fehler: Datei $file existiert nicht."
|
||||
);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"translations": {
|
||||
"de": {
|
||||
"Translation 1": "Übersetzung 1",
|
||||
"Translation 2": "Übersetzung 2"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
<?php
|
||||
|
||||
class Ladestation_Universal extends IPSModule {
|
||||
|
||||
public function Create() {
|
||||
class Ladestation_Universal extends IPSModule
|
||||
{
|
||||
public function Create()
|
||||
{
|
||||
parent::Create();
|
||||
|
||||
// Prioritäten
|
||||
@@ -34,8 +35,6 @@ public function Create() {
|
||||
$this->RegisterVariableInteger("Lademodus", "Lademodus", "", 0);
|
||||
$this->RegisterVariableFloat("Ladeleistung_Effektiv", "Ladeleistung_Effektiv", "", 0);
|
||||
|
||||
|
||||
|
||||
$this->RegisterVariableBoolean("Peak", "Peak", "", 0);
|
||||
|
||||
$this->RegisterVariableInteger("Ladestrom", "Ladestrom");
|
||||
@@ -45,13 +44,15 @@ public function Create() {
|
||||
$this->SetValue("Idle", true);
|
||||
}
|
||||
|
||||
public function ApplyChanges() {
|
||||
public function ApplyChanges()
|
||||
{
|
||||
parent::ApplyChanges();
|
||||
// Zusätzliche Anpassungen nach Bedarf
|
||||
}
|
||||
|
||||
// Aktionen verarbeiten
|
||||
public function RequestAction($Ident, $Value) {
|
||||
public function RequestAction($Ident, $Value)
|
||||
{
|
||||
switch ($Ident) {
|
||||
case "SetCurrentPower":
|
||||
$this->SetCurrentPower($Value);
|
||||
@@ -64,7 +65,8 @@ public function RequestAction($Ident, $Value) {
|
||||
}
|
||||
}
|
||||
|
||||
public function SetCurrentPower(int $power) {
|
||||
public function SetCurrentPower(int $power)
|
||||
{
|
||||
$internalPower = GetValue($this->GetIDForIdent("CurrentPower"));
|
||||
// Aktuelle Leistungsvorgabe setzen
|
||||
SetValue($this->GetIDForIdent("CurrentPower"), $power);
|
||||
@@ -73,7 +75,10 @@ public function SetCurrentPower(int $power) {
|
||||
|
||||
// Idle für 4 Zyklen auf false setzen
|
||||
SetValue($this->GetIDForIdent("Idle"), false);
|
||||
SetValue($this->GetIDForIdent("IdleCounter"), $this->ReadPropertyInteger("IdleCounterMax"));
|
||||
SetValue(
|
||||
$this->GetIDForIdent("IdleCounter"),
|
||||
$this->ReadPropertyInteger("IdleCounterMax")
|
||||
);
|
||||
} else {
|
||||
// IdleCallCounter herunterzählen, wenn power == interne Leistungsvorgabe
|
||||
$idleCounter = GetValue($this->GetIDForIdent("IdleCounter"));
|
||||
@@ -86,80 +91,78 @@ public function SetCurrentPower(int $power) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 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) {
|
||||
} elseif (!$peak && !$solarladen) {
|
||||
// Wenn weder Peak noch Solarladen aktiv sind, setze Ladeleistung auf MaxLeistung
|
||||
SetValue($this->GetIDForIdent("Ladeleistung"), $this->ReadPropertyInteger("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"));
|
||||
|
||||
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"));
|
||||
|
||||
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));
|
||||
|
||||
SetValue(
|
||||
$this->GetIDForIdent("Ladestrom"),
|
||||
$power / 400 / sqrt(3)
|
||||
);
|
||||
}
|
||||
|
||||
$this->sendPowerToStation($power);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Methode zum Abrufen der aktuellen Daten
|
||||
public function GetCurrentData(bool $Peak) {
|
||||
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");
|
||||
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);
|
||||
@@ -176,29 +179,24 @@ public function GetCurrentData(bool $Peak) {
|
||||
$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'])) {
|
||||
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("Ladeleistung_Effektiv"), $data['nrg'][11]);
|
||||
SetValue($this->GetIDForIdent("Fahrzeugstatus"), $data["car"]);
|
||||
|
||||
SetValue($this->GetIDForIdent("Fahrzeugstatus"), $data['car']);
|
||||
|
||||
|
||||
if($data['nrg'][6]>1 && $data['car']==2){
|
||||
if ($data["nrg"][6] > 1 && $data["car"] == 2) {
|
||||
SetValue($this->GetIDForIdent("Lademodus"), 1);
|
||||
|
||||
}elseif($data['nrg'][6]<=1 && $data['car']==2){
|
||||
} elseif ($data["nrg"][6] <= 1 && $data["car"] == 2) {
|
||||
SetValue($this->GetIDForIdent("Lademodus"), 0);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Peak-Wert speichern
|
||||
$this->SetValue("Peak", $Peak);
|
||||
|
||||
@@ -209,19 +207,25 @@ public function GetCurrentData(bool $Peak) {
|
||||
// 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"))));
|
||||
|
||||
$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 += $this->getRangeLimits(
|
||||
$minLeistung,
|
||||
$maxLeistung,
|
||||
GetValue($this->GetIDForIdent("Lademodus"))
|
||||
);
|
||||
}
|
||||
}
|
||||
// PowerSteps in der RegisterVariable speichern
|
||||
@@ -231,12 +235,16 @@ public function GetCurrentData(bool $Peak) {
|
||||
return $powerSteps;
|
||||
}
|
||||
|
||||
|
||||
public function sendPowerToStation($value) {
|
||||
public function sendPowerToStation($value)
|
||||
{
|
||||
// Base URL
|
||||
$baseUrl = "http://" . $this->ReadPropertyString("IP_Adresse") . "/api/set?";
|
||||
$baseUrl =
|
||||
"http://" . $this->ReadPropertyString("IP_Adresse") . "/api/set?";
|
||||
IPS_LogMessage("Ladestation", "Aufgerufene ip" . $baseUrl);
|
||||
$value = $this->convertPowerToCurrent($value, GetValue($this->GetIDForIdent("Lademodus")));
|
||||
$value = $this->convertPowerToCurrent(
|
||||
$value,
|
||||
GetValue($this->GetIDForIdent("Lademodus"))
|
||||
);
|
||||
// Initialize a cURL session
|
||||
$ch = curl_init();
|
||||
|
||||
@@ -261,7 +269,7 @@ public function sendPowerToStation($value) {
|
||||
// Check for errors
|
||||
if (curl_errno($ch)) {
|
||||
curl_close($ch);
|
||||
return 'Error:' . curl_error($ch);
|
||||
return "Error:" . curl_error($ch);
|
||||
}
|
||||
|
||||
// Second request
|
||||
@@ -272,7 +280,7 @@ public function sendPowerToStation($value) {
|
||||
// Check for errors
|
||||
if (curl_errno($ch)) {
|
||||
curl_close($ch);
|
||||
return 'Error:' . curl_error($ch);
|
||||
return "Error:" . curl_error($ch);
|
||||
}
|
||||
|
||||
// Close cURL session
|
||||
@@ -288,8 +296,8 @@ public function sendPowerToStation($value) {
|
||||
}
|
||||
}
|
||||
|
||||
public function convertPowerToCurrent($value, $Lademodus) {
|
||||
|
||||
public function convertPowerToCurrent($value, $Lademodus)
|
||||
{
|
||||
if ($Lademodus == 1) {
|
||||
if ($value == 0) {
|
||||
return 0;
|
||||
@@ -349,7 +357,6 @@ public function convertPowerToCurrent($value, $Lademodus) {
|
||||
return 32;
|
||||
}
|
||||
return 0;
|
||||
|
||||
} elseif ($Lademodus == 0) {
|
||||
if ($value == 0) {
|
||||
return 0;
|
||||
@@ -409,12 +416,11 @@ public function convertPowerToCurrent($value, $Lademodus) {
|
||||
return 32;
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function getRangeLimits($min, $max, $Lademodus) {
|
||||
public function getRangeLimits($min, $max, $Lademodus)
|
||||
{
|
||||
if ($Lademodus == 1) {
|
||||
$limits = [
|
||||
4150,
|
||||
@@ -443,9 +449,9 @@ public function getRangeLimits($min, $max, $Lademodus) {
|
||||
20100,
|
||||
20800,
|
||||
21500,
|
||||
22000
|
||||
];}
|
||||
elseif($Lademodus==0){
|
||||
22000,
|
||||
];
|
||||
} elseif ($Lademodus == 0) {
|
||||
$limits = [
|
||||
1450,
|
||||
1690,
|
||||
@@ -473,7 +479,7 @@ public function getRangeLimits($min, $max, $Lademodus) {
|
||||
6970,
|
||||
7210,
|
||||
7450,
|
||||
7690
|
||||
7690,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -487,6 +493,5 @@ public function getRangeLimits($min, $max, $Lademodus) {
|
||||
|
||||
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", "[]");
|
||||
|
||||
// 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()
|
||||
@@ -41,10 +47,11 @@ class Manager extends IPSModule
|
||||
public function DistributeEnergy()
|
||||
{
|
||||
// Systemvariablen abrufen
|
||||
$Netzbezug = GetValue($this->ReadPropertyInteger('Netzbezug'));
|
||||
$Peakleistung = $this->ReadPropertyInteger('Peakleistung');
|
||||
$Ueberschussleistung = $this->ReadPropertyInteger('Ueberschussleistung');
|
||||
|
||||
$Netzbezug = GetValue($this->ReadPropertyInteger("Netzbezug"));
|
||||
$Peakleistung = $this->ReadPropertyInteger("Peakleistung");
|
||||
$Ueberschussleistung = $this->ReadPropertyInteger(
|
||||
"Ueberschussleistung"
|
||||
);
|
||||
|
||||
// Fallunterscheidung
|
||||
if ($Netzbezug < ($Peakleistung - $Ueberschussleistung) / 2) {
|
||||
@@ -66,8 +73,12 @@ class Manager extends IPSModule
|
||||
|
||||
// Schleife, um IPS_RequestAction für alle Benutzer auszuführen
|
||||
foreach ($energyUserList as $user) {
|
||||
if (IPS_InstanceExists($user['EnergyUser'])) {
|
||||
IPS_RequestAction($user['EnergyUser'], 'GetCurrentData', $getCurrentDataParam);
|
||||
if (IPS_InstanceExists($user["EnergyUser"])) {
|
||||
IPS_RequestAction(
|
||||
$user["EnergyUser"],
|
||||
"GetCurrentData",
|
||||
$getCurrentDataParam
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,29 +87,29 @@ class Manager extends IPSModule
|
||||
$totalCurrentPower = 0; // Variable zur Summierung der CurrentPower Werte
|
||||
|
||||
foreach ($energyUserList as $user) {
|
||||
if (!IPS_InstanceExists($user['EnergyUser'])) {
|
||||
if (!IPS_InstanceExists($user["EnergyUser"])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Werte direkt von der EnergyUser-Instanz abrufen
|
||||
$currentPower = GetValue(IPS_GetObjectIDByIdent('CurrentPower', $user['EnergyUser']));
|
||||
$usedEnergy = GetValue(IPS_GetObjectIDByIdent('UsedEnergy', $user['EnergyUser']));
|
||||
$userPrio = GetValue(IPS_GetObjectIDByIdent('UserPrio', $user['EnergyUser']));
|
||||
$lockPrio = GetValue(IPS_GetObjectIDByIdent('LockPrio', $user['EnergyUser']));
|
||||
$idle = GetValue(IPS_GetObjectIDByIdent('Idle', $user['EnergyUser']));
|
||||
$powerStepsJson = GetValue(IPS_GetObjectIDByIdent('PowerSteps', $user['EnergyUser']));
|
||||
$currentPower = GetValue(IPS_GetObjectIDByIdent("CurrentPower", $user["EnergyUser"]));
|
||||
$usedEnergy = GetValue(IPS_GetObjectIDByIdent("UsedEnergy", $user["EnergyUser"]));
|
||||
$userPrio = GetValue(IPS_GetObjectIDByIdent("UserPrio", $user["EnergyUser"]));
|
||||
$lockPrio = GetValue(IPS_GetObjectIDByIdent("LockPrio", $user["EnergyUser"]));
|
||||
$idle = GetValue(IPS_GetObjectIDByIdent("Idle", $user["EnergyUser"]));
|
||||
$powerStepsJson = GetValue(IPS_GetObjectIDByIdent("PowerSteps", $user["EnergyUser"]));
|
||||
$powerSteps = json_decode($powerStepsJson, true);
|
||||
|
||||
// EnergyUser-Daten zum gefilterten Array hinzufügen
|
||||
$filteredEnergyUsers[] = [
|
||||
'EnergyUser' => $user['EnergyUser'],
|
||||
'InstanceID' => $user['EnergyUser'],
|
||||
'CurrentPower' => $currentPower,
|
||||
'UsedEnergy' => $usedEnergy,
|
||||
'UserPrio' => $userPrio,
|
||||
'LockPrio' => $lockPrio,
|
||||
'Idle' => $idle,
|
||||
'PowerSteps' => $powerSteps, // PowerSteps direkt hier hinzufügen
|
||||
"EnergyUser" => $user["EnergyUser"],
|
||||
"InstanceID" => $user["EnergyUser"],
|
||||
"CurrentPower" => $currentPower,
|
||||
"UsedEnergy" => $usedEnergy,
|
||||
"UserPrio" => $userPrio,
|
||||
"LockPrio" => $lockPrio,
|
||||
"Idle" => $idle,
|
||||
"PowerSteps" => $powerSteps, // PowerSteps direkt hier hinzufügen
|
||||
];
|
||||
|
||||
// Überprüfen, ob alle Benutzer Idle = true sind
|
||||
@@ -111,7 +122,6 @@ class Manager extends IPSModule
|
||||
}
|
||||
$remainingPower += $totalCurrentPower;
|
||||
|
||||
|
||||
if (empty($filteredEnergyUsers)) {
|
||||
return;
|
||||
}
|
||||
@@ -119,42 +129,51 @@ class Manager extends IPSModule
|
||||
// Wenn nicht alle Benutzer Idle = true sind, rufe SetCurrentPower mit CurrentPower Werten auf
|
||||
if (!$allIdle) {
|
||||
foreach ($filteredEnergyUsers as $user) {
|
||||
IPS_RequestAction($user['InstanceID'], 'SetCurrentPower', $user['CurrentPower']);
|
||||
IPS_RequestAction(
|
||||
$user["InstanceID"],
|
||||
"SetCurrentPower",
|
||||
$user["CurrentPower"]
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Sortiere die EnergyUser nach Priorität basierend auf dem Parameter
|
||||
usort($filteredEnergyUsers, function ($a, $b) use ($getCurrentDataParam) {
|
||||
$primaryKey = $getCurrentDataParam ? 'LockPrio' : 'UserPrio';
|
||||
usort($filteredEnergyUsers, function ($a, $b) use (
|
||||
$getCurrentDataParam
|
||||
) {
|
||||
$primaryKey = $getCurrentDataParam ? "LockPrio" : "UserPrio";
|
||||
|
||||
if ($a[$primaryKey] == $b[$primaryKey]) {
|
||||
return $a['UsedEnergy'] <=> $b['UsedEnergy'];
|
||||
return $a["UsedEnergy"] <=> $b["UsedEnergy"];
|
||||
}
|
||||
|
||||
return $a[$primaryKey] <=> $b[$primaryKey];
|
||||
});
|
||||
|
||||
// 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
|
||||
$priorities = array_unique(array_column($filteredEnergyUsers, $priorityKey));
|
||||
$priorities = array_unique(
|
||||
array_column($filteredEnergyUsers, $priorityKey)
|
||||
);
|
||||
$groupedUsers = [];
|
||||
|
||||
foreach ($priorities as $priority) {
|
||||
$groupedUsers[$priority] = array_filter($filteredEnergyUsers, function ($user) use ($priority, $priorityKey) {
|
||||
$groupedUsers[$priority] = array_filter(
|
||||
$filteredEnergyUsers,
|
||||
function ($user) use ($priority, $priorityKey) {
|
||||
return $user[$priorityKey] == $priority;
|
||||
});
|
||||
}
|
||||
IPS_LogMessage("Manager", print_r($groupedUsers, true));
|
||||
|
||||
);
|
||||
}
|
||||
// Jetzt kannst du die Benutzer gruppenweise verarbeiten
|
||||
foreach ($groupedUsers as $priority => $users) {
|
||||
// EnergyUser mit gleicher Priorität sammeln
|
||||
$samePriorityUsers = isset($groupedUsers[$priority]) ? $groupedUsers[$priority] : [];
|
||||
IPS_LogMessage("Manager", print_r($samePriorityUsers, true));
|
||||
|
||||
$samePriorityUsers = isset($groupedUsers[$priority])
|
||||
? $groupedUsers[$priority]
|
||||
: [];
|
||||
|
||||
// Wenn keine EnergyUser mit gleicher Priorität vorhanden sind, überspringen
|
||||
if (empty($samePriorityUsers)) {
|
||||
@@ -164,7 +183,7 @@ class Manager extends IPSModule
|
||||
$withoutZero = [];
|
||||
// Verbraucher die nicht 0 Annhemen können, bekommen einfach den tiefsten wert
|
||||
foreach ($samePriorityUsers as $entry) {
|
||||
if (in_array(0, $entry['PowerSteps'])) {
|
||||
if (in_array(0, $entry["PowerSteps"])) {
|
||||
$withZero[] = $entry;
|
||||
} else {
|
||||
$withoutZero[] = $entry;
|
||||
@@ -173,40 +192,46 @@ class Manager extends IPSModule
|
||||
// Methode für alle im withoutZero-Array aufrufen
|
||||
if (!empty($withoutZero)) {
|
||||
foreach ($withoutZero as $entry) {
|
||||
$instanceID = $entry['InstanceID'];
|
||||
$minPowerStep = min($entry['PowerSteps']);
|
||||
$instanceID = $entry["InstanceID"];
|
||||
$minPowerStep = min($entry["PowerSteps"]);
|
||||
|
||||
// Simulierte Methode (Debug-Ausgabe)
|
||||
IPS_RequestAction($instanceID, 'SetCurrentPower', $minPowerStep);
|
||||
$remainingPower -= $entry['CurrentPower'];
|
||||
|
||||
// Hier kann der tatsächliche Funktionsaufruf eingebaut werden
|
||||
// IPS_RequestAction($instanceID, 'SetCurrentPower', $minPowerStep);
|
||||
}}
|
||||
IPS_RequestAction(
|
||||
$instanceID,
|
||||
"SetCurrentPower",
|
||||
$minPowerStep
|
||||
);
|
||||
$remainingPower -= $entry["CurrentPower"];
|
||||
}
|
||||
}
|
||||
$samePriorityUsers = $withZero;
|
||||
// Array für die verteilte Energie pro User erstellen
|
||||
$userEnergyProv = [];
|
||||
$userEnergyProv = array_fill_keys(array_column($samePriorityUsers, 'InstanceID'), 0); // Initialisierung für jeden Benutzer auf 0 setzen
|
||||
IPS_LogMessage("userEnergyProv", print_r($userEnergyProv, true));
|
||||
$userEnergyProv = array_fill_keys(
|
||||
array_column($samePriorityUsers, "InstanceID"),
|
||||
0
|
||||
); // Initialisierung für jeden Benutzer auf 0 setzen
|
||||
|
||||
// Alle Schritte der Benutzer in einem Array sammeln
|
||||
$allSteps = [];
|
||||
foreach ($samePriorityUsers as $user) {
|
||||
foreach ($user['PowerSteps'] as $step) {
|
||||
$allSteps[] = ['user' => $user['InstanceID'], 'step' => $step];
|
||||
foreach ($user["PowerSteps"] as $step) {
|
||||
$allSteps[] = [
|
||||
"user" => $user["InstanceID"],
|
||||
"step" => $step,
|
||||
];
|
||||
}
|
||||
}
|
||||
IPS_LogMessage("allSteps", print_r($allSteps, true));
|
||||
|
||||
// Sortiere die Schritte nach Größe
|
||||
usort($allSteps, function ($a, $b) {
|
||||
return $a['step'] <=> $b['step'];
|
||||
return $a["step"] <=> $b["step"];
|
||||
});
|
||||
|
||||
// Iteriere durch alle Schritte
|
||||
foreach ($allSteps as $entry) {
|
||||
$user = $entry['user'];
|
||||
$powerstep = $entry['step'];
|
||||
$user = $entry["user"];
|
||||
$powerstep = $entry["step"];
|
||||
|
||||
// Überprüfe, ob noch genügend verbleibende Energie für den nächsten Schritt vorhanden ist
|
||||
if ($remainingPower >= $powerstep - $userEnergyProv[$user]) {
|
||||
@@ -215,7 +240,6 @@ class Manager extends IPSModule
|
||||
$userEnergyProv[$user] = $powerstep;
|
||||
} //else {
|
||||
// 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) {
|
||||
$weui = min(
|
||||
array_column(
|
||||
array_filter($allSteps, function ($entry) use ($userInstanceID) {
|
||||
return $entry['user'] == $userInstanceID;
|
||||
array_filter($allSteps, function ($entry) use (
|
||||
$userInstanceID
|
||||
) {
|
||||
return $entry["user"] == $userInstanceID;
|
||||
}),
|
||||
'step'
|
||||
"step"
|
||||
)
|
||||
);
|
||||
|
||||
@@ -234,15 +260,14 @@ class Manager extends IPSModule
|
||||
|
||||
// Methode SetCurrentPower für jeden EnergyUser aufrufen
|
||||
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
|
||||
class Verbraucher_1_Stufig extends IPSModule {
|
||||
|
||||
class Verbraucher_1_Stufig extends IPSModule
|
||||
{
|
||||
private $timerID;
|
||||
|
||||
public function Create() {
|
||||
public function Create()
|
||||
{
|
||||
parent::Create();
|
||||
|
||||
// Prioritäten
|
||||
@@ -33,20 +34,26 @@ class Verbraucher_1_Stufig extends IPSModule {
|
||||
$this->RegisterPropertyInteger("Schaltkontakt1", 0);
|
||||
|
||||
// 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
|
||||
$this->SetValue("Idle", true);
|
||||
}
|
||||
|
||||
public function ApplyChanges() {
|
||||
public function ApplyChanges()
|
||||
{
|
||||
parent::ApplyChanges();
|
||||
}
|
||||
|
||||
// Aktionen verarbeiten
|
||||
public function RequestAction($Ident, $Value) {
|
||||
public function RequestAction($Ident, $Value)
|
||||
{
|
||||
switch ($Ident) {
|
||||
case "SetCurrentPower":
|
||||
$this->SetCurrentPower($Value);
|
||||
@@ -62,25 +69,31 @@ class Verbraucher_1_Stufig extends IPSModule {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Methode zum Setzen der PowerSteps und Timer starten
|
||||
public function SetTimerOn() {
|
||||
|
||||
public function SetTimerOn()
|
||||
{
|
||||
// Timer setzen, der nach "Zeit_Zwischen_Zustandswechseln" abläuft
|
||||
$zeitZwischenZustandswechseln = $this->ReadPropertyInteger("Zeit_Zwischen_Zustandswechseln");
|
||||
$this->SetTimerInterval("ZustandswechselTimer", $zeitZwischenZustandswechseln * 60000); // Timer in Millisekunden
|
||||
$zeitZwischenZustandswechseln = $this->ReadPropertyInteger(
|
||||
"Zeit_Zwischen_Zustandswechseln"
|
||||
);
|
||||
$this->SetTimerInterval(
|
||||
"ZustandswechselTimer",
|
||||
$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
|
||||
public function ResetPowerSteps() {
|
||||
public function ResetPowerSteps()
|
||||
{
|
||||
// PowerSteps wieder auf den ursprünglichen Zustand setzen (wie vorherige Funktionalität)
|
||||
$this->SetValue("PowerSteps", json_encode([$this->GetValue("CurrentPower")]));
|
||||
IPS_LogMessage("Verbraucher", "In Reset Methode");
|
||||
$this->SetValue(
|
||||
"PowerSteps",
|
||||
json_encode([$this->GetValue("CurrentPower")])
|
||||
);
|
||||
|
||||
// Timer stoppen
|
||||
$this->SetTimerInterval("ZustandswechselTimer", 0);
|
||||
@@ -89,7 +102,8 @@ class Verbraucher_1_Stufig extends IPSModule {
|
||||
$this->SetValue("IsTimerActive", false);
|
||||
}
|
||||
// Methode zum Setzen des aktuellen Stromverbrauchs
|
||||
public function SetCurrentPower(float $power) {
|
||||
public function SetCurrentPower(float $power)
|
||||
{
|
||||
$this->CheckIdle($power);
|
||||
if ($this->GetValue("CurrentPower") != $power) {
|
||||
$this->SetTimerOn();
|
||||
@@ -110,7 +124,10 @@ class Verbraucher_1_Stufig extends IPSModule {
|
||||
$currentStatus = GetValue($this->ReadPropertyInteger("Schaltkontakt1"));
|
||||
|
||||
// Schaltkontaktstatus ändern
|
||||
SetValue($this->ReadPropertyInteger("Schaltkontakt1"), $schaltkontaktStatus);
|
||||
SetValue(
|
||||
$this->ReadPropertyInteger("Schaltkontakt1"),
|
||||
$schaltkontaktStatus
|
||||
);
|
||||
|
||||
if ($schaltkontaktStatus) {
|
||||
$this->SetValue("DailyOnTime", $this->GetValue("DailyOnTime") + 1);
|
||||
@@ -118,7 +135,8 @@ class Verbraucher_1_Stufig extends IPSModule {
|
||||
}
|
||||
|
||||
// Methode zum Abrufen der aktuellen Daten
|
||||
public function GetCurrentData(bool $Peak) {
|
||||
public function GetCurrentData(bool $Peak)
|
||||
{
|
||||
$IstNacht = $this->GetValue("IstNacht");
|
||||
$NeuesIstNacht = $this->ist_nachts();
|
||||
|
||||
@@ -129,17 +147,27 @@ class Verbraucher_1_Stufig extends IPSModule {
|
||||
$this->SetValue("IstNacht", $NeuesIstNacht);
|
||||
|
||||
$DailyOnTime = $this->GetValue("DailyOnTime");
|
||||
$Mindestlaufzeit = $this->ReadPropertyInteger("Mindesttlaufzeit") * 60 * 12;
|
||||
$Mindestlaufzeit =
|
||||
$this->ReadPropertyInteger("Mindesttlaufzeit") * 60 * 12;
|
||||
|
||||
// Überprüfen, ob der Timer aktiv ist
|
||||
if ($this->GetValue("IsTimerActive")) {
|
||||
// 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
|
||||
else if($NeuesIstNacht && ($DailyOnTime < $Mindestlaufzeit)) {
|
||||
elseif ($NeuesIstNacht && $DailyOnTime < $Mindestlaufzeit) {
|
||||
if ($Peak) {
|
||||
$this->SetValue("PowerSteps", json_encode([0, $this->ReadPropertyInteger("BoilerLeistung")]));
|
||||
$this->SetValue(
|
||||
"PowerSteps",
|
||||
json_encode([
|
||||
0,
|
||||
$this->ReadPropertyInteger("BoilerLeistung"),
|
||||
])
|
||||
);
|
||||
} else {
|
||||
$this->SetValue("PowerSteps",json_encode([$this->ReadPropertyInteger("BoilerLeistung")]));
|
||||
}
|
||||
@@ -149,12 +177,14 @@ class Verbraucher_1_Stufig extends IPSModule {
|
||||
if ($Peak) {
|
||||
$this->SetValue("PowerSteps", json_encode([0]));
|
||||
} 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"));
|
||||
if ($lastpower != $power) {
|
||||
$this->SetValue("Idle", false);
|
||||
@@ -170,12 +200,13 @@ class Verbraucher_1_Stufig extends IPSModule {
|
||||
}
|
||||
}
|
||||
|
||||
private function ist_nachts() {
|
||||
date_default_timezone_set('Europe/Berlin'); // Setze hier deine Zeitzone
|
||||
private function ist_nachts()
|
||||
{
|
||||
date_default_timezone_set("Europe/Berlin"); // Setze hier deine Zeitzone
|
||||
|
||||
$aktuelle_zeit = strtotime(date('H:i')); // Aktuelle Zeit in Stunden und Minuten umwandeln
|
||||
$start_nacht = strtotime('22:00'); // Startzeit der Nacht (22 Uhr)
|
||||
$ende_nacht = strtotime('07:00'); // Endzeit der Nacht (7 Uhr)
|
||||
$aktuelle_zeit = strtotime(date("H:i")); // Aktuelle Zeit in Stunden und Minuten umwandeln
|
||||
$start_nacht = strtotime("22:00"); // Startzeit der Nacht (22 Uhr)
|
||||
$ende_nacht = strtotime("07:00"); // Endzeit der Nacht (7 Uhr)
|
||||
|
||||
if ($aktuelle_zeit >= $start_nacht || $aktuelle_zeit < $ende_nacht) {
|
||||
return true;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
class WP_Steuerung extends IPSModule {
|
||||
|
||||
|
||||
public function Create() {
|
||||
class WP_Steuerung extends IPSModule
|
||||
{
|
||||
public function Create()
|
||||
{
|
||||
parent::Create();
|
||||
|
||||
// Prioritäten
|
||||
@@ -29,9 +29,6 @@ class WP_Steuerung extends IPSModule {
|
||||
$this->RegisterVariableBoolean("LetzterPeakwert", "LetzterPeakwert", "", false);
|
||||
$this->RegisterVariableBoolean("LetzterPeakwert_Aenderung", "LetzterPeakwert_Aenderung", "", false);
|
||||
|
||||
|
||||
|
||||
|
||||
$this->RegisterPropertyInteger("WP_Leistung", 6000);
|
||||
$this->RegisterPropertyInteger("Wolkenschwellwert", 60);
|
||||
$this->RegisterPropertyInteger("Wolkenwert", 0);
|
||||
@@ -47,12 +44,14 @@ class WP_Steuerung extends IPSModule {
|
||||
$this->SetValue("Idle", true);
|
||||
}
|
||||
|
||||
public function ApplyChanges() {
|
||||
public function ApplyChanges()
|
||||
{
|
||||
parent::ApplyChanges();
|
||||
}
|
||||
|
||||
// Aktionen verarbeiten
|
||||
public function RequestAction($Ident, $Value) {
|
||||
public function RequestAction($Ident, $Value)
|
||||
{
|
||||
switch ($Ident) {
|
||||
case "SetCurrentPower":
|
||||
$this->SetCurrentPower($Value);
|
||||
@@ -69,50 +68,65 @@ class WP_Steuerung extends IPSModule {
|
||||
}
|
||||
|
||||
// Methode zum Setzen des aktuellen Stromverbrauchs
|
||||
public function SetCurrentPower(float $power) {
|
||||
|
||||
$sperrzei_abs = 60*60*(GetValue($this->ReadPropertyInteger("Aussentemperatur"))+10)/25*6;
|
||||
public function SetCurrentPower(float $power)
|
||||
{
|
||||
$sperrzei_abs =
|
||||
((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;
|
||||
|
||||
}
|
||||
$sperrzeit = GetValue($this->ReadPropertyInteger("Referenzzeit"))%86400 - $sperrzei_abs;
|
||||
$sperrzeit = (GetValue($this->ReadPropertyInteger("Referenzzeit")) % 86400) - $sperrzei_abs;
|
||||
$entsperrzeit = GetValue($this->ReadPropertyInteger("Referenzzeit")) % 86400;
|
||||
$aktuellezeit = time() % 86400;
|
||||
|
||||
$this->CheckIdle($power);
|
||||
|
||||
$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);
|
||||
|
||||
}
|
||||
elseif($this->GetValue("WP_Laufzeit_Zahler")>240){
|
||||
} elseif ($this->GetValue("WP_Laufzeit_Zahler") > 240) {
|
||||
$this->SetValue("Sperrzeit", false);
|
||||
}
|
||||
|
||||
$newlocktime = $this->GetValue("Sperrzeit");
|
||||
|
||||
|
||||
if($newlocktime == true && $its_lock_time==false && $this->GetValue("WP_Laufzeit_Zahler")>240){
|
||||
if (
|
||||
$newlocktime == true &&
|
||||
$its_lock_time == false &&
|
||||
$this->GetValue("WP_Laufzeit_Zahler") > 240
|
||||
) {
|
||||
$this->SetValue("WP_Laufzeit_Zahler", 0);
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), true);
|
||||
|
||||
}
|
||||
|
||||
elseif($newlocktime == false && $its_lock_time == true && $this->GetValue("WP_Laufzeit_Zahler")>240){
|
||||
} elseif (
|
||||
$newlocktime == false &&
|
||||
$its_lock_time == true &&
|
||||
$this->GetValue("WP_Laufzeit_Zahler") > 240
|
||||
) {
|
||||
$this->SetValue("WP_Laufzeit_Zahler", 0);
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
elseif($this->GetValue("CurrentPower")!=$power || ($this->GetValue("WP_Laufzeit_Zahler")>240 && ($this->GetValue("LetzterPeakwert") != $this->GetValue("LetzterPeakwert_Aenderung"))) ){
|
||||
} elseif (
|
||||
$this->GetValue("CurrentPower") != $power ||
|
||||
($this->GetValue("WP_Laufzeit_Zahler") > 240 &&
|
||||
$this->GetValue("LetzterPeakwert") !=
|
||||
$this->GetValue("LetzterPeakwert_Aenderung"))
|
||||
) {
|
||||
$this->SetValue("WP_Laufzeit_Zahler", 0);
|
||||
|
||||
$LastPeak = $this->GetValue("LetzterPeakwert");
|
||||
@@ -120,167 +134,147 @@ class WP_Steuerung extends IPSModule {
|
||||
$state = $this->GetValue("Zustand_WP");
|
||||
|
||||
if ($state == 0) {
|
||||
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||
|
||||
}elseif($state == 1) // Normalbetrieb
|
||||
{
|
||||
if($LastPeak && $power == ($this->ReadPropertyInteger("WP_Leistung"))) {
|
||||
} elseif ($state == 1) {
|
||||
// Normalbetrieb
|
||||
if (
|
||||
$LastPeak &&
|
||||
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||
) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue("CurrentPower", $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"))){
|
||||
} 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(
|
||||
"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"))) {
|
||||
} elseif ($state == 2) {
|
||||
// Sperre
|
||||
if (
|
||||
$LastPeak &&
|
||||
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||
) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue("CurrentPower", $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"))){
|
||||
} 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(
|
||||
"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"))) {
|
||||
} elseif ($state == 3) {
|
||||
// Erhöht
|
||||
if (
|
||||
$LastPeak &&
|
||||
$power == $this->ReadPropertyInteger("WP_Leistung")
|
||||
) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue("CurrentPower", $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"))){
|
||||
} 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(
|
||||
"CurrentPower",
|
||||
$this->ReadPropertyInteger("WP_Leistung")
|
||||
);
|
||||
} elseif ($LastPeak == false && $power == 0) {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
$this->SetValue("CurrentPower", 0);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$this->SetValue("Zustand_WP", 1);
|
||||
}
|
||||
|
||||
$newState = $this->GetValue("Zustand_WP");
|
||||
|
||||
if ($newState == 0) {
|
||||
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||
|
||||
} elseif ($newState == 1) {
|
||||
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||
|
||||
} elseif ($newState == 2) {
|
||||
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), true);
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||
|
||||
} elseif ($newState == 3) {
|
||||
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), true);
|
||||
|
||||
} else {
|
||||
|
||||
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
|
||||
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$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
|
||||
public function GetCurrentData(bool $Peak) {
|
||||
|
||||
public function GetCurrentData(bool $Peak)
|
||||
{
|
||||
// tagessperrzeit berechnen
|
||||
|
||||
|
||||
|
||||
$this->SetValue("LetzterPeakwert", $Peak);
|
||||
|
||||
|
||||
if($this->GetValue("WP_Laufzeit_Zahler")<(20*12)){
|
||||
|
||||
$this->SetValue("PowerSteps", json_encode([$this->GetValue("CurrentPower")]));
|
||||
|
||||
}elseif($this->ReadPropertyBoolean("Schwellwert_Anwenden")==true && ($this->ReadPropertyInteger("Schwellwert")>GetValue($this->ReadPropertyInteger("WW_Temp"))) ){
|
||||
|
||||
|
||||
$this->SetValue("PowerSteps", json_encode([$this->ReadPropertyInteger("WP_Leistung")]));
|
||||
}
|
||||
|
||||
else{
|
||||
|
||||
$this->SetValue("PowerSteps", json_encode([0, $this->ReadPropertyInteger("WP_Leistung")]));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function CheckIdle($power){
|
||||
public function CheckIdle($power)
|
||||
{
|
||||
$lastpower = GetValue($this->GetIDForIdent("CurrentPower"));
|
||||
if ($lastpower != $power) {
|
||||
$this->SetValue("Idle", false);
|
||||
$this->SetValue("IdleCounter", $this->ReadPropertyInteger("IdleCounterMax"));
|
||||
$this->SetValue(
|
||||
"IdleCounter",
|
||||
$this->ReadPropertyInteger("IdleCounterMax")
|
||||
);
|
||||
}
|
||||
// IdleCounter auslesen und verarbeiten
|
||||
$idleCounter = $this->GetValue("IdleCounter");
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"compatibility": {
|
||||
"version": "7.1"
|
||||
},
|
||||
"version": "0.155",
|
||||
"version": "0.156",
|
||||
"build": 0,
|
||||
"date": 0
|
||||
}
|
||||
Reference in New Issue
Block a user