ladestation angepasst

This commit is contained in:
2025-04-28 10:17:30 +02:00
parent ae4410d6bf
commit 67789f9bc4

View File

@@ -16,6 +16,8 @@ class Ladestation_v2 extends IPSModule
$this->RegisterPropertyString("Password", "");
$this->RegisterPropertyInteger("Interval", 5); // Recheninterval
$this->RegisterPropertyInteger("Max_Current_abs", 32); // Recheninterval
$this->RegisterPropertyInteger("Zeit_Zwischen_Zustandswechseln", 1);
// Ladestationspezifische Variabeln
$this->RegisterVariableFloat("Max_Current","Maximaler Ladestrom","", 0);
@@ -36,6 +38,8 @@ class Ladestation_v2 extends IPSModule
$this->RegisterVariableBoolean("Peak", "Peak", "", 0);
IPS_SetHidden($this->GetIDForIdent("Peak"), true);
$this->RegisterVariableBoolean("IsTimerActive", "IsTimerActive", "", false);
$this->RegisterTimer("ZustandswechselTimer",0,"IPS_RequestAction(" .$this->InstanceID .', "ResetTimer", "");');
@@ -133,6 +137,10 @@ class Ladestation_v2 extends IPSModule
case "Ladebereit":
$this->SetValue("Ladebereit", (bool)$Value);
break;
case "ResetTimer":
$this->ResetTimer();
break;
default:
throw new Exception("Invalid Ident");
@@ -159,11 +167,11 @@ class Ladestation_v2 extends IPSModule
else{
if($this->Get_Car_Status($carType)==true){
$this->sendPowerToStation(32);
$this->sendPowerToStation($this->ReadPropertyInteger("Max_Current_abs"));
$counter = $this->GetValue("Pending_Counter");
if($counter>(35/($this->ReadPropertyInteger("Interval")))){
if($counter>(60/($this->ReadPropertyInteger("Interval")))){
$this->SetValue("Pending_Counter", 0);
if($this->GetValue("Ladeleistung_Effektiv")>7500){
@@ -189,7 +197,7 @@ class Ladestation_v2 extends IPSModule
}else{
$this->SetValue("Car_detected", false);
$this->sendPowerToStation(32);
$this->sendPowerToStation($this->ReadPropertyInteger("Max_Current_abs"));
}
}
@@ -197,6 +205,29 @@ class Ladestation_v2 extends IPSModule
}
// Methode zum Setzen der PowerSteps und Timer starten
public function SetTimerOn()
{
// Timer setzen, der nach "Zeit_Zwischen_Zustandswechseln" abläuft
$zeitZwischenZustandswechseln = $this->ReadPropertyInteger("Zeit_Zwischen_Zustandswechseln");
$this->SetTimerInterval("ZustandswechselTimer", $zeitZwischenZustandswechseln * 60000); // Timer in Millisekunden
// Timer-Status auf true setzen
$this->SetValue("IsTimerActive", true);
}
// Methode zum Zurücksetzen von PowerSteps nach Ablauf des Timers
public function ResetTimer()
{
// Timer stoppen
$this->SetTimerInterval("ZustandswechselTimer", 0);
// Timer-Status auf false setzen
$this->SetValue("IsTimerActive", false);
}
public function Get_Car_Status(int $carType)
{
$ch = curl_init();
@@ -343,14 +374,20 @@ class Ladestation_v2 extends IPSModule
public function SetAktuelle_Leistung(int $power)
{
// Hier eine Leistungsänderung detektieren für Idle und interne Mindestlaufzeiten
$this->CheckIdle($power);
if ($this->GetValue("Aktuelle_Leistung") != $power) {
$this->SetTimerOn();
}
$internalPower = GetValue($this->GetIDForIdent("Aktuelle_Leistung"));
// Aktuelle Leistungsvorgabe setzen
SetValue($this->GetIDForIdent("Aktuelle_Leistung"), $power);
if($power <= 0){
$this->SetValue("Pending_Counter", 0);
}
$internalPower = GetValue($this->GetIDForIdent("Aktuelle_Leistung"));
// Aktuelle Leistungsvorgabe setzen
SetValue($this->GetIDForIdent("Aktuelle_Leistung"), $power);
$this->SetValue("Bezogene_Energie", ($this->GetValue("Bezogene_Energie") + ($this->GetValue("Aktuelle_Leistung")*($this->ReadPropertyInteger("Interval")/3600))));
if ($power != $internalPower) {
@@ -397,6 +434,14 @@ class Ladestation_v2 extends IPSModule
// Methode zum Abrufen der aktuellen Daten
public function GetCurrentData(bool $Peak)
{
// Überprüfen, ob der Timer aktiv ist
if ($this->GetValue("IsTimerActive")) {
// Timer ist aktiv, PowerSteps setzen
$this->SetValue("PowerSteps", json_encode([$this->GetValue("Aktuelle_Leistung")]));
return;
}
// Aktuelle Properties abrufen
$ladebereit = GetValue($this->GetIDForIdent("Ladebereit"));
$solarladen = GetValue($this->GetIDForIdent("Solarladen"));
@@ -545,5 +590,24 @@ class Ladestation_v2 extends IPSModule
return "Invalid value. Must be between 0 and 32.";
}
}
public function CheckIdle($power)
{
$lastpower = GetValue($this->GetIDForIdent("Aktuelle_Leistung"));
if ($lastpower != $power) {
$this->SetValue("Idle", false);
$this->SetValue("IdleCounter",$this->ReadPropertyInteger("IdleCounterMax"));
}
// IdleCounter auslesen und verarbeiten
$idleCounter = $this->GetValue("IdleCounter");
if ($idleCounter > 0) {
$this->SetValue("Idle", false);
$this->SetValue("IdleCounter", $idleCounter - 1);
} else {
$this->SetValue("Idle", true);
}
}
}
?>