Easee-Station für normalbetrieb integriert.

This commit is contained in:
2025-08-05 15:00:53 +02:00
parent 1928f0d785
commit 66290c7cf7
2 changed files with 136 additions and 1 deletions

View File

@@ -24,6 +24,10 @@
{
"caption": "Easee - Nur Solarladen",
"value": 5
},
{
"caption": "Easee",
"value": 6
}
]
},

View File

@@ -87,6 +87,7 @@ class Ladestation_v2 extends IPSModule
$this->SetValue("Idle", true);
$this->RegisterTimer("Timer_Do_UserCalc_EVC",$this->ReadPropertyInteger("Interval")*1000,"IPS_RequestAction(" .$this->InstanceID .', "Do_UserCalc", "");');
$this->RegisterTimer("Timer_Refresh_Token",0,"IPS_RequestAction(" .$this->InstanceID .', "Refresh_Token", "");');
}
@@ -95,6 +96,14 @@ class Ladestation_v2 extends IPSModule
parent::ApplyChanges();
$this->SetTimerInterval("Timer_Do_UserCalc_EVC",$this->ReadPropertyInteger("Interval")*1000);
// erstelle einen Timer der das Request token aktualisiert wenn die station dies braucht.
if($carType==6){
$this->Refresh_Token();
$this->SetTimerInterval("Timer_Refresh_Token",1800);
}
// Zusätzliche Anpassungen nach Bedarf
}
@@ -146,6 +155,10 @@ class Ladestation_v2 extends IPSModule
$this->ResetTimer();
break;
case "Refresh_Token":
$this->Refresh_Token();
break;
default:
throw new Exception("Invalid Ident");
}
@@ -399,7 +412,49 @@ class Ladestation_v2 extends IPSModule
}
break;
case 6:
//Aktueller Zustand Ladestation abfragen (Leistung, auto eingesteckt?)
$ch2 = curl_init();
$url2 = "https://api.easee.com/api/chargers/".$this->ReadPropertyString("Seriennummer")."/state";
curl_setopt_array($ch2, [
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer ".$this->GetBuffer("Easee_Token")."",
"content-type: application/*+json"
],
]);
curl_setopt($ch2, CURLOPT_URL, $url2);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
$response_easee = curl_exec($ch2);
curl_close($ch2);
$easee_data = json_decode($response_easee, true);
if (json_last_error() === JSON_ERROR_NONE && isset($easee_data["chargerOpMode"])) {
if ($easee_data["chargerOpMode"] != 1 && (($easee_data["chargerOpMode"] != 6)||($this->GetValue("Car_detected")==true)) && $easee_data["chargerOpMode"] != 7) {
$car_on_station = true;
}
else{
$car_on_station = false;
}
$this->SetValue("Ladeleistung_Effektiv", round($easee_data["totalPower"]*1000));
$this->SetValue("Fahrzeugstatus", $easee_data["chargerOpMode"]);
}
break;
default:
$this->SetValue("Car_detected", false);
$this->SetValue("Fahrzeugstatus", -1);
@@ -598,6 +653,9 @@ class Ladestation_v2 extends IPSModule
case 5:
// Keine base Url nötig
break;
case 6:
// Keine base Url nötig
break;
}
$ch = curl_init();
@@ -639,6 +697,24 @@ class Ladestation_v2 extends IPSModule
],
]);
break;
case 6:
$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\":0}",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer ".$this->GetBuffer("Easee_Token")."",
"content-type: application/*+json"
],
]);
break;
default:
return "Invalid station type.";
}
@@ -670,6 +746,23 @@ class Ladestation_v2 extends IPSModule
if($this->ReadPropertyString("Username") != $this->GetValue("Letzer_User")){
return;
}
$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\":0}",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer ".$this->GetBuffer("Easee_Token")."",
"content-type: application/*+json"
],
]);
break;
case 6:
$url2 = "https://api.easee.com/api/chargers/".$this->ReadPropertyString("Seriennummer")."/commands/set_dynamic_charger_current";
curl_setopt_array($ch, [
CURLOPT_ENCODING => "",
@@ -684,6 +777,7 @@ class Ladestation_v2 extends IPSModule
],
]);
break;
default:
return "Invalid station type.";
}
@@ -711,6 +805,43 @@ class Ladestation_v2 extends IPSModule
}
}
public function Refresh_Token(){
$payload = json_encode([
'userName' => $this->ReadPropertyString("Username"),
'password' => $this->ReadPropertyString("Password"),
]);
// cURL-Handle initialisieren
$ch = curl_init('https://api.easee.com/api/accounts/login');
// cURL-Optionen setzen
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true, // Antwort als String zurückgeben
CURLOPT_POST => true, // POST-Methode verwenden
CURLOPT_HTTPHEADER => [
'Accept: application/json',
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => $payload, // JSON-Body übergeben
]);
// Anfrage ausführen und Antwort speichern
$response = curl_exec($ch);
// Auf Fehler prüfen
if ($response === false) {
echo 'cURL-Fehler: ' . curl_error($ch);
curl_close($ch);
exit;
}
// cURL-Handle schließen
curl_close($ch);
$this->SetBuffer("Easee_Token",json_decode($response, true)['accessToken']);
}
public function CheckIdle($power)
{
$lastpower = GetValue($this->GetIDForIdent("Aktuelle_Leistung"));