smart me ladestation integriert

This commit is contained in:
2024-12-19 10:17:31 +01:00
parent 155ce251b0
commit 00341c4dfe
3 changed files with 112 additions and 15 deletions

View File

@@ -62,22 +62,27 @@
"name": "ID",
"caption": "ID",
"suffix": "",
"visible": false,
"visibilityCondition": {
"field": "Ladestation",
"value": 3
}
"visible": true
},
{
"type": "ValidationTextBox",
"name": "Seriennummer",
"caption": "Seriennummer",
"suffix": "",
"visible": false,
"visibilityCondition": {
"field": "Ladestation",
"value": 3
}
}
"visible": true
},
{
"type": "ValidationTextBox",
"name": "Username",
"caption": "Username",
"suffix": "",
"visible": true
},
{ "type": "PasswordTextBox", "name": "Password", "caption": "Passwort" }
]
}

View File

@@ -13,6 +13,10 @@ class Ladestation_Universal extends IPSModule
$this->RegisterPropertyInteger("MaxLeistung_1ph", 7800);
$this->RegisterPropertyString("IP_Adresse", "0.0.0.0");
$this->RegisterPropertyInteger("Ladestation", 2);
$this->RegisterPropertyString("ID", "");
$this->RegisterPropertyString("Seriennummer", "");
$this->RegisterPropertyString("Username", "");
$this->RegisterPropertyString("Password", "");
// Ladestationspezifische Variabeln
@@ -171,6 +175,15 @@ class Ladestation_Universal extends IPSModule
"http://" . $this->ReadPropertyString("IP_Adresse") . "/mqtt?payload="
);
}
elseif($this->ReadPropertyInteger("Ladestation")==3){
curl_setopt(
$ch,
CURLOPT_URL,
"https://api.smart-me.com/pico/charging/". $this->ReadPropertyInteger("ID");
);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $this->ReadPropertyInteger("Username") . ":" . $$this->ReadPropertyInteger("Password"));
}
// Setze die Option, die Antwort als String zurückzugeben
@@ -187,6 +200,7 @@ class Ladestation_Universal extends IPSModule
// Dekodiere die JSON-Antwort
$data = json_decode($response, true);
if($this->ReadPropertyInteger("Ladestation")==2||$this->ReadPropertyInteger("Ladestation")==1){
// Ü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
@@ -205,7 +219,28 @@ class Ladestation_Universal extends IPSModule
}
}
}
if($this->ReadPropertyInteger("Ladestation")==3){
// Überprüfe, ob das JSON-Dekodieren erfolgreich war und der Schlüssel "car" existiert
if (json_last_error() === JSON_ERROR_NONE && isset($data["State"])) {
// Speichere den Wert von "car" in der Variable $status
SetValue(
$this->GetIDForIdent("Ladeleistung_Effektiv"),
round($data["ActiveChargingPower"]*1000)
);
SetValue($this->GetIDForIdent("Fahrzeugstatus"), $data["State"]);
if ($data["ActiveChargingPower"]/$data["MaxAllowedChargingCurrent"] > 0.4 && $data["car"] != 1) {
SetValue($this->GetIDForIdent("Lademodus"), 1);
} elseif ($data["car"] != 1) {
SetValue($this->GetIDForIdent("Lademodus"), 0);
}
}
}
}
// Peak-Wert speichern
$this->SetValue("Peak", $Peak);
@@ -251,7 +286,9 @@ class Ladestation_Universal extends IPSModule
$baseUrl ="http://" . $this->ReadPropertyString("IP_Adresse") . "/api/set?";
}elseif($this->ReadPropertyInteger("Ladestation")==1){
$baseUrl ="http://" . $this->ReadPropertyString("IP_Adresse") . "/mqtt?payload=";
}
}elseif($this->ReadPropertyInteger("Ladestation")==3){
$baseUrl ="https://api.smart-me.com/pico/loadmanagementgroup/current/" . $this->ReadPropertyString("Seriennummer") . "?current=";
}
// Base URL
IPS_LogMessage("Ladestation", "Aufgerufene ip" . $baseUrl);
@@ -266,15 +303,33 @@ class Ladestation_Universal extends IPSModule
if ($value == 0) {
if($this->ReadPropertyInteger("Ladestation")==2){
$url = $baseUrl . "frc=1";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}elseif($this->ReadPropertyInteger("Ladestation")==1){
$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;
}
}elseif($this->ReadPropertyInteger("Ladestation")==3){
$url = $baseUrl . "0";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $this->ReadPropertyInteger("Username") . ":" . $$this->ReadPropertyInteger("Password"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}
// For value between 1 and 32, make two requests
@@ -285,7 +340,9 @@ class Ladestation_Universal extends IPSModule
}elseif($this->ReadPropertyInteger("Ladestation")==1){
$url = $baseUrl . "alw=1";
}
}elseif($this->ReadPropertyInteger("Ladestation")==3){
// Nichts zu tun für Smart-Me station
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response1 = curl_exec($ch);
@@ -301,11 +358,43 @@ class Ladestation_Universal extends IPSModule
if($this->ReadPropertyInteger("Ladestation")==2){
$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];
}elseif($this->ReadPropertyInteger("Ladestation")==1){
$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];
}
elseif($this->ReadPropertyInteger("Ladestation")==3){
$url2 = $baseUrl . $value*1000;
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $this->ReadPropertyInteger("Username") . ":" . $$this->ReadPropertyInteger("Password"));
$response2 = curl_exec($ch);
// Check for errors
@@ -319,6 +408,9 @@ class Ladestation_Universal extends IPSModule
// Return responses
return [$response1, $response2];
}
}
// If value is out of range

View File

@@ -6,7 +6,7 @@
"compatibility": {
"version": "7.1"
},
"version": "0.198",
"version": "0.199",
"build": 0,
"date": 0
}