RegisterPropertyString("Verbraucher_Liste", "[]"); $this->RegisterPropertyInteger("Is_Peak", 0); $this->RegisterPropertyInteger("delta_power", 0); $this->RegisterPropertyInteger("Interval", 5); // Recheninterval // Variabeln für Kommunkation mit Manager $this->RegisterVariableInteger("Sperre_Prio", "Sperre_Prio"); $this->RegisterVariableInteger("PV_Prio", "PV_Prio"); $this->RegisterVariableBoolean("Idle", "Idle", "", 0); $this->RegisterVariableInteger("Aktuelle_Leistung", "Aktuelle_Leistung", "", 0); $this->RegisterVariableFloat("Bezogene_Energie", "Bezogene_Energie", "", 0); $this->RegisterVariableString("PowerSteps", "PowerSteps"); $this->RegisterVariableInteger("Power", "Power"); $this->RegisterVariableBoolean("Is_Peak_Shaving", "Is_Peak_Shaving"); $this->RegisterVariableInteger("Leistung_Delta", "Leistung_Delta", "", 0); // Hilfsvariabeln für Idle zustand $this->RegisterPropertyInteger("IdleCounterMax", 2); $this->RegisterVariableInteger("IdleCounter", "IdleCounter", "", 0); $this->SetValue("IdleCounter", 0); // Initialisiere Idle $this->SetValue("Idle", true); $this->RegisterTimer("Timer_Do_UserCalc_Verb",$this->ReadPropertyInteger("Interval")*1000,"IPS_RequestAction(" .$this->InstanceID .', "Do_UserCalc", "");'); } public function ApplyChanges() { parent::ApplyChanges(); $this->SetTimerInterval("Timer_Do_UserCalc_Verb",$this->ReadPropertyInteger("Interval")*1000); } public function RequestAction($Ident, $Value) { switch ($Ident) { case "SetAktuelle_Leistung": $this->SetValue("Power", (int)$Value); break; case "GetCurrentData": $this->SetValue("Is_Peak_Shaving", (bool)$Value); break; case "Do_UserCalc": $this->SetAktuelle_Leistung($this->GetValue("Power")); $this->GetCurrentData($this->GetValue("Is_Peak_Shaving")); break; default: throw new Exception("Invalid Ident"); } } private function berechneKombinationen(array $verbraucherListe) { $kombinationen = [0]; IPS_LogMessage("externer verb 1", print_r($kombinationen)); foreach ($verbraucherListe as $verbraucher) { if ($verbraucher['Read_Var'] == 1) { IPS_LogMessage("externer verb 2", print_r($kombinationen)); $tempListe = $kombinationen; foreach ($tempListe as &$wert) { $wert += $verbraucher['P_Nenn']; } unset($wert); $kombinationen = array_merge($kombinationen, $tempListe); IPS_LogMessage("externer verb 3", print_r($kombinationen)); } } IPS_LogMessage("externer verb 4", print_r($kombinationen)); sort($kombinationen); IPS_LogMessage("externer verb 5", print_r($kombinationen)); return array_unique($kombinationen); } public function SetAktuelle_Leistung(float $power) { $this->CheckIdle($power); $verbraucherListe = json_decode($this->ReadPropertyString("Verbraucher_Liste"), true); $kombinationen = [];//$this->kombinationenRekursiv($verbraucherListe, $power); foreach ($verbraucherListe as $verbraucher) { $writeVarID = $verbraucher['Write_Var']; $pNenn = $verbraucher['P_Nenn']; $this->SetValue($writeVarID, 4); } $this->SetValue("Leistung_Delta", GetValue($this->ReadPropertyInteger("delta_power"))); } public function GetCurrentData(bool $Peak) { $this->SetValue("Is_Peak_Shaving", $Peak); SetValue($this->ReadPropertyInteger("Is_Peak"), $Peak); $verbraucherListe = json_decode($this->ReadPropertyString("Verbraucher_Liste"), true); $kombinationen = $this->berechneKombinationen($verbraucherListe); $this->SetValue("PowerSteps", json_encode($kombinationen)); } public function CheckIdle($power) { $lastpower = GetValue($this->GetIDForIdent("Aktuelle_Leistung")); if ($lastpower != $power) { $this->SetValue("Idle", false); $this->SetValue("IdleCounter",$this->ReadPropertyInteger("IdleCounterMax")); } $idleCounter = $this->GetValue("IdleCounter"); if ($idleCounter > 0) { $this->SetValue("Idle", false); $this->SetValue("IdleCounter", $idleCounter - 1); } else { $this->SetValue("Idle", true); } } } ?>