Exemplo n.º 1
0
function CreateVariable($Name, $Type, $Value, $Ident = '', $ParentID = 0)
{
    echo "CreateVariable: ( {$Name}, {$Type}, {$Value}, {$Ident}, {$ParentID} ) \n";
    if ('' != $Ident) {
        $VarID = @IPS_GetObjectIDByIdent($Ident, $ParentID);
        if (false !== $VarID) {
            SetVariable($VarID, $Type, $Value);
            return;
        }
    }
    $VarID = @IPS_GetObjectIDByName($Name, $ParentID);
    if (false !== $VarID) {
        $Obj = IPS_GetObject($VarID);
        if (2 == $Obj['ObjectType']) {
            $Var = IPS_GetVariable($VarID);
            if ($Type == $Var['VariableValue']['ValueType']) {
                SetVariable($VarID, $Type, $Value);
                return;
            }
        }
    }
    $VarID = IPS_CreateVariable($Type);
    IPS_SetParent($VarID, $ParentID);
    IPS_SetName($VarID, $Name);
    if ('' != $Ident) {
        IPS_SetIdent($VarID, $Ident);
    }
    SetVariable($VarID, $Type, $Value);
}
Exemplo n.º 2
0
 public function WriteBoolean(string $Pin, boolean $Value)
 {
     if ($Pin == '') {
         throw new Exception('Pin is not Set!');
     }
     if (!in_array($Pin, $this->DPin_Name)) {
         throw new Exception('Pin not exists!');
     }
     $VarID = @$this->GetIDForIdent($Pin);
     if ($VarID === false) {
         throw new Exception('Pin not exists! Try WriteParameter.');
     }
     if (IPS_GetVariable($VarID)['VariableType'] !== 0) {
         throw new Exception('Wrong Datatype for ' . $VarID);
     }
     if ($Value === true) {
         $ValueStr = 0x5;
     } else {
         $ValueStr = 0x4;
     }
     $ATData = new TXB_Command_Data();
     $ATData->ATCommand = $Pin;
     $ATData->Data = chr($ValueStr);
     /*        $ResponseATData = $this->SendCommand($ATData);
               if ($ResponseATData->Status <> TXB_Command_Status::XB_Command_OK)
               throw new Exception('Error on Send Command ' . $VarID); */
     $this->SendCommand($ATData);
     if ($this->ReadPropertyBoolean('EmulateStatus')) {
         SetValue($VarID, $Value);
     }
     return true;
 }
	function get_MaxValueByControlId($ControlId) {
		$VariableObject = IPS_GetVariable($ControlId);
		$ProfileName = $VariableObject['VariableCustomProfile'];
		$ProfileObject = IPS_GetVariableProfile($ProfileName);
		$MaxValue = Count($ProfileObject['Associations']);
		return $MaxValue;
	}
Exemplo n.º 4
0
 private function processChilds($childCategory, $state)
 {
     $childs = IPS_GetChildrenIDs($childCategory);
     foreach ($childs as $child) {
         $link = @IPS_GetLink($child);
         if ($link) {
             $variableID = $link["TargetID"];
             $variableObject = IPS_GetObject($variableID);
             $variable = IPS_GetVariable($variableID);
             $ipsValue = $state;
             // request associated action for the specified variable and value
             if ($variable["VariableCustomAction"] > 0) {
                 IPS_RunScriptEx($variable["VariableCustomAction"], array("VARIABLE" => $variableID, "VALUE" => $ipsValue));
             } else {
                 IPS_RequestAction($variableObject["ParentID"], $variableObject["ObjectIdent"], $ipsValue);
             }
         }
     }
 }
Exemplo n.º 5
0
 $DeviceHidden = true;
 foreach ($Childs as $Var) {
     $Obj = IPS_GetObject($Var);
     if (array_key_exists($Obj['ObjectIdent'], $Mapping)) {
         $Name = sprintf($Mapping[$Obj['ObjectIdent']]['Name Raum'], utf8_decode((string) $Channel['Name']), utf8_decode((string) $Channel->Room[0]['Name']));
         //				    $Name = 		$NameMappingRoom[$Obj['ObjectIdent']];
         IPS_SetName($Var, $Name);
         // Profil ändern, wenn nicht leer im Mapping
         if ($Mapping[$Obj['ObjectIdent']]['Profil'] != '') {
             if (!@IPS_SetVariableCustomProfile($Var, $Mapping[$Obj['ObjectIdent']]['Profil'])) {
                 echo "Fehler bei Gerät mit der Addresse " . (string) $Channel['Address'] . " und Datenpunkt " . $Obj['ObjectIdent'] . PHP_EOL;
                 echo "  Profil '" . $Mapping[$Obj['ObjectIdent']]['Profil'] . "' konnte nicht zugewiesen werden." . PHP_EOL;
                 echo "--------------------------------------------------------------------" . PHP_EOL;
             }
         }
         if (IPS_GetVariable($Var)['VariableAction'] > 0) {
             // Standardaktion möglich
             if ($Mapping[$Obj['ObjectIdent']]['Action'] === true) {
                 IPS_SetVariableCustomAction($Var, 0);
             } elseif ($Mapping[$Obj['ObjectIdent']]['Action'] === false) {
                 IPS_SetVariableCustomAction($Var, 1);
             }
         } else {
             if ($Mapping[$Obj['ObjectIdent']]['Action'] === true) {
                 echo "Gerät mit der Addresse " . (string) $Channel['Address'] . " hat keine Standardaktion," . PHP_EOL;
                 echo "  für den Datenpunkt " . $Obj['ObjectIdent'] . " des Gerätes mit Namen '" . utf8_decode((string) $Channel['Name']) . "'." . PHP_EOL;
                 echo "--------------------------------------------------------------------" . PHP_EOL;
             }
         }
         if (is_string($Mapping[$Obj['ObjectIdent']]['Action'])) {
             IPS_SetVariableCustomAction($Var, GetOrCreateScript($ScriptCat, $Mapping[$Obj['ObjectIdent']]['Action']));
 /**
  * constructor
  *
  * first constructor: used to bind an existing device variable to the power meter. 
  * e.g. the 'POWER' variable for HomeMatic HM-ES-PMSw1-Pl, there is no need to create a new variable, but
  * it's necessary to enable logging for it and provide a interface for that variable
  *
  * @param integer $instanceId instance id of the variable
  * @param IPSVariableProfile $profile variable profile for this variable
  * @param boolean $enableLogging enables or disables the ips functionality to log variable changes in a database
  * @param integer $archiveId instance id of the archive control (usually located in IPS\core)
  * @param boolean $debug enables / disables debug information
  *
  * @throws Exception if the parameter \$profile is not an IPSVariableProfile datatype
  * @access public
  */
 private function __construct1($instanceId, $profile = NULL, $enableLogging = false, $archiveId = NULL, $debug = false)
 {
     if (isset($profile) && !$profile instanceof IPSVariableProfile) {
         throw new Exception("Parameter \$profile must be an instance of IPSVariableProfile!");
     }
     //if($debug) echo "Parameter \$enableLogging = $enableLogging\n";
     $obj = @IPS_GetObject($instanceId);
     if ($obj == NULL) {
         throw new Exception("Object with id '{$instanceId}' does not exist");
     }
     $this->id = $instanceId;
     $this->name = $obj["ObjectName"];
     $this->parent = $obj["ParentID"];
     $this->aggregationType = 0;
     $var = IPS_GetVariable($this->id);
     if ($profile->getName() != $var["VariableProfile"]) {
         IPS_SetVariableCustomProfile($this->id, $profile->getName());
         IPS_SetInfo($this->id, "this variable was edited by script " . $_IPS['SELF'] . " - variable profile was set to '" . $profile->getName() . "'");
     }
     $this->profile = $profile;
     $this->enableLogging = $enableLogging;
     $this->archiveId = $archiveId;
     $this->debug = $debug;
     $this->verifyVariableLogging();
 }
Exemplo n.º 7
0
 /**
  * Startet den Timer bis zum Alarm
  *
  * @access private
  */
 private function StartTimer()
 {
     if (IPS_GetKernelRunlevel() != KR_READY) {
         return;
     }
     $this->ActiveVarID = 0;
     $NowTime = time();
     $LastTime = $NowTime + 98765;
     //init wert damit lasttime immer größer als aktuelle zeit
     $TriggerVarList = $this->NoTriggerVarList;
     foreach ($TriggerVarList->Items as $i => $IPSVars) {
         if (!IPS_VariableExists($IPSVars->VarId)) {
             continue;
         }
         if ($IPSVars->Alert === true) {
             continue;
         }
         $Variable = IPS_GetVariable($IPSVars->VarId);
         $TestTime = $Variable['VariableUpdated'];
         if ($TestTime + $this->ReadPropertyInteger('Timer') < $NowTime) {
             $TriggerVarList->Items[$i]->Alert = true;
             $this->Alerts++;
             if ($this->Alerts == 1) {
                 $this->SetStateVar(true, $IPSVars->VarId);
                 $this->DoScript($IPSVars->VarId, true, false);
             } else {
                 if ($this->ReadPropertyBoolean('MultipleAlert')) {
                     $this->DoScript($IPSVars->VarId, true, false);
                 }
             }
             continue;
         } else {
             if ($TestTime < $LastTime) {
                 $LastTime = $TestTime;
                 $this->ActiveVarID = $IPSVars->VarId;
             }
         }
     }
     $this->NoTriggerVarList = $TriggerVarList;
     if ($this->ActiveVarID == 0) {
         IPS_LogMessage('NoTrigger', 'Keine Var mehr in Ruhe. Überwachung pausiert');
         $this->StopTimer();
     } else {
         $TargetTime = $LastTime + $this->ReadPropertyInteger('Timer');
         $DiffTime = $TargetTime - $NowTime;
         $this->SetTimerInterval('NoTrigger', $DiffTime * 1000);
     }
 }
 /**
  * Timer Event to reinitialize system
  * Executed if there are no valid data within Timer as indicated by LastUpdate
  */
 public function ReInitEvent()
 {
     $id = @$this->GetIDForIdent('LastUpdate');
     if (!$id) {
         return;
     }
     $var = IPS_GetVariable($id);
     if (!$var) {
         return;
     }
     $last = $var['VariableUpdated'];
     //if (!$last) $last=0;
     $now = time();
     $diff = $now - $last;
     $this->debug(__FUNCTION__, "last update {$diff} s ago");
     if ($diff > self::MAXAGE && $this->isActive() && $this->HasActiveParent()) {
         $this->init();
     }
 }
Exemplo n.º 9
0
 protected function GetVariable($Ident, $VarType, $VarName, $Profile, $EnableAction)
 {
     $VarID = @$this->GetIDForIdent($Ident);
     if ($VarID > 0) {
         if (IPS_GetVariable($VarID)['VariableType'] != $VarType) {
             IPS_DeleteVariable($VarID);
             $VarID = false;
         }
     }
     if ($VarID === false) {
         $this->MaintainVariable($Ident, $VarName, $VarType, $Profile, 0, true);
         if ($EnableAction) {
             $this->MaintainAction($Ident, true);
         }
         $VarID = $this->GetIDForIdent($Ident);
     }
     return $VarID;
 }
Exemplo n.º 10
0
 /**
  * RegisterVariableByParent
  * @param integer $ParentID
  * @param string $Ident
  * @param string $Name
  * @param integer $Type
  * @param string $Profile
  * @param integer $Position
  * @return integer
  */
 private function RegisterVariableByParent($ParentID, $Ident, $Name, $Type, $Profile = "", $Position = 0)
 {
     if ($Profile !== "") {
         //prefer system profiles
         if (IPS_VariableProfileExists("~" . $Profile)) {
             $Profile = "~" . $Profile;
         }
         if (!IPS_VariableProfileExists($Profile)) {
             throw new Exception("Profile with name " . $Profile . " does not exist");
         }
     }
     //search for already available variables with proper ident
     $vid = @IPS_GetObjectIDByIdent($Ident, $ParentID);
     //properly update variableID
     if ($vid === false) {
         $vid = 0;
     }
     //we have a variable with the proper ident. check if it fits
     if ($vid > 0) {
         //check if we really have a variable
         if (!IPS_VariableExists($vid)) {
             throw new Exception("Ident with name " . $Ident . " is used for wrong object type");
         }
         //bail out
         //check for type mismatch
         if (IPS_GetVariable($vid)["VariableType"] != $Type) {
             //mismatch detected. delete this one. we will create a new below
             IPS_DeleteVariable($vid);
             //this will ensure, that a new one is created
             $vid = 0;
         }
     }
     //we need to create one
     if ($vid === 0) {
         $vid = IPS_CreateVariable($Type);
         //configure it
         IPS_SetParent($vid, $ParentID);
         IPS_SetIdent($vid, $Ident);
         IPS_SetName($vid, $Name);
         IPS_SetPosition($vid, $Position);
         //IPS_SetReadOnly($vid, true);
     }
     //update variable profile. profiles may be changed in module development.
     //this update does not affect any custom profile choices
     IPS_SetVariableCustomProfile($vid, $Profile);
     return $vid;
 }
Exemplo n.º 11
0
 /**
  * Startet den Timer bis zum Alarm
  *
  * @access private
  */
 private function StartTimer()
 {
     if (IPS_GetKernelRunlevel() != KR_READY) {
         return;
     }
     $NowTime = time();
     if (!IPS_VariableExists($this->ReadPropertyInteger('VarID'))) {
         IPS_SetProperty($this->InstanceID, 'VarID', 0);
         IPS_ApplyChanges($this->InstanceID);
         return;
     }
     $Variable = IPS_GetVariable($this->ReadPropertyInteger('VarID'));
     $LastTime = $Variable['VariableUpdated'];
     $TargetTime = $LastTime + $this->ReadPropertyInteger('Timer');
     $DiffTime = $TargetTime - $NowTime;
     if ($TargetTime < $NowTime) {
         $this->SetStateVar(true);
         $this->DoScript($this->ReadPropertyInteger('VarID'), true, $this->State);
         $this->State = true;
         if ($this->ReadPropertyBoolean('MultipleAlert') == false) {
             $this->StopTimer();
         } else {
             $this->SetTimerInterval('NoTrigger', $this->ReadPropertyInteger('Timer') * 1000);
         }
         // neuer Timer mit max. Zeit, ohne now zu berücksichtigen.
     } else {
         $this->SetStateVar(false);
         if ($this->State) {
             $this->DoScript($this->ReadPropertyInteger('VarID'), false, $this->State);
             $this->State = false;
         }
         $this->SetTimerInterval('NoTrigger', $DiffTime * 1000);
     }
 }
Exemplo n.º 12
0
 private function ReadBatteryStates()
 {
     $InstanzIDsListAll[] = IPS_GetInstanceListByModuleID("{A89F8DFA-A439-4BF1-B7CB-43D047208DDD}");
     // FHT
     $InstanzIDsListAll[] = IPS_GetInstanceListByModuleID("{2FD7576A-D2AD-47EE-9779-A502F23CABB3}");
     // FS20 HMS
     $InstanzIDsListAll[] = IPS_GetInstanceListByModuleID("{EE4A81C6-5C90-4DB7-AD2F-F6BBD521412E}");
     // HomeMatic
     $InstanzIDsListAll[] = IPS_GetInstanceListByModuleID("{101352E1-88C7-4F16-998B-E20D50779AF6}");
     // Z-Wave
     $a = 0;
     $l = 0;
     foreach ($InstanzIDsListAll as $InstanzIDsList) {
         foreach ($InstanzIDsList as $InstanzID) {
             $InstanzHersteller = IPS_GetInstance($InstanzID);
             $InstanzHersteller = $InstanzHersteller["ModuleInfo"]["ModuleName"];
             switch ($InstanzHersteller) {
                 case "FHT":
                     $InstanzHersteller = "FHT";
                     break;
                 case "HMS":
                     $InstanzHersteller = "HMS";
                     break;
                 case "HomeMatic Device":
                     $InstanzHersteller = "HomeMatic";
                     break;
                 case "Z-Wave Module":
                     $InstanzHersteller = "Z-Wave";
                     break;
             }
             //FHT
             $VarID = @IPS_GetObjectIDByIdent('LowBatteryVar', $InstanzID);
             if ($VarID !== false and $InstanzHersteller == "FHT") {
                 $Var = IPS_GetVariable($VarID);
                 $VarLastUpdated = $Var["VariableUpdated"];
                 $VarLastUpdatedDiffSek = time() - $VarLastUpdated;
                 $DeviceID = IPS_GetProperty($InstanzID, "Address");
                 $LowBat = GetValueBoolean($VarID);
                 if ($LowBat === true) {
                     $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID));
                     if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     $Batterien_AR["Alle"][$a]["Batterie"] = "LEER";
                     $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller;
                     $Batterien_AR["Alle"][$a]["ID"] = $DeviceID;
                     $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek;
                     $Batterien_AR["Leer"][$l]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID));
                     if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB"));
                         $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB"));
                         $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB"));
                         $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     $Batterien_AR["Leer"][$l]["Batterie"] = "LEER";
                     $Batterien_AR["Leer"][$l]["Hersteller"] = $InstanzHersteller;
                     $Batterien_AR["Leer"][$l]["ID"] = $DeviceID;
                     $Batterien_AR["Leer"][$l]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID;
                     $Batterien_AR["Leer"][$l]["LetztesVarUpdateTimestamp"] = $VarLastUpdated;
                     $Batterien_AR["Leer"][$l]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek;
                     $a++;
                     $l++;
                 } else {
                     $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID));
                     if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     $Batterien_AR["Alle"][$a]["Batterie"] = "OK";
                     $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller;
                     $Batterien_AR["Alle"][$a]["ID"] = $DeviceID;
                     $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek;
                     $a++;
                 }
             }
             //FS20 HMS
             $VarID = @IPS_GetObjectIDByIdent('LowBatteryVar', $InstanzID);
             if ($VarID !== false and $InstanzHersteller == "HMS") {
                 $Var = IPS_GetVariable($VarID);
                 $VarLastUpdated = $Var["VariableUpdated"];
                 $VarLastUpdatedDiffSek = time() - $VarLastUpdated;
                 $DeviceID = IPS_GetProperty($InstanzID, "DeviceID");
                 $LowBat = GetValueBoolean($VarID);
                 if ($LowBat === true) {
                     $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID));
                     if ($this->ReadPropertyBoolean("NamenParentObjekt") == true) {
                         if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                             $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID);
                             $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB"));
                             $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                         }
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     $Batterien_AR["Alle"][$a]["Batterie"] = "LEER";
                     $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller;
                     $Batterien_AR["Alle"][$a]["ID"] = $DeviceID;
                     $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek;
                     $Batterien_AR["Leer"][$l]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID));
                     if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB"));
                         $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB"));
                         $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB"));
                         $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     $Batterien_AR["Leer"][$l]["Batterie"] = "LEER";
                     $Batterien_AR["Leer"][$l]["Hersteller"] = $InstanzHersteller;
                     $Batterien_AR["Leer"][$l]["ID"] = $DeviceID;
                     $Batterien_AR["Leer"][$l]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID;
                     $Batterien_AR["Leer"][$l]["LetztesVarUpdateTimestamp"] = $VarLastUpdated;
                     $Batterien_AR["Leer"][$l]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek;
                     $a++;
                     $l++;
                 } else {
                     $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID));
                     if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     $Batterien_AR["Alle"][$a]["Batterie"] = "OK";
                     $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller;
                     $Batterien_AR["Alle"][$a]["ID"] = $DeviceID;
                     $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek;
                     $a++;
                 }
             }
             //HomeMatic
             $VarID = @IPS_GetObjectIDByIdent('LOWBAT', $InstanzID);
             if ($VarID !== false and $InstanzHersteller == "HomeMatic") {
                 $Var = IPS_GetVariable($VarID);
                 $VarLastUpdated = $Var["VariableUpdated"];
                 $VarLastUpdatedDiffSek = time() - $VarLastUpdated;
                 $DeviceID = substr(IPS_GetProperty($InstanzID, "Address"), 0, -2);
                 $LowBat = GetValueBoolean($VarID);
                 if ($LowBat === true) {
                     $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID));
                     if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     $Batterien_AR["Alle"][$a]["Batterie"] = "LEER";
                     $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller;
                     $Batterien_AR["Alle"][$a]["ID"] = $DeviceID;
                     $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek;
                     $Batterien_AR["Leer"][$l]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID));
                     if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB"));
                         $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB"));
                         $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB"));
                         $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     $Batterien_AR["Leer"][$l]["Batterie"] = "LEER";
                     $Batterien_AR["Leer"][$l]["Hersteller"] = $InstanzHersteller;
                     $Batterien_AR["Leer"][$l]["ID"] = $DeviceID;
                     $Batterien_AR["Leer"][$l]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID;
                     $Batterien_AR["Leer"][$l]["LetztesVarUpdateTimestamp"] = $VarLastUpdated;
                     $Batterien_AR["Leer"][$l]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek;
                     $a++;
                     $l++;
                 } else {
                     $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID));
                     if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     $Batterien_AR["Alle"][$a]["Batterie"] = "OK";
                     $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller;
                     $Batterien_AR["Alle"][$a]["ID"] = $DeviceID;
                     $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek;
                     $a++;
                 }
             }
             //Z-Wave
             $VarID = @IPS_GetObjectIDByIdent('BatteryLowVariable', $InstanzID);
             if ($VarID !== false and $InstanzHersteller == "Z-Wave") {
                 $Var = IPS_GetVariable($VarID);
                 $VarLastUpdated = $Var["VariableUpdated"];
                 $VarLastUpdatedDiffSek = time() - $VarLastUpdated;
                 $DeviceID = IPS_GetProperty($InstanzID, "NodeID");
                 $LowBat = GetValueBoolean($VarID);
                 if ($LowBat === true) {
                     $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID));
                     if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     $Batterien_AR["Alle"][$a]["Batterie"] = "LEER";
                     $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller;
                     $Batterien_AR["Alle"][$a]["ID"] = $DeviceID;
                     $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek;
                     $Batterien_AR["Leer"][$l]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID));
                     if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB"));
                         $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB"));
                         $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle3TB"));
                         $Batterien_AR["Leer"][$l][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     $Batterien_AR["Leer"][$l]["Batterie"] = "LEER";
                     $Batterien_AR["Leer"][$l]["Hersteller"] = $InstanzHersteller;
                     $Batterien_AR["Leer"][$l]["ID"] = $DeviceID;
                     $Batterien_AR["Leer"][$l]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID;
                     $Batterien_AR["Leer"][$l]["LetztesVarUpdateTimestamp"] = $VarLastUpdated;
                     $Batterien_AR["Leer"][$l]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek;
                     $a++;
                     $l++;
                 } else {
                     $Batterien_AR["Alle"][$a]["Name"] = $this->Umlaute_Ersetzen(IPS_GetName($InstanzID));
                     if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr1NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle1TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr2NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabelle2TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                         $ParentID = $this->ParentIDermitteln("ParentNr3NS", $InstanzID);
                         $ParentNameTabelle = $this->Umlaute_Ersetzen($this->ReadPropertyString("NameParentTabell3TB"));
                         $Batterien_AR["Alle"][$a][$ParentNameTabelle] = $this->Umlaute_Ersetzen(IPS_GetName($ParentID));
                     }
                     $Batterien_AR["Alle"][$a]["Batterie"] = "OK";
                     $Batterien_AR["Alle"][$a]["Hersteller"] = $InstanzHersteller;
                     $Batterien_AR["Alle"][$a]["ID"] = $DeviceID;
                     $Batterien_AR["Alle"][$a]["Hersteller_ID"] = $InstanzHersteller . " - " . $DeviceID;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateTimestamp"] = $VarLastUpdated;
                     $Batterien_AR["Alle"][$a]["LetztesVarUpdateVorSek"] = $VarLastUpdatedDiffSek;
                     $a++;
                 }
             }
         }
     }
     if (isset($Batterien_AR)) {
         //Array sortieren, doppelte Einträge entfernen und neu durchnummerieren
         foreach ($Batterien_AR["Alle"] as $nr => $inhalt) {
             $nameALLE[$nr] = strtolower($inhalt["Name"]);
             if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                 $nameParent1ALLE[$nr] = $this->Umlaute_Ersetzen(strtolower($inhalt[$this->ReadPropertyString("NameParentTabelle1TB")]));
             }
             if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                 $nameParent2ALLE[$nr] = $this->Umlaute_Ersetzen(strtolower($inhalt[$this->ReadPropertyString("NameParentTabelle2TB")]));
             }
             if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                 $nameParent3ALLE[$nr] = $this->Umlaute_Ersetzen(strtolower($inhalt[$this->ReadPropertyString("NameParentTabelle3TB")]));
             }
             $batterieALLE[$nr] = strtolower($inhalt["Batterie"]);
             $herstellerALLE[$nr] = strtolower($inhalt["Hersteller"]);
             $idALLE[$nr] = strtolower($inhalt["ID"]);
             $herstelleridALLE[$nr] = strtolower($inhalt["Hersteller_ID"]);
             $lastupdatetsALLE[$nr] = strtolower($inhalt["LetztesVarUpdateTimestamp"]);
             $lastupdatevsALLE[$nr] = strtolower($inhalt["LetztesVarUpdateVorSek"]);
         }
         //Nach was soll das Array sortiert werden?
         if ($this->ReadPropertyString("ArraySortierWert") == "name") {
             array_multisort($nameALLE, SORT_ASC, $Batterien_AR["Alle"]);
         } elseif ($this->ReadPropertyString("ArraySortierWert") == "parentname1") {
             if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                 array_multisort($nameParent1ALLE, SORT_ASC, $Batterien_AR["Alle"]);
             } else {
                 array_multisort($nameALLE, SORT_ASC, $Batterien_AR["Alle"]);
             }
         } elseif ($this->ReadPropertyString("ArraySortierWert") == "parentname2") {
             if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                 array_multisort($nameParent2ALLE, SORT_ASC, $Batterien_AR["Alle"]);
             } else {
                 array_multisort($nameALLE, SORT_ASC, $Batterien_AR["Alle"]);
             }
         } elseif ($this->ReadPropertyString("ArraySortierWert") == "parentname3") {
             if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                 array_multisort($nameParent3ALLE, SORT_ASC, $Batterien_AR["Alle"]);
             } else {
                 array_multisort($nameALLE, SORT_ASC, $Batterien_AR["Alle"]);
             }
         } elseif ($this->ReadPropertyString("ArraySortierWert") == "batterie") {
             array_multisort($batterieALLE, SORT_ASC, $Batterien_AR["Alle"]);
         } elseif ($this->ReadPropertyString("ArraySortierWert") == "hersteller") {
             array_multisort($herstellerALLE, SORT_ASC, $Batterien_AR["Alle"]);
         } elseif ($this->ReadPropertyString("ArraySortierWert") == "id") {
             array_multisort($idALLE, SORT_ASC, $Batterien_AR["Alle"]);
         } elseif ($this->ReadPropertyString("ArraySortierWert") == "letztesupdts") {
             array_multisort($lastupdatetsALLE, SORT_ASC, $Batterien_AR["Alle"]);
         }
         $Batterien_AR["Alle"] = $this->Array_UniqueBySubitem_Sort($Batterien_AR["Alle"], "Hersteller_ID");
         $Batterien_AR["Alle"] = array_merge($Batterien_AR["Alle"]);
         if (isset($Batterien_AR["Leer"])) {
             foreach ($Batterien_AR["Leer"] as $nr => $inhalt) {
                 $nameLEER[$nr] = strtolower($inhalt["Name"]);
                 if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                     $nameParent1LEER[$nr] = $this->Umlaute_Ersetzen(strtolower($inhalt[$this->ReadPropertyString("NameParentTabelle1TB")]));
                 }
                 if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                     $nameParent2LEER[$nr] = $this->Umlaute_Ersetzen(strtolower($inhalt[$this->ReadPropertyString("NameParentTabelle2TB")]));
                 }
                 if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                     $nameParent3LEER[$nr] = $this->Umlaute_Ersetzen(strtolower($inhalt[$this->ReadPropertyString("NameParentTabelle3TB")]));
                 }
                 $batterieLEER[$nr] = strtolower($inhalt["Batterie"]);
                 $herstellerLEER[$nr] = strtolower($inhalt["Hersteller"]);
                 $idLEER[$nr] = strtolower($inhalt["ID"]);
                 $herstelleridLEER[$nr] = strtolower($inhalt["Hersteller_ID"]);
                 $lastupdatetsLEER[$nr] = strtolower($inhalt["LetztesVarUpdateTimestamp"]);
                 $lastupdatevsLEER[$nr] = strtolower($inhalt["LetztesVarUpdateVorSek"]);
             }
             //Nach was soll das Array sortiert werden?
             if ($this->ReadPropertyString("ArraySortierWert") == "name") {
                 array_multisort($nameLEER, SORT_ASC, $Batterien_AR["Leer"]);
             } elseif ($this->ReadPropertyString("ArraySortierWert") == "parentname1") {
                 if ($this->ReadPropertyBoolean("NamenParentObjekt1CB") == true) {
                     array_multisort($nameParent1LEER, SORT_ASC, $Batterien_AR["Leer"]);
                 } else {
                     array_multisort($nameLEER, SORT_ASC, $Batterien_AR["Leer"]);
                 }
             } elseif ($this->ReadPropertyString("ArraySortierWert") == "parentname2") {
                 if ($this->ReadPropertyBoolean("NamenParentObjekt2CB") == true) {
                     array_multisort($nameParent2LEER, SORT_ASC, $Batterien_AR["Leer"]);
                 } else {
                     array_multisort($nameLEER, SORT_ASC, $Batterien_AR["Leer"]);
                 }
             } elseif ($this->ReadPropertyString("ArraySortierWert") == "parentname3") {
                 if ($this->ReadPropertyBoolean("NamenParentObjekt3CB") == true) {
                     array_multisort($nameParent3LEER, SORT_ASC, $Batterien_AR["Leer"]);
                 } else {
                     array_multisort($nameLEER, SORT_ASC, $Batterien_AR["Leer"]);
                 }
             } elseif ($this->ReadPropertyString("ArraySortierWert") == "batterie") {
                 array_multisort($batterieLEER, SORT_ASC, $Batterien_AR["Leer"]);
             } elseif ($this->ReadPropertyString("ArraySortierWert") == "hersteller") {
                 array_multisort($herstellerLEER, SORT_ASC, $Batterien_AR["Leer"]);
             } elseif ($this->ReadPropertyString("ArraySortierWert") == "id") {
                 array_multisort($idLEER, SORT_ASC, $Batterien_AR["Leer"]);
             } elseif ($this->ReadPropertyString("ArraySortierWert") == "letztesupdts") {
                 array_multisort($lastupdatetsLEER, SORT_ASC, $Batterien_AR["Leer"]);
             }
             $Batterien_AR["Leer"] = $this->Array_UniqueBySubitem_Sort($Batterien_AR["Leer"], "Hersteller_ID");
             $Batterien_AR["Leer"] = array_merge($Batterien_AR["Leer"]);
         }
         return $Batterien_AR;
     } else {
         return false;
     }
 }
 /**
  * parses an record string
  * 
  * @param $data string
  * @param $status string
  * @return array
  */
 private function Parse($data, $status)
 {
     /**
      * @par Status
      * @code
      * #----Status (te923con -s -i '')
      * 0x29 :0x17 :0x14 :0x10 :0x26 :1   :1   :1   :1   :1   :1   :1   :1
      * SYSSW:BARSW:EXTSW:RCCSW:WINSW:BATR:BATU:BATW:BAT5:BAT4:BAT5:BAT2:BAT1
      * @endcode
      * - SYSSW  - software version of system controller
      * - BARSW  - software version of barometer
      * - EXTSW  - software version of UV and channel controller
      * - RCCSW  - software version of rain controller
      * - WINSW  - software version of wind controller
      * - BATR   - battery of rain sensor (1-good (not present), 0-low)
      * - BATU   - battery of UV sensor (1-good (not present), 0-low)
      * - BATW   - battery of wind sensor (1-good (not present), 0-low)
      * - BAT5   - battery of sensor 5 (1-good (not present), 0-low)
      * - BAT4   - battery of sensor 4 (1-good (not present), 0-low)
      * - BAT3   - battery of sensor 3 (1-good (not present), 0-low)
      * - BAT2   - battery of sensor 2 (1-good (not present), 0-low)
      * - BAT1   - battery of sensor 1 (1-good (not present), 0-low)
      *
      * @par Data
      * @code
      * #------Data (te923con -i 'i')
      *
      * 1356207784:22.95:41:7.70:91:8.00:83:i :i :i :i :i :i :1001.9:i :3 :0    :9 :0.1:0.0:7.2:356
      * T0   :H0:T1  :H1:T2  :H2:T3:H3:T4:H4:T5:H5:PRESS :UV:FC:STORM:WD:WS :WG :WC :RC
      * @endcode
      * -  T0    - temperature from internal sensor in °C
      * -  H0    - humidity from internal sensor in % rel
      * -  T1..5 - temperature from external sensor 1..4 in °C
      * -  H1..5 - humidity from external sensor 1...4 in % rel
      * -  PRESS - air pressure in mBar
      * -  UV    - UV index from UV sensor
      * -  FC    - station forecast, see below for more details
      * -  STORM - stormwarning; 0 - no warning, 1 - fix your dog
      * -  WD    - wind direction in n x 22.5°; 0 -> north
      * -  WS    - wind speed in m/s
      * -  WG    - wind gust speed in m/s
      * -  WC    - windchill temperature in °C
      * -  RC    - rain counter (maybe since station starts measurement) as value
      *
      *
      * weather forecast means (as precisely as possible)
      * - 0 - heavy snow
      * - 1 - little snow
      * - 2 - heavy rain
      * - 3 - little rain
      * - 4 - cloudy
      * - 5 - some clouds
      * - 6 - sunny
      */
     $te_data = array();
     $status = explode(":", $status);
     $data = explode(":", $data);
     $cdata = count($data);
     $cstatus = count($status);
     $this->debug(__FUNCTION__, "Entered: Data:{$cdata},Status: {$cstatus}");
     //if (($cdata == 22) && ($cstatus == 13)) {
     $date = $data[0];
     $tsid = @$this->GetIDForIdent('TimeStamp');
     if ($tsid > 0) {
         SetValueInteger($tsid, $date);
     }
     $te_data['date'] = $date;
     //Indoor and Sensor1-5 T/H
     for ($s = 0; $s < self::MAXSENSORS; $s++) {
         $f = $s * 2 + 1;
         if (trim($data[$f]) == 'i') {
             continue;
         }
         $te_data[$s]['Id'] = "{$s}";
         $te_data[$s]['Temp'] = (double) $data[$f];
         if ($s > 0) {
             $batf = 13 - $s;
             if (isset($status[$batf])) {
                 $stat = $status[$batf] == '0' ? 'LOW' : 'OK';
                 $te_data[$s]['Battery'] = $stat;
             }
         }
         if (trim($data[$f + 1]) != 'i') {
             $te_data[$s]['Hum'] = (int) $data[$f + 1];
         }
         //todo
         $te_data[$s]['Typ'] = 'T/F';
         if ($s == 0) {
             $te_data[$s]['Typ'] = 'Indoor';
         } else {
             if (!isset($te_data[$s]['Hum'])) {
                 $te_data[$s]['Typ'] = 'T';
             }
         }
     }
     //indoor specioa
     if (trim($data[13]) != 'i') {
         $te_data[0]['Press'] = (int) $data[13];
     }
     if (trim($data[15]) != 'i') {
         $te_data[0]['Forecast'] = (int) $data[15];
     }
     //uv
     if (trim($data[14]) != 'i') {
         $te_data['UV']['UV'] = $data[14];
         $te_data['UV']['Bat'] = $status[6];
     }
     //wind
     if (trim($data[18]) != 'i') {
         $te_data['Wind']['Wind'] = $data[18] * self::ms_to_kmh;
         $te_data['Wind']['Storm'] = $data[16] != 0 ? 'YES' : 'No';
         $te_data['Wind']['WindDir'] = $data[17] * 22.5;
         $te_data['Wind']['WindGust'] = $data[19] * self::ms_to_kmh;
         $te_data['Wind']['WindChill'] = (double) $data[20];
         $te_data['Wind']['Bat'] = $status[7];
     }
     //rain
     if (trim($data[21]) != 'i') {
         $new = (int) $data[21];
         $factor = $this->GetRainPerCount() / 1000;
         $rcid = @$this->GetIDForIdent('LastRainCounter');
         $dailyid = @$this->GetIDForIdent('NewDayRainCounter');
         $old = GetValueInteger($rcid);
         $daily = GetValueInteger($dailyid);
         $diff = $new - $old;
         $dailydiff = $new - $daily;
         $rain = $diff * $factor;
         $raindaily = $dailydiff * $factor;
         $te_data['Rain']['RainLastDay'] = '';
         $dailyvar = IPS_GetVariable($dailyid);
         $dailyupdated = $dailyvar['VariableUpdated'];
         if (is_new_day($dailyupdated)) {
             //set last day sum
             SetValueInteger($dailyid, $old);
             //calculate rain last day
             $lastday = ($old - $daily) * $factor;
             if ($lastday < 0 or $lastday > 500) {
                 $lastday = 0;
             }
             $te_data['Rain']['RainLastDay'] = $lastday;
             $this->debug(__FUNCTION__, "::NewDay, Store old Counter({$old}) and Daily({$lastday})");
         }
         if ($new > $old) {
             SetValueInteger($rcid, $new);
         }
         if ($rain < 0 or $rain > 100) {
             $rain = 0;
         }
         $te_data['Rain']['Rain'] = $rain;
         if ($raindaily < 0 or $raindaily > 500) {
             $raindaily = 0;
         }
         $te_data['Rain']['RainDaily'] = $raindaily;
         $te_data['Rain']['Bat'] = $status[5];
     }
     //fill standard fields
     foreach (array('Wind', 'Rain', 'UV', 'Indoor') as $dev) {
         if (isset($te_data[$dev])) {
             $te_data[$dev]['Typ'] = $dev . "Sensor";
             $te_data[$dev]['Id'] = $dev;
             if (isset($te_data[$dev]['Bat'])) {
                 $stat = trim($te_data[$dev]['Bat']) == '0' ? 'LOW' : 'OK';
                 $te_data[$dev]['Battery'] = $stat;
                 unset($te_data[$dev]['Bat']);
             }
         }
     }
     $this->debug(__FUNCTION__, 'OK');
     /*
     } else {
         $this->debug(__FUNCTION__, "Field Error (22 data and 14 status fields expected");
     }
     */
     $this->debug(__FUNCTION__, " Parsed Data:" . print_r($te_data, true));
     if (count($te_data) == 0) {
         IPS_LogMessage(__CLASS__, __FUNCTION__ . " Error: Parsing returned no data");
     }
     return $te_data;
 }
 public function Update()
 {
     // prüfen
     //        IPS_LogMessage("CondBoolValue", print_r($this->ReadPropertyInteger("ConditionBoolean"), 1));
     //        IPS_LogMessage("CondValue", print_r($this->ReadPropertyInteger("ConditionValue"), 1));
     //        IPS_LogMessage("IPS", print_r($_IPS, 1));
     $SourceID = $this->ReadPropertyInteger("Source");
     if ($SourceID == 0) {
         return;
     }
     if ($_IPS["SENDER"] == "Variable") {
         if ($_IPS["VARIABLE"] != $this->ReadPropertyInteger("Source")) {
             trigger_error("Error processing Eventdata", E_USER_WARNING);
             return;
         }
         $Value = $_IPS["VALUE"];
     } else {
         $Value = GetValue($SourceID);
     }
     //        IPS_LogMessage("IPS", print_r($Value, 1));
     $Source = IPS_GetVariable($SourceID);
     switch ($Source["VariableType"]) {
         case 0:
             // bool
             if ($this->ReadPropertyInteger("ConditionBoolean") == (bool) $Value) {
                 $this->HideOrDeaktiv(true);
             } else {
                 $this->HideOrDeaktiv(false);
             }
             break;
         case 1:
             // int
             if ((int) $this->ReadPropertyString("ConditionValue") == (int) $Value) {
                 $this->HideOrDeaktiv(true);
             } else {
                 $this->HideOrDeaktiv(false);
             }
             break;
         case 2:
             // float
             if ((double) $this->ReadPropertyString("ConditionValue") == (double) $Value) {
                 $this->HideOrDeaktiv(true);
             } else {
                 $this->HideOrDeaktiv(false);
             }
             break;
         case 3:
             // string
             if ((string) $this->ReadPropertyString("ConditionValue") == (string) $Value) {
                 $this->HideOrDeaktiv(true);
             } else {
                 $this->HideOrDeaktiv(false);
             }
             break;
     }
 }
Exemplo n.º 15
0
		private function ReceiveCodeVariable($object) {
			$variableId   = (int)$object['Id'];
			$variable     = IPS_GetVariable($variableId);
			$value        = GetValue($variableId);
			$action       = $variable['VariableCustomAction'] ;
			$type         = $variable['VariableValue']['ValueType'];
			$profile      = $variable['VariableCustomProfile'];
			$profileData  = IPS_GetVariableProfile($profile);
			$associations = $profileData['Associations'];

			if ($profile=='' or $action==0) return;

			if (GetValue($this->objectEditId)<>0) {
				SetValue($this->objectEditId, 0);
			}

			switch($type) {
				case 0: // Boolean
					IPSLogger_Dbg(__file__, 'Execute Action '.$action);
					IPS_RunScriptWaitEx($action, array( 'SENDER'=>'WebFront', 'VALUE'=>!$value, 'VARIABLE'=>$variableId, 'REMOTE_ADDR'=>'localhost'));
					break;
				case 1: // Integer
					if ($object['Value']=="") {
						SetValue($this->objectEditId, $variableId);
					} else {
						IPS_RunScriptWaitEx($action, array( 'SENDER'=>'WebFront', 'VALUE'=>(int)$object['Value'], 'VARIABLE'=>$variableId, 'REMOTE_ADDR'=>'localhost'));
					}
					break;
				case 2: // Float
					break;
				case 3: // String
					break;
				default: // Unsupported Datatype
			}
		}
 /**
  * parses an record string
  * 
  * @param $txt string Output from ws2500 program
  * @return array
  */
 private function Parse($txt)
 {
     /*
      # Sensorname[-number] (drop outs): values of sensor
      ## Blocknumber: Block(1)
      ## Date: Cal(date), time(sec)
      ## Station: Id(1)
      ## THS(Temp/humidity): Temperatur(�C), Humidity(%), New(1)
      ## PS(Pressure): Pressure-relativ(hPa), New
      ## RS(Rain): Counter(1), OneCount(mm/1000), Rain(mm/1000), Tol(1), New(1)
      ## WS(Wind): Speed(Km/h), Direction(�), Variance(�), New(1)
      ## LS(Light): Light(lux), Factor(1), Flag(1), Duration(h), DeltaDuration(min), New(1)
      ## PYS(Pyranometer): Energy(W/m), Factor(1)
      #
      Blocknumber: 348
      Date: Sun May  8 06:56:17 2016, 1462690577
      Station: 1
      THS-1 (0): 24.9, 20, h
      THS-2 (1): 20.4, 44, 1
      THS-3 (0): 23.7, 21, 1
      THS-4 (0): 23.0, 31, 1
      THS-5 (0): 22.1, 32, 1
      THS-6 (0): 24.5, 28, 1
      THS-7 (1): 17.3, 45, 1
      THS-8 (1): 17.0, 51, 1
      THS-17 (0): 23.2, 32, 1
      PS     (0): 1009, 1
      LS    (0): 479, 100, 0, 52.27, -1, 1
     */
     $lines = explode("\n", $txt);
     if (count($lines) < 4) {
         $this->debug(__FUNCTION__, 'Not enough data');
         return;
     }
     foreach ($lines as $line) {
         if (!isset($line[0])) {
             continue;
         }
         if ($line[0] == '#') {
             continue;
         }
         if ($line[0] == '+') {
             continue;
         }
         $result = array();
         $datum = date('Y-m-d H:i:s');
         if (preg_match_all("/^([\\w-]+).*?:\\s+(.*)\$/", $line, $result)) {
             $dev = $result[1][0];
             $typ = $dev;
             $id = 0;
             $p = strpos($dev, '-');
             if ($p > 0) {
                 $typ = substr($dev, 0, $p);
                 $id = substr($dev, $p + 1);
             }
             $values = $result[2][0];
             //$values=str_replace(" ",'',$values);
             $data = array();
             $data['Id'] = $dev;
             $caps = '';
             switch ($typ) {
                 case 'Date':
                     list($d, $ts) = explode(',', $values);
                     $tsid = @$this->GetIDForIdent('TimeStamp');
                     if ($tsid > 0) {
                         $old = GetValueInteger($tsid);
                         if ($ts > $old) {
                             SetValueInteger($tsid, $ts);
                         }
                     }
                     $datum = date('Y-m-d H:i:s', $ts);
                     $this->debug(__FUNCTION__, "Date: {$d}, TS {$ts}, Datum {$datum}");
                     break;
                 case 'Blocknumber':
                     $block = $values;
                     $blid = @$this->GetIDForIdent('Block');
                     if ($blid > 0) {
                         $old = GetValueInteger($blid);
                         if ($block != $old) {
                             SetValueInteger($blid, $block);
                         } else {
                             $this->debug(__FUNCTION__, "BlockNumber ({$block}) is the same, skipping");
                             return;
                         }
                     }
                     $this->debug(__FUNCTION__, "Blocknumber: {$block}");
                     break;
                 case 'Station':
                     break;
                 case 'THS':
                     $values = str_replace(" ", "", $values);
                     list($temp, $hum, $new) = explode(',', $values);
                     $new = trim($new);
                     if ($new != '0') {
                         $data['Date'] = $datum;
                         $data['Typ'] = 'T/F';
                         $caps .= 'Temp;Hum;';
                         if ($id == 17) {
                             $data['Typ'] = 'Indoor';
                             $data['Id'] = 'Indoor';
                             $caps .= 'Press;';
                         }
                         $data['Temp'] = $temp;
                         $data['Hum'] = $hum;
                         $this->debug(__FUNCTION__, "{$dev}: Temp:{$temp}, Hum:{$hum}");
                         $this->SendWSData($data, $caps);
                     }
                     break;
                 case 'RS':
                     $values = str_replace(" ", "", $values);
                     list($rc, $cf, $rain, $tol, $new) = explode(',', $values);
                     if ($new == 1) {
                         $rcid = @$this->GetIDForIdent('LastRainCounter');
                         $dailyid = @$this->GetIDForIdent('NewDayRainCounter');
                         //build diffs
                         $old = GetValueInteger($rcid);
                         $daily = GetValueInteger($dailyid);
                         $diff = $new - $old;
                         //counter overflow 4096
                         if ($diff < 0) {
                             $diff += 4096;
                         }
                         $dailydiff = $new - $daily;
                         if ($dailydiff < 0) {
                             $dailydiff += 4096;
                         }
                         $crain = $diff * $this->GetRainPerCount() / 1000;
                         if ($crain != $rain) {
                             $this->debug(__FUNCTION__, "Rain different c:{$crain},d:{$rain} ");
                         }
                         $raindaily = $dailydiff * $this->GetRainPerCount() / 1000;
                         $dailyvar = IPS_GetVariable($dailyid);
                         $dailyupdated = $dailyvar['VariableUpdated'];
                         if (is_new_day($dailyupdated)) {
                             //new day routine,set
                             //$rcvar=IPS_GetVariable($rcid);
                             //$updated=$rcvar['VariableUpdated'];
                             //if($updated<$date) {
                             //set last day sum
                             $this->debug(__FUNCTION__, 'NewDay, Store old Counter');
                             SetValueInteger($dailyid, $old);
                             //}
                         }
                         if ($new > $old) {
                             SetValueInteger($rcid, $new);
                         }
                         if ($rain < 0 or $rain > 100) {
                             $rain = 0;
                         }
                         if ($raindaily < 0 or $raindaily > 500) {
                             $raindaily = 0;
                         }
                         $data['Date'] = $datum;
                         $data['Typ'] = 'Rain';
                         $data['Rain'] = $rain;
                         $data['RainCounter'] = $rc;
                         $data['RainDaily'] = $raindaily;
                         $data['CounterFactor'] = $cf;
                         $caps .= 'RainCounter;Rain;RainDaily;';
                         $this->debug(__FUNCTION__, "Rain Counter:{$rc}, Rain:{$rain}, cf: {$cf}, daily: {$raindaily} ,TOL:{$tol}");
                         $this->SendWSData($data, $caps);
                     }
                     break;
                 case 'WS':
                     $values = str_replace(" ", "", $values);
                     list($speed, $dir, $var, $new) = explode(',', $values);
                     if ($new == 1) {
                         $data['Date'] = $datum;
                         $data['Typ'] = 'Wind';
                         $data['WindSpeed'] = $speed;
                         $data['WindDir'] = $dir;
                         $data['WindVar'] = $var;
                         $caps .= 'WindSpeed;WindDir;WindVar';
                         $this->debug(__FUNCTION__, "Wind Speed:{$speed}, Dir:{$dir}, Var: {$var}");
                         $this->SendWSData($data, $caps);
                     }
                     break;
                 case 'LS':
                     $values = str_replace(" ", "", $values);
                     list($light, $factor, $flag, $dur, $deltadur, $new) = explode(',', $values);
                     if ($new == 1) {
                         $data['Date'] = $datum;
                         $data['Typ'] = 'Light';
                         $data['Light'] = $light * $factor;
                         $caps .= 'Light;';
                         $this->debug(__FUNCTION__, "Light {$light} factor: {$factor}, Flag:{$flag}, Dur:{$dur}, Deltadur:{$deltadur}");
                         $this->SendWSData($data, $caps);
                     }
                     break;
                 case 'PYS':
                     $values = str_replace(" ", "", $values);
                     list($light, $factor, $new) = explode(',', $values);
                     if ($new == 1) {
                         $data['Date'] = $datum;
                         $data['Typ'] = 'Pyrano';
                         $data['UV'] = $light * $factor;
                         $caps .= 'UV;';
                         $this->debug(__FUNCTION__, "PYR {$light} factor: {$factor} ");
                         $this->SendWSData($data, $caps);
                     }
                     break;
                 case 'PS':
                     $values = str_replace(" ", "", $values);
                     list($press, $new) = explode(',', $values);
                     if ($new == 1) {
                         $data['Date'] = $datum;
                         $data['Typ'] = 'Indoor';
                         $data['Id'] = 'Indoor';
                         $data['Press'] = $press;
                         $caps .= 'Press;';
                         $this->debug(__FUNCTION__, "Press {$press}");
                         $this->SendWSData($data, $caps);
                     }
                     break;
                 default:
                     $this->debug(__FUNCTION__, "Unknown type '{$typ}'");
                     break;
             }
             //switch
         }
         //match  line
     }
     //for lines
 }