Initial commit
This commit is contained in:
67
Ladestation_Universal/README.md
Normal file
67
Ladestation_Universal/README.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# Manager_1
|
||||
Beschreibung des Moduls.
|
||||
|
||||
### Inhaltsverzeichnis
|
||||
|
||||
1. [Funktionsumfang](#1-funktionsumfang)
|
||||
2. [Voraussetzungen](#2-voraussetzungen)
|
||||
3. [Software-Installation](#3-software-installation)
|
||||
4. [Einrichten der Instanzen in IP-Symcon](#4-einrichten-der-instanzen-in-ip-symcon)
|
||||
5. [Statusvariablen und Profile](#5-statusvariablen-und-profile)
|
||||
6. [WebFront](#6-webfront)
|
||||
7. [PHP-Befehlsreferenz](#7-php-befehlsreferenz)
|
||||
|
||||
### 1. Funktionsumfang
|
||||
|
||||
*
|
||||
|
||||
### 2. Voraussetzungen
|
||||
|
||||
- IP-Symcon ab Version 7.1
|
||||
|
||||
### 3. Software-Installation
|
||||
|
||||
* Über den Module Store das 'Manager_1'-Modul installieren.
|
||||
* Alternativ über das Module Control folgende URL hinzufügen
|
||||
|
||||
### 4. Einrichten der Instanzen in IP-Symcon
|
||||
|
||||
Unter 'Instanz hinzufügen' kann das 'Manager_1'-Modul mithilfe des Schnellfilters gefunden werden.
|
||||
- Weitere Informationen zum Hinzufügen von Instanzen in der [Dokumentation der Instanzen](https://www.symcon.de/service/dokumentation/konzepte/instanzen/#Instanz_hinzufügen)
|
||||
|
||||
__Konfigurationsseite__:
|
||||
|
||||
Name | Beschreibung
|
||||
-------- | ------------------
|
||||
|
|
||||
|
|
||||
|
||||
### 5. Statusvariablen und Profile
|
||||
|
||||
Die Statusvariablen/Kategorien werden automatisch angelegt. Das Löschen einzelner kann zu Fehlfunktionen führen.
|
||||
|
||||
#### Statusvariablen
|
||||
|
||||
Name | Typ | Beschreibung
|
||||
------ | ------- | ------------
|
||||
| |
|
||||
| |
|
||||
|
||||
#### Profile
|
||||
|
||||
Name | Typ
|
||||
------ | -------
|
||||
|
|
||||
|
|
||||
|
||||
### 6. WebFront
|
||||
|
||||
Die Funktionalität, die das Modul im WebFront bietet.
|
||||
|
||||
### 7. PHP-Befehlsreferenz
|
||||
|
||||
`boolean GEF_BeispielFunktion(integer $InstanzID);`
|
||||
Erklärung der Funktion.
|
||||
|
||||
Beispiel:
|
||||
`GEF_BeispielFunktion(12345);`
|
||||
30
Ladestation_Universal/form.json
Normal file
30
Ladestation_Universal/form.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"elements": [
|
||||
{
|
||||
"type": "ValidationTextBox",
|
||||
"name": "IP_Adresse",
|
||||
"caption": "IP-Adresse Go-E",
|
||||
"suffix": ""
|
||||
},
|
||||
{
|
||||
"type": "NumberSpinner",
|
||||
"name": "MinLeistung",
|
||||
"caption": "Mindestleistung Ladestation"
|
||||
},
|
||||
{
|
||||
"type": "NumberSpinner",
|
||||
"name": "IdleCounterMax",
|
||||
"caption": "Zyklen zwischen zwei Leisutungsänderungen",
|
||||
"suffix": ""
|
||||
},
|
||||
{
|
||||
"type": "NumberSpinner",
|
||||
"name": "MaxLeistung",
|
||||
"caption": "Maximlalleistung Ladestation"
|
||||
},
|
||||
{
|
||||
"type": "Label",
|
||||
"caption": "Aktuell wird nur Go-E ladestation zu testzwecken unterstützt!"
|
||||
}
|
||||
]
|
||||
}
|
||||
8
Ladestation_Universal/locale.json
Normal file
8
Ladestation_Universal/locale.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"translations": {
|
||||
"de": {
|
||||
"Translation 1": "Übersetzung 1",
|
||||
"Translation 2": "Übersetzung 2"
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Ladestation_Universal/module.json
Normal file
12
Ladestation_Universal/module.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"id": "{C684C38F-8C0D-CCE0-4533-11769F314B2D}",
|
||||
"name": "Ladestation_Universal",
|
||||
"type": 3,
|
||||
"vendor": "Belevo AG",
|
||||
"aliases": [],
|
||||
"parentRequirements": [],
|
||||
"childRequirements": [],
|
||||
"implemented": [],
|
||||
"prefix": "GEF",
|
||||
"url": ""
|
||||
}
|
||||
349
Ladestation_Universal/module.php
Normal file
349
Ladestation_Universal/module.php
Normal file
@@ -0,0 +1,349 @@
|
||||
<?php
|
||||
|
||||
class Ladestation_Universal extends IPSModule {
|
||||
|
||||
public function Create() {
|
||||
parent::Create();
|
||||
|
||||
// Prioritäten
|
||||
$this->RegisterVariableInteger("LockPrio", "LockPrio");
|
||||
$this->RegisterVariableInteger("UserPrio", "UserPrio");
|
||||
|
||||
// Energiehandling
|
||||
$this->RegisterVariableBoolean("Idle", "Idle", "", 0);
|
||||
$this->RegisterVariableInteger("CurrentPower", "CurrentPower", "", 0);
|
||||
$this->RegisterVariableFloat("UsedEnergy", "UsedEnergy", "", 0);
|
||||
$this->RegisterVariableString("PowerSteps", "PowerSteps"); // PowerSteps-Variable registrieren
|
||||
|
||||
// Trägheit
|
||||
$this->RegisterPropertyInteger("IdleCounterMax", 2);
|
||||
$this->RegisterVariableInteger("IdleCounter", "IdleCounter", "", 0);
|
||||
$this->SetValue("IdleCounter", 0);
|
||||
|
||||
// Properties registrieren
|
||||
$this->RegisterPropertyInteger("MinLeistung", 3600);
|
||||
$this->RegisterPropertyInteger("MaxLeistung", 11000);
|
||||
$this->RegisterPropertyString("IP_Adresse", "0.0.0.0");
|
||||
|
||||
$this->RegisterVariableBoolean("Ladebereit", "Ladebereit", "~Switch", 11);
|
||||
$this->RegisterVariableBoolean("Solarladen", "Solarladen", "~Switch", 11);
|
||||
$this->RegisterVariableInteger("Fahrzeugstatus", "Fahrzeugstatus", "", 0);
|
||||
|
||||
|
||||
|
||||
$this->RegisterVariableBoolean("Peak", "Peak", "", 0);
|
||||
|
||||
$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) {
|
||||
$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
|
||||
SetValue($this->GetIDForIdent("Idle"), false);
|
||||
SetValue($this->GetIDForIdent("IdleCounter"), $this->ReadPropertyInteger("IdleCounterMax"));
|
||||
} else {
|
||||
// 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"));
|
||||
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);
|
||||
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"));
|
||||
$minLeistung = $this->ReadPropertyInteger("MinLeistung");
|
||||
$maxLeistung = $this->ReadPropertyInteger("MaxLeistung");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
// Setze die URL
|
||||
curl_setopt($ch, CURLOPT_URL, "http://" . $this->ReadPropertyString("IP_Adresse") . "/mqtt?payload=");
|
||||
|
||||
// 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("Fahrzeugstatus"), $data['car']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 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));
|
||||
|
||||
} elseif ($solarladen && $Peak) {
|
||||
$powerSteps = [0];
|
||||
|
||||
} else {
|
||||
$powerSteps += $this->getRangeLimits($minLeistung, $maxLeistung);
|
||||
|
||||
}
|
||||
}
|
||||
// PowerSteps in der RegisterVariable speichern
|
||||
SetValue($this->GetIDForIdent("PowerSteps"), json_encode($powerSteps));
|
||||
|
||||
// Rückgabe der Powersteps
|
||||
return $powerSteps;
|
||||
}
|
||||
|
||||
|
||||
public function sendPowerToStation($value) {
|
||||
// Base URL
|
||||
$baseUrl = "http://" . $this->ReadPropertyString("IP_Adresse") . "/mqtt?payload=";
|
||||
IPS_LogMessage("Ladestation", "Aufgerufene ip" . $baseUrl);
|
||||
$value = $this->convertPowerToCurrent($value);
|
||||
// Initialize a cURL session
|
||||
$ch = curl_init();
|
||||
|
||||
// If value is 0, make a single request
|
||||
if ($value == 0) {
|
||||
$url = $baseUrl . "alw=0";
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $response;
|
||||
}
|
||||
|
||||
// For value between 1 and 32, make two requests
|
||||
else if ($value >= 1 && $value <= 32) {
|
||||
// First request
|
||||
$url1 = $baseUrl . "alw=1";
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
public function getRangeLimits($min, $max) {
|
||||
$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
|
||||
];
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($limits as $limit) {
|
||||
if ($limit >= $min && $limit <= $max) {
|
||||
$result[] = $limit;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user