Auf Stand V2.001 gebracht, Sofarmodul ist jetzt integriert.

This commit is contained in:
2025-06-04 11:42:10 +02:00
parent b7bb55b7fa
commit fa3232c736
10 changed files with 706 additions and 44 deletions

View File

@@ -17,6 +17,8 @@ class Ladestation_v2 extends IPSModule
$this->RegisterPropertyInteger("Interval", 5); // Recheninterval
$this->RegisterPropertyInteger("Max_Current_abs", 32); // Recheninterval
$this->RegisterPropertyInteger("Zeit_Zwischen_Zustandswechseln", 1);
$this->RegisterPropertyInteger("Token_Easee", 0); // Recheninterval
$this->RegisterPropertyInteger("Token_ECarUp", 0); // Recheninterval
// Ladestationspezifische Variabeln
@@ -156,12 +158,18 @@ class Ladestation_v2 extends IPSModule
$this->SetValue("Car_detected", true);
if($this->GetValue("Max_Current")<6){
$this->SetValue("Car_is_full", true);
}
}else{
$this->SetValue("Car_detected", false);
$this->SetValue("Leistung_Delta", 0);
$this->SetValue("Car_is_full", false);
$this->SetValue("IsTimerActive", false);
$this->SetValue("Is_1_ph", false);
$this->SetValue("Aktuelle_Leistung", 0);
$this->SetValue("IdleCounter", 0);
$this->SetValue("Idle", true);
}
}
else{
@@ -197,6 +205,7 @@ class Ladestation_v2 extends IPSModule
}else{
$this->SetValue("Car_detected", false);
$this->SetValue("Leistung_Delta", 0);
$this->sendPowerToStation($this->ReadPropertyInteger("Max_Current_abs"));
}
}
@@ -317,16 +326,53 @@ class Ladestation_v2 extends IPSModule
break;
case 4:
$this->SetValue("Car_detected", true);
$car_on_station = true;
break;
case 5:
echo "Fall 5";
// Benutzer eCarUp abfragen
$authToken = GetValue($this->ReadPropertyInteger("Token_ECarUp"));
$ID = $this->ReadPropertyString("ID");
$apiUrl = 'https://public-api.ecarup.com/v1/station/' . $ID . '/conn'.'ectors/'. $ID . '/active-charging';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'accept: application/json',
'Authorization: Bearer ' . $authToken
]);
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) {
IPS_LogMessage("Ladestation", "Fehler beim Abrufen der eCarUp API-Daten");
return;
}
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
IPS_LogMessage("Ladestation", "Fehler beim Dekodieren der JSON-Antwort");
return;
}
if (isset($data['driverIdentifier']) && ($data['driverIdentifier']==$this->ReadPropertyInteger("Username"))) {
$this->SetValue("Ladeleistung_Effektiv", $this->GetValue("Power"));
$this->SetValue("Fahrzeugstatus", 2);
$car_on_station = true;
} else {
$car_on_station = false;
$this->SetValue("Fahrzeugstatus", 1);
$this->SetValue("Ladeleistung_Effektiv", 0);
}
break;
default:
$this->SetValue("Car_detected", false);
$this->SetValue("Fahrzeugstatus", -1);
$this->SetValue("Car_detected", false);
$this->SetValue("Fahrzeugstatus", -1);
break;
}
@@ -522,6 +568,9 @@ class Ladestation_v2 extends IPSModule
case 4:
// Nichts zu tun für Dummy station
return;
case 5:
// Keine base Url nötig
break;
}
$ch = curl_init();
@@ -545,6 +594,21 @@ class Ladestation_v2 extends IPSModule
case 4:
// Nichts zu tun für Dummy station
return;
case 5:
$url = "https://api.easee.com/api/chargers/".$this->ReadPropertyString("Seriennummer")."/commands/set_dynamic_charger_current";
curl_setopt_array($ch, [
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"amps\":". $value .",\"minutes\":1}",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer ".GetValue($this->ReadPropertyInteger("Token_Easee"))."",
"content-type: application/*+json"
],
]);
default:
return "Invalid station type.";
}
@@ -572,6 +636,21 @@ class Ladestation_v2 extends IPSModule
case 4:
// Nichts zu tun für Dummy station
return;
case 5:
$url2 = "https://api.easee.com/api/chargers/".$this->ReadPropertyString("Seriennummer")."/commands/set_dynamic_charger_current";
curl_setopt_array($ch, [
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"amps\":". $value .",\"minutes\":1}",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer ".GetValue($this->ReadPropertyInteger("Token_Easee"))."",
"content-type: application/*+json"
],
]);
break;
default:
return "Invalid station type.";
}