Ladestation auf neue API umgebaut

This commit is contained in:
2024-10-11 15:23:43 +02:00
parent 3f8b7b712d
commit 424d528870
2 changed files with 10 additions and 5 deletions

View File

@@ -32,6 +32,7 @@ public function Create() {
$this->RegisterVariableBoolean("Solarladen", "Solarladen", "~Switch", 11);
$this->RegisterVariableInteger("Fahrzeugstatus", "Fahrzeugstatus", "", 0);
$this->RegisterVariableInteger("Lademodus", "Lademodus", "", 0);
$this->RegisterVariableFloat("Ladeleistung_Effektiv", "Ladeleistung_Effektiv", "", 0);
@@ -158,7 +159,7 @@ public function GetCurrentData(bool $Peak) {
$ch = curl_init();
// Setze die URL
curl_setopt($ch, CURLOPT_URL, "http://" . $this->ReadPropertyString("IP_Adresse") . "/mqtt?payload=");
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);
@@ -177,6 +178,10 @@ public function GetCurrentData(bool $Peak) {
// Ü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['tpa']);
SetValue($this->GetIDForIdent("Fahrzeugstatus"), $data['car']);
@@ -229,7 +234,7 @@ public function GetCurrentData(bool $Peak) {
public function sendPowerToStation($value) {
// Base URL
$baseUrl = "http://" . $this->ReadPropertyString("IP_Adresse") . "/mqtt?payload=";
$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
@@ -237,7 +242,7 @@ public function sendPowerToStation($value) {
// If value is 0, make a single request
if ($value == 0) {
$url = $baseUrl . "alw=0";
$url = $baseUrl . "frc=1";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
@@ -248,7 +253,7 @@ public function sendPowerToStation($value) {
// For value between 1 and 32, make two requests
else if ($value >= 1 && $value <= 32) {
// First request
$url1 = $baseUrl . "alw=1";
$url1 = $baseUrl . "frc=2";
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response1 = curl_exec($ch);