private function CreateInstanceByIdent($id, $ident, $name, $moduleid = "{485D0419-BE97-4548-AA9C-C083EB82E61E}") { $iid = @IPS_GetObjectIDByIdent($ident, $id); if ($iid === false) { $iid = IPS_CreateInstance($moduleid); IPS_SetParent($iid, $id); IPS_SetName($iid, $name); IPS_SetIdent($iid, $ident); } return $iid; }
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; }
/** * Create a new EnergyDev instance and set its properties * @param array $data parsed record * @param String $caps String semicolon seperated capabilities of this device * @return int new Instance ID */ private function CreateENDevice($data, $caps) { $instID = 0; $Device = $data['Id']; $typ = $data['Typ']; $ModuleID = $this->module_interfaces['EnergyDev']; if (IPS_ModuleExists($ModuleID)) { //return $result; $this->debug(__FUNCTION__, "Create Device {$Device},Type {$typ}"); $instID = IPS_CreateInstance($ModuleID); if ($instID > 0) { IPS_ConnectInstance($instID, $this->InstanceID); //Parents are ourself! IPS_SetProperty($instID, 'DeviceID', $Device); IPS_SetProperty($instID, 'Class', __CLASS__); IPS_SetProperty($instID, 'Typ', $typ); IPS_SetProperty($instID, 'CapList', $caps); IPS_SetProperty($instID, 'Debug', $this->isDebug()); //follow debug settings from splitter IPS_SetName($instID, "{$typ} ID {$Device}"); $ident = __CLASS__ . "_EN_{$Device}"; $ident = preg_replace("/\\W/", "_", $ident); //nicht-Buchstaben/zahlen entfernen IPS_SetIdent($instID, $ident); IPS_ApplyChanges($instID); $cat = $this->GetCategory(); $pcat = $this->GetParentCategory(); $ident = preg_replace("/\\W/", "_", $cat); //nicht-Buchstaben/zahlen entfernen $catid = @IPS_GetObjectIDByIdent($ident, $pcat); if ($catid == 0) { $catid = IPS_CreateCategory(); IPS_SetName($catid, $cat); if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) { IPS_LogMessage(__CLASS__, "Category {$cat} Ident {$ident} ({$catid}) created"); } else { IPS_LogMessage(__CLASS__, "Category {$cat} Ident {$ident} ({$catid}) FAILED"); } } $this->debug(__FUNCTION__, "Category:{$catid}"); if (!IPS_SetParent($instID, $catid)) { $this->debug(__FUNCTION__, "SetParent to Cat {$catid} failed"); } $this->debug(__FUNCTION__, 'New ID:' . $instID); //if instID } else { $this->debug(__FUNCTION__, 'Instance is not created!'); } } //module exists return $instID; }
public function SomfyCreateInstance(string $InstName, string $AIOSomfyAdresse, string $SomfyType, string $CategoryID) { //Prüfen ob Instanz schon existiert $InstanzID = @IPS_GetInstanceIDByName($InstName, $CategoryID); if ($InstanzID === false) { //echo "Instanz nicht gefunden!"; //Neue Instanz anlegen $InsID = IPS_CreateInstance("{0F83D875-4737-4244-8234-4CF08E6F2626}"); IPS_SetName($InsID, $InstName); // Instanz benennen IPS_SetParent($InsID, $CategoryID); // Instanz einsortieren unter dem Objekt mit der ID "$CategoryID" IPS_SetProperty($InsID, "Adresse", $AIOSomfyAdresse); //Adresse setzten. IPS_ApplyChanges($InsID); //Neue Konfiguration übernehmen IPS_LogMessage("Instanz erstellt:", "Name: " . $InstName); return $InsID; } else { //echo "Die Instanz-ID lautet: ". $InstanzID; return $InstanzID; } }
private function CreateDevices() { // Create Variables Profiles // From Foobot: ["time","pm","tmp","hum","co2","voc","allpollu"],"units":["s","ugm3","C","pc","ppm","ppb","%"] [1445275154,45.449997,25.754375,39.512215,1033.0,286.0,62.60714] $this->RegisterProfileIntegerEx("Pollutant.Co2", "Gauge", "", " ppm", array(array(0, "%d", "", 0xff00), array(1000, "%d", "", 0xffff00), array(2000, "%d", "", 0xff0000))); $this->RegisterProfileFloatEx("Pollutant.PM", "Gauge", "", " uG/m3", array(array(0, "%.1f", "", 0xff00), array(25, "%.1f", "", 0xff0000))); $this->RegisterProfileIntegerEx("Pollutant.VC", "Gauge", "", " ppb", array(array(0, "%d", "", 0xff00), array(500, "%d", "", 0xff0000))); $this->RegisterProfileFloatEx("Pollutant.GPI", "Gauge", "", " %", array(array(0, "%.1f", "", 0xff00), array(50, "%.1f", "", 0xffff00), array(100, "%.1f", "", 0xff0000))); // Get Foobot devices from API and loop on them to create Instances and Variables $devices = $this->GetDevices(); if ($devices !== false) { //foreach ($devices as $device) { // Prepared for multiple Foobot devices support - to be tested // Create a dummy Instance for each Foobot Sensor if it does not exist already if (!$this->deviceInstanceExists($devices->name)) { $FBdeviceModuleID = IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}"); IPS_SetName($FBdeviceModuleID, $devices->name); IPS_SetParent($FBdeviceModuleID, $this->InstanceID); $this->RegisterVariableString("Uuid", "Device UUID", "~String", 1); SetValue($this->GetIDForIdent('Uuid'), $devices->uuid); IPS_SetHidden($this->GetIDForIdent('Uuid'), true); IPS_SetParent($this->GetIDForIdent('Uuid'), $FBdeviceModuleID); $this->RegisterVariableString("Mac", "Device Mac", "~String", 2); SetValue($this->GetIDForIdent('Mac'), $devices->mac); IPS_SetHidden($this->GetIDForIdent('Mac'), true); IPS_SetParent($this->GetIDForIdent('Mac'), $FBdeviceModuleID); // Create Variables $this->RegisterVariableInteger("Co2", "Carbon Dioxide", "Pollutant.Co2", 10); IPS_SetParent($this->GetIDForIdent('Co2'), $FBdeviceModuleID); $this->RegisterVariableInteger("Voc", "Volatile compounds", "Pollutant.VC", 11); IPS_SetParent($this->GetIDForIdent('Voc'), $FBdeviceModuleID); $this->RegisterVariableFloat("Pm", "PM2.5", "Pollutant.PM", 12); IPS_SetParent($this->GetIDForIdent('Pm'), $FBdeviceModuleID); $this->RegisterVariableFloat("Allpollu", "Global Pollution Index", "Pollutant.GPI", 13); IPS_SetParent($this->GetIDForIdent('Allpollu'), $FBdeviceModuleID); $this->RegisterVariableFloat("Tmp", "Temperature", "~Temperature", 14); IPS_SetParent($this->GetIDForIdent('Tmp'), $FBdeviceModuleID); $this->RegisterVariableFloat("Hum", "Humidity", "~Humidity.F", 15); IPS_SetParent($this->GetIDForIdent('Hum'), $FBdeviceModuleID); } //} // End of loop on devices return true; } else { $this->SetStatus(203); if ($this->debug) { IPS_LogMessage("FOOBOT Module", "ERROR: No Foobot Devices have been found!"); } return false; } }
/** * Create a new EnergyDev instance and set its properties * @param array $data parsed record * @param String $caps String semicolon seperated capabilities of this device * @return int new Instance ID */ private function CreateEnergyDevice($data, $caps) { $instID = 0; $Device = $data['Id']; $typ = $data['Typ']; $name = $data['Name']; $branch = $data['Branch']; unset($data['Branch']); if (!$name) { $name = "XS1 {$branch} {$Device}"; } $class = __CLASS__ . "-EN"; //$host = $this->GetHost(); $ModuleID = $this->module_interfaces['EnergyDev']; if (IPS_ModuleExists($ModuleID)) { //return $result; $this->debug(__FUNCTION__, 'Device:' . $Device); $instID = IPS_CreateInstance($ModuleID); if ($instID > 0) { IPS_SetProperty($instID, 'DeviceID', $Device); IPS_SetProperty($instID, 'Class', $class); IPS_SetProperty($instID, 'Typ', $typ); IPS_SetProperty($instID, 'CapList', $caps); IPS_SetProperty($instID, 'Debug', $this->isDebug()); //follow debug settings from splitter IPS_SetName($instID, "XS1 {$branch} '{$name}'"); $ident = $class . "_" . $branch . "_{$Device}"; $ident = preg_replace("/\\W/", "_", $ident); //nicht-Buchstaben/zahlen entfernen IPS_SetIdent($instID, $ident); IPS_ConnectInstance($instID, $this->InstanceID); IPS_ApplyChanges($instID); //set category $cat = $this->GetCategory() . " {$branch}" . "s"; $pcat = $this->GetParentCategory(); $ident = preg_replace("/\\W/", "_", $cat); //fix naming $catid = @IPS_GetObjectIDByIdent($ident, $pcat); if ($catid == 0) { $catid = IPS_CreateCategory(); IPS_SetName($catid, $cat); if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) { IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) created"); } else { IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) FAILED"); } } $this->debug(__FUNCTION__, "Category:{$catid}"); if (!IPS_SetParent($instID, $catid)) { $this->debug(__FUNCTION__, "SetParent Instance {$instID} to Cat {$catid} failed, Dropping instance"); IPS_DeleteInstance($instID); $instID = 0; } else { $this->debug(__FUNCTION__, 'New ID:' . $instID); } //if instID } else { $this->debug(__FUNCTION__, 'Instance is not created!'); } } //module exists return $instID; }
/** * Create a new WSDev instance and set its properties * @param array $data parsed record * @param String $caps String semicolon seperated capabilities of this device * @return int new Instance ID */ private function CreateWSDevice($data, $caps) { $instID = 0; $Device = $data['Id']; $typ = $data['Typ']; $ModuleID = $this->module_interfaces['WSDEV']; if (IPS_ModuleExists($ModuleID)) { //return $result; $this->debug(__FUNCTION__, "Create Device {$Device},Type {$typ}"); $instID = IPS_CreateInstance($ModuleID); if ($instID > 0) { IPS_ConnectInstance($instID, $this->InstanceID); //Parents are ourself! IPS_SetProperty($instID, 'DeviceID', $Device); IPS_SetProperty($instID, 'Class', __CLASS__); IPS_SetProperty($instID, 'Typ', $typ); IPS_SetProperty($instID, 'CapList', $caps); IPS_SetProperty($instID, 'Debug', $this->isDebug()); //follow debug settings from splitter switch ($Device) { case 0: case $Device < 8: IPS_SetName($instID, 'Sensor ' . $Device); break; case 8: IPS_SetName($instID, 'KombiSensor'); break; case 9: IPS_SetName($instID, 'InnenSensor'); break; default: IPS_SetName($instID, "unknown Sensor('" . strToHex($Device) . "')"); break; } //switch $ident = __CLASS__ . "_WS_{$Device}"; $ident = preg_replace("/\\W/", "_", $ident); //nicht-Buchstaben/zahlen entfernen IPS_SetIdent($instID, $ident); IPS_ApplyChanges($instID); $cat = $this->GetCategory(); $pcat = $this->GetParentCategory(); $ident = preg_replace("/\\W/", "_", $cat); //nicht-Buchstaben/zahlen entfernen $catid = @IPS_GetObjectIDByIdent($ident, $pcat); if ($catid == 0) { $catid = IPS_CreateCategory(); IPS_SetName($catid, $cat); if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) { IPS_LogMessage(__CLASS__, "Category {$cat} Ident {$ident} ({$catid}) created"); } else { IPS_LogMessage(__CLASS__, "Category {$cat} Ident {$ident} ({$catid}) FAILED"); } } $this->debug(__FUNCTION__, "Category:{$catid}"); if (!IPS_SetParent($instID, $catid)) { $this->debug(__FUNCTION__, "SetParent to Cat {$catid} failed"); } $this->debug(__FUNCTION__, 'New ID:' . $instID); //if instID //set willi profile for forecast $vid = @IPS_GetObjectIDByIdent('Forecast', $instID); if ($vid > 0) { IPS_SetVariableCustomProfile($vid, "WS300_Willi"); } } else { $this->debug(__FUNCTION__, 'Instance is not created!'); } } //module exists return $instID; }
protected function RequireParent($ModuleID, $Name = '') { $instance = IPS_GetInstance($this->InstanceID); if ($instance['ConnectionID'] == 0) { $parentID = IPS_CreateInstance($ModuleID); $instance = IPS_GetInstance($parentID); if ($Name == '') { IPS_SetName($parentID, $instance['ModuleInfo']['ModuleName']); } else { IPS_SetName($parentID, $Name); } IPS_ConnectInstance($this->InstanceID, $parentID); } }
public function SyncDevices() { $lightsCategoryId = $this->GetLightsCategory(); $lights = $this->Request('/lights'); foreach ($lights as $lightId => $light) { $name = utf8_decode((string)$light->name); $uniqueId = (string)$light->uniqueid; echo "$lightId. $name ($uniqueId)\n"; $deviceId = $this->GetDeviceByUniqueId($uniqueId); if ($deviceId == 0) { $deviceId = IPS_CreateInstance($this->DeviceGuid()); IPS_SetProperty($deviceId, 'UniqueId', $uniqueId); } IPS_SetParent($deviceId, $lightsCategoryId); IPS_SetProperty($deviceId, 'LightId', (integer)$lightId); IPS_SetName($deviceId, $name); // Verbinde Light mit Bridge if (IPS_GetInstance($deviceId)['ConnectionID'] <> $this->InstanceID) { @IPS_DisconnectInstance($deviceId); IPS_ConnectInstance($deviceId, $this->InstanceID); } IPS_ApplyChanges($deviceId); HUE_RequestData($deviceId); } }
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; }
/** * Create a new EneryDev instance and set its properties * @param array $data parsed record * @param String $caps String semicolon seperated capabilities of this device * @return int new Instance ID */ private function CreateENDevice($data, $caps) { $instID = 0; $class = $data['Class']; $Device = $data['Id']; $typ = $data['Typ']; $ModuleID = $this->module_interfaces['EnergyDev']; if (IPS_ModuleExists($ModuleID)) { //return $result; $this->debug(__FUNCTION__, 'Device:' . $Device); $instID = IPS_CreateInstance($ModuleID); if ($instID > 0) { IPS_SetProperty($instID, 'DeviceID', $Device); IPS_SetProperty($instID, 'Class', $class); IPS_SetProperty($instID, 'Typ', $typ); IPS_SetProperty($instID, 'CapList', $caps); IPS_SetProperty($instID, 'Debug', $this->isDebug()); //follow debug settings from splitter IPS_SetName($instID, "{$typ} Device " . $Device); $ident = $class . "_" . $typ . "_" . $Device; $ident = preg_replace("/\\W/", "_", $ident); //nicht-Buchstaben/zahlen entfernen IPS_SetIdent($instID, $ident); IPS_ConnectInstance($instID, $this->InstanceID); IPS_ApplyChanges($instID); //set factor if (isset($data['CounterFactor'])) { IPS_SetProperty($instID, 'CounterFactor', floatval($data['CounterFactor'])); $this->debug(__FUNCTION__, 'Set Counterfactor=' . $data['CounterFactor']); } //set category $cat = $this->GetCategory(); $pcat = $this->GetParentCategory(); $ident = preg_replace("/\\W/", "_", $cat); //fix naming $catid = @IPS_GetObjectIDByIdent($ident, $pcat); if ($catid == 0) { $catid = IPS_CreateCategory(); IPS_SetName($catid, $cat); if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) { IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) created"); } else { IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) FAILED"); } } $this->debug(__FUNCTION__, "Category:{$catid}"); if (!IPS_SetParent($instID, $catid)) { $this->debug(__FUNCTION__, "SetParent Instance {$instID} to Cat {$catid} failed, Dropping instance"); IPS_DeleteInstance($instID); $instID = 0; } else { $this->debug(__FUNCTION__, 'New ID:' . $instID); } //parent if (IPS_HasChanges($instID)) { IPS_ApplyChanges($instID); } } else { $this->debug(__FUNCTION__, 'Instance is not created!'); } //if instID } //module exists return $instID; }
/** * 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: * * LJ_GenerateShutter($id, $Start, $End); * */ public function GenerateShutter($Start, $End) { $qid = @IPS_GetObjectIDByIdent("KNXQuick", 0); if($qid === false) { $qid = IPS_CreateCategory(); IPS_SetName($qid, "KNX quick"); IPS_SetIdent($qid, "KNXQuick"); } $sid = @IPS_GetObjectIDByIdent("Shutter", $qid); if($sid === false) { $sid = IPS_CreateCategory(); IPS_SetName($sid, "Shutter"); IPS_SetIdent($sid, "Shutter"); IPS_SetParent($sid, $qid); IPS_SetPosition($sid, 2); } for($i=$Start; $i<=$End; $i++) { for($j=0; $j<=9; $j++) { $iid = @IPS_GetObjectIDByIdent("Shutter".strtoupper(dechex($i).$j), $sid); if($iid === false) { $iid = IPS_CreateInstance("{24A9D68D-7B98-4D74-9BAE-3645D435A9EF}"); IPS_SetName($iid, "Shutter (Group ".strtoupper(dechex($i)).", Channel ".$j.")"); IPS_SetIdent($iid, "Shutter".strtoupper(dechex($i)).$j); IPS_SetParent($iid, $sid); IPS_SetProperty($iid, "GroupMoveAddress1", 14); IPS_SetProperty($iid, "GroupMoveAddress2", 0); IPS_SetProperty($iid, "GroupMoveAddress3", ($i*16)+$j); IPS_SetProperty($iid, "GroupStopAddress1", 14); IPS_SetProperty($iid, "GroupStopAddress2", 1); IPS_SetProperty($iid, "GroupStopAddress3", ($i*16)+$j); if($j > 0) { $mapping = Array(); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 0, "GroupAddress3" => $i*16 ); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 0, "GroupAddress3" => 240 ); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 0, "GroupAddress3" => 240+$j ); IPS_SetProperty($iid, "GroupMoveMapping", json_encode($mapping)); $mapping = Array(); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 1, "GroupAddress3" => $i*16 ); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 1, "GroupAddress3" => 240 ); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 1, "GroupAddress3" => 240+$j ); IPS_SetProperty($iid, "GroupStopMapping", json_encode($mapping)); } IPS_ApplyChanges($iid); } } } echo "Done."; }
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; }