Files
Energiemanager_Symconmodule…/WP_Steuerung/module.php
2024-11-08 15:59:25 +01:00

210 lines
7.4 KiB
PHP

<?php
class WP_Steurung extends IPSModule {
public function Create() {
parent::Create();
// Prioritäten
$this->RegisterVariableInteger("LockPrio", "LockPrio");
$this->RegisterVariableInteger("UserPrio", "UserPrio");
// Energiehandling
$this->RegisterVariableBoolean("Idle", "Idle", "", true);
$this->RegisterVariableInteger("CurrentPower", "CurrentPower", "", 0);
$this->RegisterVariableFloat("UsedEnergy", "UsedEnergy", "", 0);
$this->RegisterVariableString("PowerSteps", "PowerSteps"); // PowerSteps-Variable registrieren
// Trägheit
$this->RegisterPropertyInteger("IdleCounterMax", 4);
$this->RegisterVariableInteger("IdleCounter", "IdleCounter", "", 0);
$this->SetValue("IdleCounter", 0);
$this->RegisterVariableInteger("Mindestlaufzeit", "IdleCounter", "", 0);
$this->RegisterVariableInteger("Zustand_WP", "Zustand_WP", "", 0);
$this->RegisterVariableInteger("WP_Laufzeit_Zahler", "WP_Laufzeit_Zahler", "", 20*12);
$this->RegisterVariableBoolean("LetzterPeakwert", "LetzterPeakwert", "", false);
$this->RegisterPropertyInteger("WP_Leistung", 6000);
$this->RegisterPropertyInteger("Wolkenschwellwert", 60);
$this->RegisterPropertyInteger("Wolkenwert", 0);
$this->RegisterPropertyInteger("Aussentemperatur", 0);
$this->RegisterPropertyInteger("Referenzzeit", 0);
$this->RegisterPropertyInteger("Sperrkontakt", 0);
$this->RegisterPropertyInteger("Kontakt_Erhoeung", 0);
//Initialisieren
$this->SetValue("Idle", true);
}
public function ApplyChanges() {
parent::ApplyChanges();
}
// Aktionen verarbeiten
public function RequestAction($Ident, $Value) {
switch ($Ident) {
case "SetCurrentPower":
$this->SetCurrentPower($Value);
break;
case "GetCurrentData":
return $this->GetCurrentData($Value);
break;
case "ResetPowerSteps":
$this->ResetPowerSteps($Value);
break;
default:
throw new Exception("Invalid Ident");
}
}
// Methode zum Setzen des aktuellen Stromverbrauchs
public function SetCurrentPower(float $power) {
$sperrzei_abs = 60*60*(GetValue($this->ReadPropertyInteger("Aussentemperatur"))+10)/25*60;
if($sperrzei_abs>6*60*60){
$sperrzei_abs = 6*60*60;
}
if(GetValue($this->ReadPropertyInteger("Wolkenschwellwert"))<GetValue($this->ReadPropertyInteger("Wolkenwert")) || $sperrzei_abs < 0 ){
$sperrzei_abs = 0;
}
$sperrzeit = GetValue($this->ReadPropertyInteger("Referenzzeit"))%86400 - $sperrzei_abs;
$entsperrzeit = GetValue($this->ReadPropertyInteger("Referenzzeit"))%86400;
$aktuellezeit = time()%86400;
$its_lock_time = false;
if($aktuellezeit > $sperrzeit && $aktuellezeit < $entsperrzeit){
$its_lock_time = true;
}
$timestamp = time();
$this->CheckIdle($power);
if($this->GetValue("CurrentPower")!=$power){
$this->SetValue("WP_Laufzeit_Zahler", 0);
$LastPeak = $this->GetValue("LetzterPeakwert");
$state = $this->GetValue("Zustand_WP");
if($state == 0){
$this->SetValue("Zustand_WP", 1);
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
}elseif($state == 1) // Normalbetrieb
{
if($LastPeak && $power == $this->GetValue("WP_Leistung")) {
$this->SetValue("Zustand_WP", 1);
if($its_lock_time){
$this->SetValue("Zustand_WP", 2);
}
} elseif($LastPeak && $power == 0){
$this->SetValue("Zustand_WP", 2);
}
elseif($LastPeak == false && $power == $this->GetValue("WP_Leistung")){
$this->SetValue("Zustand_WP", 3);
}
elseif($LastPeak == false && $power == 0){
$this->SetValue("Zustand_WP", 1);
if($its_lock_time){
$this->SetValue("Zustand_WP", 2);
}
}
}elseif($state == 2) // Sperre
{
if($LastPeak && $power == $this->GetValue("WP_Leistung")) {
$this->SetValue("Zustand_WP", 1);
if($its_lock_time){
$this->SetValue("Zustand_WP", 2);
}
} elseif($LastPeak && $power == 0){
$this->SetValue("Zustand_WP", 2);
}
elseif($LastPeak == false && $power == $this->GetValue("WP_Leistung")){
$this->SetValue("Zustand_WP", 3);
}
elseif($LastPeak == false && $power == 0){
$this->SetValue("Zustand_WP", 1);
if($its_lock_time){
$this->SetValue("Zustand_WP", 2);
}
}
}elseif($state == 3) // Erhöht
{
if($LastPeak && $power == $this->GetValue("WP_Leistung")) {
$this->SetValue("Zustand_WP", 1);
} elseif($LastPeak && $power == 0){
$this->SetValue("Zustand_WP", 2);
}
elseif($LastPeak == false && $power == $this->GetValue("WP_Leistung")){
$this->SetValue("Zustand_WP", 3);
}
elseif($LastPeak == false && $power == 0){
$this->SetValue("Zustand_WP", 1);
}
}
else{
$this->SetValue("Zustand_WP", 1);
}
$newState = $this->GetValue("Zustand_WP");
if($newState == 0){
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
}elseif($newState == 1){
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
}elseif($newState == 2){
SetValue($this->ReadPropertyInteger("Sperrkontakt"), true);
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
}elseif($newState == 3){
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), true);
}else{
SetValue($this->ReadPropertyInteger("Sperrkontakt"), false);
SetValue($this->ReadPropertyInteger("Kontakt_Erhoeung"), false);
}
}else{
$newCount = $this->GetValue("WP_Laufzeit_Zahler");
$this->SetValue("WP_Laufzeit_Zahler", ($newCount +1));
}
}
}
?>