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); }
private function GetVariableId() { $id = @IPS_GetObjectIDByName($this->moduleName, $this->instanceId); if ($id===false) { $position = count(IPS_GetChildrenIDs($this->instanceId)) * 10 + 10; $id = CreateVariable ($this->moduleName, 3 /*String*/, $this->instanceId, $position, "~String"); } return $id; }
public function RequestModule() { $monitorID = $this->GetIDForIdent('Monitordaten'); $string = GetValueString($monitorID); if ($string == '') { Logamatic_RequestMonitordaten($this->InstanceID); return true; } else { $ParentID = @IPS_GetObjectIDByName('Konfiguration', $this->InstanceID); $array = array('Modul in Slot 1', 'Modul in Slot 2', 'Modul in Slot 3', 'Modul in Slot 4', 'Modul in Slot A'); // mögliche Slots in Logamatic 43xx for ($x = 0; $x < count($array); $x++) { $Slot = @IPS_GetObjectIDByName($array[$x], $ParentID); $Modultyp = GetValueString($Slot); switch ($Modultyp) { case 'FM441': $InsID = IPS_CreateInstance('{08E2244F-D084-4574-9EE7-C6A23A008CFA}'); IPS_SetName($InsID, 'Logamatic FM441'); IPS_SetParent($InsID, $this->InstanceID); break; case 'FM442': $InsID = IPS_CreateInstance('{02B58635-9185-4AA4-90D2-FF0F1C947201}'); IPS_SetName($InsID, 'Logamatic FM442'); IPS_SetParent($InsID, $this->InstanceID); break; case 'FM443': $InsID = IPS_CreateInstance('{540D690E-35DA-4C96-974F-7F74DA840927}'); IPS_SetName($InsID, 'Logamatic FM443'); IPS_SetParent($InsID, $this->InstanceID); break; case 'FM444': $InsID = IPS_CreateInstance('{D887C2E7-9A65-42CB-9DC7-A092FD98FCBA}'); IPS_SetName($InsID, 'Logamatic FM444'); IPS_SetParent($InsID, $this->InstanceID); break; case 'ZM432': $InsID = IPS_CreateInstance('{DC32EE80-C473-4806-A8A3-158DCFB6E2EE}'); IPS_SetName($InsID, 'Logamatic ZM432'); IPS_SetParent($InsID, $this->InstanceID); break; case 'frei': break; } } } return true; }
/** ObjektId aus Pfad ermittlen * * Der Befehl ermittelt aus einer Pfadangabe (zB. "IPSLibrary.IPSUtils.IPSUtils.inc.php") die ID des Scriptes * * @param string $path Pfadangabe * @param string $returnFalse wenn true, retouniert die Funktion false wenn das übergebene Object nicht gefunden wurde * @return integer ID des Objektes * */ function IPSUtil_ObjectIDByPath($path, $returnFalse=false) { $categoryList = explode('.',$path); if (count($categoryList)==1 and is_numeric($categoryList[0])) { return (int)$categoryList[0]; } $objId = 0; $parentId = 0; foreach ($categoryList as $idx=>$category) { $objId = @IPS_GetObjectIDByIdent($category, $parentId); if ($objId===false) { $objId=@IPS_GetObjectIDByName($category, $parentId); } if ($objId===false) { if ($returnFalse) { return false; } else { throw new IPSUtilException('"'.$category.'" could NOT be found while searching for Path '.$path); } } $parentId = $objId; } return $objId; }
function GetOrCreateDummyByName($Parent, $Name) { $ObjID = @IPS_GetObjectIDByName($Name, $Parent); if ($ObjID == 0) { $ObjID = IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}"); IPS_SetParent($ObjID, $Parent); IPS_SetName($ObjID, $Name); } return $ObjID; }
private function getDeviceAddress($deviceName) { $ret = IPS_GetInstanceListByModuleID("{44D8BE09-743E-484F-A64D-154C4235BE94}"); $DeviceURL = ""; $AccessToken = ""; $retArray = ""; $SecChannelExp = 0; if ($ret == null) { echo "Error: ips4WinDeviceRegistration is not implemented! Please create a new instance of ips4WinDeviceRegistration!\n"; } else { if (count($ret) > 1) { echo "Error: multiple ips4WinDeviceRegistration found, unsupported installation! Please make sure you have only one instance of ips4WinDeviceRegistration!\n"; } else { $id = $ret[0]; $objList = IPS_GetChildrenIDs($id); //print_r($objList); $i = count($objList); for ($j = 0; $j < $i; $j++) { $vid = @IPS_GetObjectIDByName("deviceName", $objList[$j]); if ($vid !== false) { if ($deviceName == null) { $device = GetValueString($vid); $vid = @IPS_GetObjectIDByName("SecChannel", $objList[$j]); if ($vid !== false) { $DeviceURL = GetValueString($vid); } $vid = @IPS_GetObjectIDByName("AccessToken", $objList[$j]); if ($vid !== false) { $AccessToken = GetValueString($vid); } $vid = @IPS_GetObjectIDByName("SecChannelExp", $objList[$j]); if ($vid !== false) { $SecChannelExp = GetValueInteger($vid); } if ($retArray == "") { $retArray[0] = explode("###", $device . "###" . $DeviceURL . "###" . $AccessToken . "###" . $SecChannelExp); } else { $retArray[count($retArray)] = explode("###", $device . "###" . $DeviceURL . "###" . $AccessToken . "###" . $SecChannelExp); } $DeviceURL = ""; $AccessToken = ""; $SecChannelExp = 0; } else { if (strtolower($deviceName) == strtolower(GetValueString($vid))) { $vid = @IPS_GetObjectIDByName("SecChannel", $objList[$j]); if ($vid !== false) { $DeviceURL = GetValueString($vid); } $vid = @IPS_GetObjectIDByName("AccessToken", $objList[$j]); if ($vid !== false) { $AccessToken = GetValueString($vid); } $vid = @IPS_GetObjectIDByName("SecChannelExp", $objList[$j]); if ($vid !== false) { $SecChannelExp = GetValueInteger($vid); } $retArray = array(explode("###", $deviceName . "###" . $DeviceURL . "###" . $AccessToken . "###" . $SecChannelExp)); $j = $i; } } } } } } return $retArray; }
public function SetDefaultGroupVolume() { if (!$this->ReadPropertyBoolean("GroupCoordinator")) { die("This function is only allowed for GroupCoordinators"); } $groupMembers = GetValueString(IPS_GetObjectIDByName("GroupMembers", $this->InstanceID)); $groupMembersArray = array(); if ($groupMembers) { $groupMembersArray = array_map("intval", explode(",", $groupMembers)); } $groupMembersArray[] = $this->InstanceID; foreach ($groupMembersArray as $key => $ID) { try { SNS_SetDefaultVolume($ID); } catch (Exception $e) { } } $GroupVolume = 0; foreach ($groupMembersArray as $key => $ID) { $GroupVolume += GetValueInteger(IPS_GetObjectIDByName("Volume", $ID)); } SetValueInteger(IPS_GetObjectIDByName("GroupVolume", $this->InstanceID), intval(round($GroupVolume / sizeof($groupMembersArray)))); }
if ($sleeptimer) { $SleeptimerArray = explode(":", $sonos->GetSleeptimer()); $SleeptimerMinutes = $SleeptimerArray[0] * 60 + $SleeptimerArray[1]; if ($SleeptimerArray[2]) { $SleeptimerMinutes = $SleeptimerMinutes + 1; } } else { $SleeptimerMinutes = 0; } SetValueInteger(IPS_GetObjectIDByName("Sleeptimer", IPS_GetParent($_IPS["SELF"])), $SleeptimerMinutes); } } $nowPlaying = GetValueString(IPS_GetObjectIDByName("nowPlaying", IPS_GetParent($_IPS["SELF"]))); if ($actuallyPlaying != $nowPlaying) { SetValueString(IPS_GetObjectIDByName("nowPlaying", IPS_GetParent($_IPS["SELF"])), $actuallyPlaying); } } // Set Group Volume if (IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "GroupCoordinator")) { $groupMembers = GetValueString(IPS_GetObjectIDByName("GroupMembers", IPS_GetParent($_IPS["SELF"]))); $groupMembersArray = array(); if ($groupMembers) { $groupMembersArray = array_map("intval", explode(",", $groupMembers)); } $groupMembersArray[] = IPS_GetParent($_IPS["SELF"]); $GroupVolume = 0; foreach ($groupMembersArray as $key => $ID) { $GroupVolume += GetValueInteger(IPS_GetObjectIDByName("Volume", $ID)); } SetValueInteger(IPS_GetObjectIDByName("GroupVolume", IPS_GetParent($_IPS["SELF"])), intval(round($GroupVolume / sizeof($groupMembersArray)))); }
function Dummy_GetOrSet($name, $parent) { $DummyID = @IPS_GetObjectIDByName($name, $parent); if (!$DummyID) { $DummyID = IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}"); IPS_SetParent($DummyID, $parent); IPS_SetName($DummyID, $name); } return $DummyID; }
<?php include_once "../modules/SymconSonos/Sonos/sonosAccess.php"; // Nothing to do if Instance is Group Coordinator if (IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "GroupCoordinator")) { return; } $groupForcing = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "GroupForcing"); $rinconMapping = array(); $allSonosInstances = IPS_GetInstanceListByModuleID("{F6F3A773-F685-4FD2-805E-83FD99407EE8}"); $MemberOfGroupID = @IPS_GetObjectIDByName("MemberOfGroup", IPS_GetParent($_IPS["SELF"])); $MemberOfGroup = 0; if ($MemberOfGroupID) { $MemberOfGroup = GetValueInteger($MemberOfGroupID); } //ensure that all rincons are known foreach ($allSonosInstances as $key => $SonosID) { $rincon = IPS_GetProperty($SonosID, "RINCON"); if (!$rincon) { // Get RINCON // Not sure why, but when executed in ApplyChanges of module.php RINCON is not alway set $ipAddress = IPS_GetProperty($SonosID, "IPAddress"); if ($ipAddress) { $curl = curl_init(); curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => "http://" . $ipAddress . ":1400/xml/device_description.xml")); $result = curl_exec($curl); if (!curl_exec($curl)) { continue; } $xmlr = new SimpleXMLElement($result); $rincon = str_replace("uuid:", "", $xmlr->device->UDN);
/** * This function will be available automatically after the module is imported with the module control. * Using the custom prefix this function will be callable from PHP and JSON-RPC through: * * KP_RequestInfo($id); * */ public function RequestInfo() { $locationisday = IPS_GetInstanceListByModuleID("{45E97A63-F870-408A-B259-2933F7EABF74}"); $locationisday = IPS_GetObjectIDByName('Is Day', $locationisday[0]); $IsDay = $this->ReadPropertyBoolean("IsDay"); if ($IsDay == true and GetValueBoolean($locationisday) == false) { return; } else { $url = $this->ReadPropertyString("url"); $Ausgabe = file_get_contents("{$url}", "r"); //AC-Leistung_Aktuell $pos1 = strpos($Ausgabe, "aktuell</td>"); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 65, $pos2 - $pos1 - 65); $data1 = (double) $data; SetValue($this->GetIDForIdent("ACLeistungAktuell"), $data1); //AC_Leistung_Status $pos1 = strpos($Ausgabe, "Status</td>"); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 33, $pos2 - $pos1 - 33); SetValue($this->GetIDForIdent("ACLeistungStatus"), $data); //Energie_Gesamtertrag $pos1 = strpos($Ausgabe, "Gesamtenergie</td>"); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 30); $data = substr($Ausgabe, $pos1 + 70, $pos2 - $pos1 - 70); $data1 = (double) $data; SetValue($this->GetIDForIdent("Gesamtertrag"), $data1); //Energie_Tagesertrag_Aktuell $pos1 = strpos($Ausgabe, "Tagesenergie</td>"); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 70, $pos2 - $pos1 - 70); $data1 = (double) $data; SetValue($this->GetIDForIdent("Tagesertrag"), $data1); //PV_Generator_String1_Spannung $pos1 = strpos($Ausgabe, "Spannung</td>", $pos2); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66); $data1 = (double) $data; SetValue($this->GetIDForIdent("SpannungString1"), $data1); //Ausgangsleistung_L1_Spannung $pos1 = strpos($Ausgabe, "Spannung</td>", $pos2); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66); $data1 = (double) $data; SetValue($this->GetIDForIdent("L1Spannung"), $data1); //PV_Generator_String1_Strom $pos1 = strpos($Ausgabe, "Strom</td>", $pos2); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 63, $pos2 - $pos1 - 63); $data1 = (double) $data; SetValue($this->GetIDForIdent("StromString1"), $data1); //Ausgangsleistung_L1_Leistung $pos1 = strpos($Ausgabe, "Leistung</td>", $pos2); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66); $data1 = (double) $data; SetValue($this->GetIDForIdent("L1Leistung"), $data1); //PV_Generator_String2_Spannung $pos1 = strpos($Ausgabe, "Spannung</td>", $pos2); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66); $data1 = (double) $data; SetValue($this->GetIDForIdent("SpannungString2"), $data1); //Ausgangsleistung_L2_Spannung $pos1 = strpos($Ausgabe, "Spannung</td>", $pos2); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66); $data1 = (double) $data; SetValue($this->GetIDForIdent("L2Spannung"), $data1); //PV_Generator_String2_Strom $pos1 = strpos($Ausgabe, "Strom</td>", $pos2); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 63, $pos2 - $pos1 - 63); $data1 = (double) $data; SetValue($this->GetIDForIdent("StromString2"), $data1); //Ausgangsleistung_L2_Leistung $pos1 = strpos($Ausgabe, "Leistung</td>", $pos2); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66); $data1 = (double) $data; SetValue($this->GetIDForIdent("L2Leistung"), $data1); //PV_Generator_String3_Spannung $pos1 = strpos($Ausgabe, "Spannung</td>", $pos2); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66); $data1 = (double) $data; SetValue($this->GetIDForIdent("SpannungString3"), $data1); //Ausgangsleistung_L3_Spannung $pos1 = strpos($Ausgabe, "Spannung</td>", $pos2); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66); $data1 = (double) $data; SetValue($this->GetIDForIdent("L3Spannung"), $data1); //PV_Generator_String3_Strom $pos1 = strpos($Ausgabe, "Strom</td>", $pos2); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 63, $pos2 - $pos1 - 63); $data1 = (double) $data; SetValue($this->GetIDForIdent("StromString3"), $data1); //Ausgangsleistung_L3_Leistung $pos1 = strpos($Ausgabe, "Leistung</td>", $pos2); $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20); $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66); $data1 = (double) $data; SetValue($this->GetIDForIdent("L3Leistung"), $data1); } }