login(); // --- STATUS SmartHome ----------------------------------------------------------------------------- $SQLUEBERGABE = Hausstatus($sh); $Variable01 = $argv[1]; $Variable02 = $argv[2]; $DUDEL = ($SQLUEBERGABE [$Variable01] [$Variable02]); echo ($DUDEL); // --- Funktion "Get Hausinformationen" ----------------------------------------------------------------------------- function Hausstatus ($sh) { $configuration = $sh->getConfiguration(); $ConfigurationVersion = xml_attribute($configuration, 'ConfigurationVersion'); // --- determine Room infos $LCARR = $configuration->LCs->LC; $RAUMZAEHLER = 0; foreach ($LCARR as $LC) { // fails in case of attributes (like $FN) : $ID = strip_tags($LC->Id->asXML()); $ID = $LC->Id->__toString(); $NAME = $LC->Name->__toString(); $POSITION = intval($LC->Position->__toString()); $ROOMS["$ID"] = array ($NAME, $POSITION); $RAUMZAEHLER = $RAUMZAEHLER +1; } $ROOMS = sortArray($ROOMS, 1); // sort by position for($x = 0; $x < $RAUMZAEHLER; $x++) { $ZIMMER[$x] = (string) $configuration -> LCs -> LC[$x] -> Name; } // --- determine BD infos $BDARR = $configuration->BDs->BD; foreach ($BDARR as $BD) { $FN = $BD["FN"]->__toString(); // SerialNo. $APPID = $BD["AppId"]->__toString(); $ID = $BD->Id->__toString(); $ROOM = "";// to be filled later (when fetching $LDS) $ROOMPOS = "";// to be filled later (when fetching $LDS) if ( isset($BD->AIPs->Ppt["Value"]) ) { $VALUE = $BD->AIPs->Ppt["Value"]->__toString() ; // Type } else { $VALUE = "V."; // Variable } $BDS["$ID"] = array($VALUE, $FN, $APPID, $ROOM, $ROOMPOS); } // --- determine Logical Devices $LDARR = $configuration->LDs->LD; foreach ($LDARR as $LD) { $ID = $LD->Id->__toString(); $LCID = $LD["LCID"]->__toString(); $NAME = $LD["Name"]->__toString(); $BDID = $LD->BDId->__toString(); $ROOM = $ROOMS["$LCID"][0]; $ROOMPOS = $ROOMS["$LCID"][1]; $BDTYPE = ("$BDID" == "") ? "" : $BDS["$BDID"][0]; $LDS["$ID"] = array($NAME, $LCID, $BDID, $BDTYPE, $ROOM, $ROOMPOS); } $LDS = sortArray($LDS, 5); // sort by Room-position $CONFIGR['LDs'] = $LDS; $LDS = $CONFIGR['LDs'] ; // --- determine and sort Hausinformationen $i=1; $devstates = $sh->getAllLogicalDeviceStates(); $LDSARR = $devstates->LogicalDeviceState; foreach ($LDSARR as $LD) { $LID = $LD["LID"]->__toString(); $ROOM = $LDS["$LID"][4]; $ROOMPOS = $LDS["$LID"][5]; $LDNAME = $LDS["$LID"][0]; $TEMPERATURE = isset ($LD["Temperature"]) ? $LD["Temperature"]->__toString() : null; // Rst: RoomTemperatureSensorState Sensor Temperature $HUMIDITY = isset ($LD["Humidity"]) ? $LD["Humidity"]->__toString() : null; // Rst: RoomHumiditySensorState Sensor Humidity $PTTMP = isset ($LD["PtTmp"]) ? $LD["PtTmp"]->__toString() : null; // Rst: RoomTemperatureActuatorState Actor: Temperature $OPNMD = isset ($LD["OpnMd"]) ? $LD["OpnMd"]->__toString() : null; // Rst: RoomTemperatureActuatorState Actor: Auto / Manu $WRAC = isset ($LD["WRAc"]) ? $LD["WRAc"]->__toString() : null; // Rst: RoomTemperatureActuatorState ???? $VALUE = isset ($LD->Ppts->Ppt["Value"]) ? $LD->Ppts->Ppt["Value"]->__toString() : null; // GenericDeviceState $ISON = isset ($LD["IsOn"]) ? $LD["IsOn"]->__toString() : (isset ($LD->IsOn) ? $LD->IsOn->__toString() : null); // SwitchActuatorState $ISSMOKE = isset ($LD->IsSmokeAlarm) ? $LD->IsSmokeAlarm->__toString() : null; // $BDTYPE = $LDS["$LID"][3]; $RSTDATA[$i] = array($LID, $ROOM, $ROOMPOS, $LDNAME, $TEMPERATURE, $HUMIDITY, $PTTMP, $OPNMD, $WRAC, $VALUE, $ISON, $ISSMOKE, $BDTYPE); for($count = 3; $count < 12; $count++) { for($y = 0; $y < $RAUMZAEHLER; $y++) { if($ROOM == $ZIMMER[$y] and $TEMPERATURE > 0) { $RT[$ROOM]['Temperatur'] = $TEMPERATURE; } if($ROOM == $ZIMMER[$y] and $PTTMP > 0) { if($PTTMP < 18) { $HS[$ROOM] ['Heizstatus'] = 0; } else { $HS[$ROOM] ['Heizstatus'] = 1; } } if($ROOM == $ZIMMER[$y] and $HUMIDITY > 0) { $RF[$ROOM] ['Luftfeuchte'] = $HUMIDITY; } if($ROOM == $ZIMMER[$y] and $VALUE == TRUE) { $LOGIKSCHALTER[$ROOM] [$LDNAME] = $VALUE; } if($ROOM == $ZIMMER[$y] and $ISON == TRUE) { $FUNKSCHALTER[$ROOM] [$LDNAME] = ($ISON); } } } $i=$i+1; } $HAUSSTATUS = array_merge_recursive($RT, $RF, $HS, $LOGIKSCHALTER, $FUNKSCHALTER); return ($HAUSSTATUS); } // --- Class Smarthome -------------------------------------------------------------------------- class Smarthome { private $host; private $username; private $password; private $sessionId = false; private $configurationVersion = false; function __construct($host, $username, $password) { $this->host = $host; $this->username = $username; $this->password = $password; } function login() { $data = ''; $response = $this->doRequest($data); $a = $response->attributes(); $this->sessionId = $a->SessionId; $this->configurationVersion = $a->CurrentConfigurationVersion; } function doRequest($data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://'.$this->host.'/cmd'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSLVERSION, 3); //Neu eingefügt curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $output = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); $xml = new SimpleXMLElement($output); return $xml; } function getInformation() { $data = ''; $response = $this->doRequest($data); return $response->ShcInformation; } function getAllLogicalDeviceStates() { $data = ''; $response = $this->doRequest($data); return $response->States; } function getConfiguration() { $data = ''; $response = $this->doRequest($data); return $response; } function switchActuator($logicalDeviceId, $on) { $data = ' '; $response = $this->doRequest($data); } function setPointTemperature($logicalDeviceId, $pointTemperature) { $data = ' '.$logicalDeviceId.' '.$pointTemperature.' '; $response = $this->doRequest($data); } function setLogicalDeviceState($logicalDeviceId, $on) { $data = ' '; $response = $this->doRequest($data); } } // --- Allgemeine Funktionen -------------------------------------------------------------------------- function sortArray($data, $field) { if (!is_array($field)) $field = array($field); uasort($data, function($a, $b) use($field) { $retval = 0; foreach($field as $fieldname) { if($retval == 0) $retval = strnatcmp($a[$fieldname],$b[$fieldname]); } return $retval; }); return $data; } function xml_attribute($object, $attribute) { if(isset($object[$attribute])) return (string) $object[$attribute]; } #?>