private function RefreshLinks() { if ($this->ReadPropertyInteger("LinkSource") == 0) { foreach (IPS_GetChildrenIDs($this->InstanceID) as $Child) { if (IPS_GetObject($Child)['ObjectType'] == 6) { IPS_DeleteLink($Child); } } return; } $present = array(); foreach (IPS_GetChildrenIDs($this->InstanceID) as $Child) { if (IPS_GetObject($Child)['ObjectType'] == 6) { $present[] = IPS_GetLink($Child)['TargetID']; } } $create = array_diff(IPS_GetChildrenIDs($this->ReadPropertyInteger("LinkSource")), $present); foreach ($create as $Target) { if (IPS_GetObject($Target)["ObjectIsHidden"]) { continue; } $Link = IPS_CreateLink(); IPS_SetParent($Link, $this->InstanceID); IPS_SetName($Link, IPS_GetName($Target)); IPS_SetLinkTargetID($Link, $Target); } }
public function createGroupWithID($name, $id, $parentID) { $group = @IPS_GetObjectIDByIdent($id, $parentID); if (!$group) { $group = IPS_CreateCategory(); IPS_SetName($group, $name); IPS_SetParent($group, $parentID); IPS_SetIdent($group, $id); $variable = IPS_CreateVariable(0); IPS_SetParent($variable, $group); IPS_SetName($variable, "Turn on"); IPS_SetIdent($variable, "state_" . $id); SetValue($variable, true); $variable = IPS_CreateVariable(1); IPS_SetParent($variable, $group); IPS_SetName($variable, "Delay"); IPS_SetIdent($variable, "delay_" . $id); SetValue($variable, 3600); $childs = IPS_CreateCategory(); IPS_SetName($childs, "Links"); IPS_SetParent($childs, $group); IPS_SetIdent($childs, "childs_" . $id); } return $group; }
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); }
/** * @public * * Initialisierung eines IPSComponentShutter_FS20 Objektes * * @param integer $instanceId InstanceId des FS20 Devices */ public function __construct($instanceId) { $this->instanceId = IPSUtil_ObjectIDByPath($instanceId); $this->isRunningId = @IPS_GetObjectIDByIdent('isrunning', $this->instanceId); if($this->isRunningId===false) { $this->isRunningId = IPS_CreateVariable(0); IPS_SetParent($this->isRunningId, $this->instanceId); IPS_SetName($this->isRunningId, 'IsRunning'); IPS_SetIdent($this->isRunningId, 'isrunning'); IPS_SetInfo($this->isRunningId, "This Variable was created by Script IPSComponentShutter_FS20"); } }
function CheckVariable($name, $vartyp, $profile, $parentID) { $InstanzID = @IPS_GetVariableIDByName($name, $parentID); if ($InstanzID === false) { $InstanzID = IPS_CreateVariable($vartyp); IPS_SetName($InstanzID, $name); // Instanz benennen IPS_SetParent($InstanzID, $parentID); IPS_SetVariableCustomProfile($InstanzID, $profile); } //echo "ID: ".$InstanzID." ".$name."\n"; return $InstanzID; }
function Migrate_Structure($module, $oldPath, $newPath, $filePath) { $oldCategoryId = @get_ObjectIDByPath($oldPath, true); if ($oldCategoryId==null) { echo "$oldPath not found ...\n"; return; } // Download new Module Scripts $moduleManager = new IPSModuleManager($module); //$moduleManager->DeployModule(); $moduleManager->LoadModule(); // Migrate existing Structure CreateCategoryPath($newPath); $newCategoryPath = str_replace('.app.', '.data.', $newPath); $newCategoryId = CreateCategoryPath($newCategoryPath); foreach (IPS_GetChildrenIDs($oldCategoryId) as $idx=>$childId) { $object = IPS_GetObject($childId); switch($object['ObjectType']) { case 0: // Category case 1: // Instance echo "Migrate Category=$childId, Name=".IPS_GetName($childId)."\n"; Migrate_Category($childId, $filePath); IPS_SetParent($childId, $newCategoryId); break; case 2: // Variable echo "Migrate Variable=$childId, Name=".IPS_GetName($childId)."\n"; IPS_SetParent($childId, $newCategoryId); break; case 3: // Script Delete_Script($childId, $filePath); break; default: echo "Unknown Object=$childId, Name=".IPS_GetName($childId)."\n"; } echo "Move $childId from $oldCategoryId to $newCategoryId ($newCategoryPath)\n"; } if (!IPS_DeleteCategory($oldCategoryId)) { echo "Error deleting old Category ".IPS_GetName($oldCategoryId)."\n"; exit; } echo '-------------------------------------------------------------------------------------------------------------'.PHP_EOL; echo '---- Bestehende Variablen von Modul '.$module.' wurden in die neue Strukture migriert'.PHP_EOL; echo '----'.PHP_EOL; echo '---- Anpassung der Konfiguration und erneute Installation muss manuell gemacht werden !!!'.PHP_EOL; echo '---- ACHTUNG: Pfad für WebFront und Mobile Installation haben sich geändert (liegt jetzt unter "Visualization.WebFront"'.PHP_EOL; echo '---- bzw. "Visualization.Mobile". Pfad im Init File (/IPSLibrary/install/InitializationFiles/<<Module>>.ini'.PHP_EOL; echo '---- anpassen oder Links manuell verschieben.'.PHP_EOL; echo '---- Im Zweifel einfach die bestehenden Strukture des jeweiligen Modules löschen, und eine erneute Installation'.PHP_EOL; echo '---- Installation ausführen.'.PHP_EOL; echo '-------------------------------------------------------------------------------------------------------------'.PHP_EOL; }
private function CreateVariableByIdent($id, $ident, $name, $type, $profile = "") { $vid = @IPS_GetObjectIDByIdent($ident, $id); if ($vid === false) { $vid = IPS_CreateVariable($type); IPS_SetParent($vid, $id); IPS_SetName($vid, $name); IPS_SetIdent($vid, $ident); if ($profile != "") { IPS_SetVariableCustomProfile($vid, $profile); } } return $vid; }
/** * constructor * * @throws Exception if $type is not valid * @access public */ public function __construct($parentId, $name, $content, $debug = false) { $this->parentId = $parentId; $this->name = $name; $this->content = $content; $this->debug = $debug; $this->id = @IPS_GetScriptIDByName($this->name, $this->parentId); //check if event does already exist if ($this->id == false) { if ($this->debug) { echo "INFO - create IPS script {$name}\n"; } $this->id = IPS_CreateScript(0); IPS_SetName($this->id, $this->name); IPS_SetParent($this->id, $this->parentId); IPS_SetScriptContent($this->id, $this->content); IPS_SetInfo($this->id, "this script was created by script " . $_IPS['SELF'] . " which is part of the ips-library (https://github.com/florianprobst/ips-library)"); } }
protected function RegisterTimer($ident, $interval, $script) { $id = @IPS_GetObjectIDByIdent($ident, $this->InstanceID); if ($id && IPS_GetEvent($id)['EventType'] <> 1) { IPS_DeleteEvent($id); $id = 0; } if (!$id) { $id = IPS_CreateEvent(1); IPS_SetParent($id, $this->InstanceID); IPS_SetIdent($id, $ident); } IPS_SetName($id, $ident); IPS_SetHidden($id, true); IPS_SetEventScript($id, "\$id = \$_IPS['TARGET'];\n$script;"); if (!IPS_EventExists($id)) throw new Exception("Ident with name $ident is used for wrong object type"); if (!($interval > 0)) { IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, 1); IPS_SetEventActive($id, false); } else { IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, $interval); IPS_SetEventActive($id, true); } }
/** * constructor * * @throws Exception if $type is not valid * @access public */ public function __construct($parentId, $name, $cycle, $debug = false) { $this->parentId = $parentId; $this->name = $name; $this->cycle = $cycle; $this->debug = $debug; $this->id = @IPS_GetEventIDByName($this->name, $this->parentId); //check if event does already exist if ($this->id == false) { if ($this->debug) { echo "INFO - create IPS event {$name}\n"; } $this->id = IPS_CreateEvent(1); //create trigger event and store id IPS_SetName($this->id, $this->name); //set event name IPS_SetParent($this->id, $this->parentId); //move event to parent (this will be called when trigger occurs) IPS_SetEventCyclic($this->id, 0, 1, 0, 0, 1, $cycle); //every $cycle seconds IPS_SetInfo($this->id, "this event was created by script " . $_IPS['SELF'] . " which is part of the ips-library (https://github.com/florianprobst/ips-library)"); $this->activate(); } }
function IPSWatering_ActivateRefreshTimer($Value) { $Name = 'Refresh'; $scriptId_Timer = IPSUtil_ObjectIDByPath('Program.IPSLibrary.app.modules.IPSWatering.IPSWatering_RefreshTimer'); $TimerId = @IPS_GetEventIDByName($Name, $scriptId_Timer); if ($TimerId === false) { $TimerId = IPS_CreateEvent(1 /*Cyclic Event*/); IPS_SetName($TimerId, $Name); IPS_SetParent($TimerId, $scriptId_Timer); if (!IPS_SetEventCyclic($TimerId, 2 /*Daily*/, 1 /*Int*/,0 /*Days*/,0/*DayInt*/,1/*TimeType Sec*/,1/*Sec*/)) { IPSLogger_Err(__file__, "IPS_SetEventCyclic failed for Refresh Timer!!!"); exit; } } if ($Value) { IPS_SetEventActive($TimerId, true); } else { $OneOrMoreCirclesActive = false; $categoryId_Circles = IPSUtil_ObjectIDByPath('Program.IPSLibrary.data.modules.IPSWatering.WaterCircles'); $CircleIds = IPS_GetChildrenIds($categoryId_Circles); foreach($CircleIds as $CircleId) { $OneOrMoreCirclesActive = ($OneOrMoreCirclesActive or GetValue(get_ControlId(c_Control_Active, $CircleId))); } if (!$OneOrMoreCirclesActive) { IPS_SetEventActive($TimerId, false); } } }
/** * constructor * * second constructor: create the variable in symcon if it does not exist * * @param string $name name of the variable * @param integer $type IPS datatype * @param integer $parent id of the variables parent, this defines where the variable will be created * @param mixed $value initially set a variable value * @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 integer $aggregationType logging aggregation: 0 = gauge, 1 = counter * @param boolean $debug enables / disables debug information * * @throws Exception if the parameter \$profile is not an IPSVariableProfile datatype * @access public */ private function __construct2($name, $type, $parent, $profile = NULL, $enableLogging = false, $archiveId = NULL, $aggregationType = 0, $debug = false) { if (isset($profile) && !$profile instanceof IPSVariableProfile) { throw new Exception("Parameter \$profile must be an instance of IPSVariableProfile! \$name of the variable is '{$name}'"); } $this->name = $name; $this->type = $type; $this->parent = $parent; $this->profile = $profile; $this->enableLogging = $enableLogging; $this->archiveId = $archiveId; $this->aggregationType = $aggregationType; $this->debug = $debug; $this->id = @IPS_GetVariableIDByName($name, $parent); if ($this->id == false) { if ($this->debug) { echo "INFO - create IPS variable {$name}\n"; } $this->id = IPS_CreateVariable($this->type); IPS_SetName($this->id, $name); IPS_SetParent($this->id, $parent); IPS_SetInfo($this->id, "this variable was created by script " . $_IPS['SELF'] . " which is part of the ips-library (https://github.com/florianprobst/ips-library)"); if (isset($profile)) { IPS_SetVariableCustomProfile($this->id, $profile->getName()); } $this->verifyVariableLogging(); } }
protected function SetTimerByIdent_InSekunden($ident, $Sekunden) { $eid = @IPS_GetObjectIDByIdent($ident, $this->InstanceID); if ($eid === false) { $eid = IPS_CreateEvent(1); IPS_SetParent($eid, $this->InstanceID); IPS_SetName($eid, $ident); IPS_SetIdent($eid, $ident); IPS_SetEventScript($eid, 'HMON_Benachrichtigung($_IPS[\'TARGET\'], false, true);'); IPS_SetInfo($eid, "this timer was created by script #" . $_IPS['SELF']); } if ($Sekunden === false) { IPS_SetEventActive($eid, false); return $eid; } else { IPS_SetEventCyclicTimeFrom($eid, intval(date("H", time() + $Sekunden)), intval(date("i", time() + $Sekunden)), intval(date("s", time() + $Sekunden))); IPS_SetEventActive($eid, true); return $eid; } }
/** * 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; }
/** * ModBusMaster_WriteCoil * @param boolean $Value * @return boolean */ public function WriteCoil($Value) { if ($this->ReadPropertyBoolean("ReadOnly")) { trigger_error("Address is marked as read-only!", E_USER_WARNING); return; } if ($this->ReadPropertyInteger("DataType") === 0) { $resultat = $this->SendDataToParent(json_encode(array("DataID" => "{A3419A88-C83B-49D7-8706-D3AFD596DFBB}", "FC" => "5", "Address" => $this->ReadPropertyInteger("Address"), "Data" => $Value))); if ($this->ReadPropertyInteger("SwitchDuration") > 0 and $Value) { $eid = @IPS_GetObjectIDByIdent("SwitchDuration", $this->InstanceID); if ($eid === false) { $eid = 0; } else { if (IPS_GetEvent($eid)['EventType'] != 1) { IPS_DeleteEvent($eid); $eid = 0; } } if ($eid == 0) { $eid = IPS_CreateEvent(1); IPS_SetParent($eid, $this->InstanceID); IPS_SetIdent($eid, "SwitchDuration"); IPS_SetName($eid, "SwitchDuration"); IPS_SetHidden($eid, true); IPS_SetEventScript($eid, "ModBusMaster_WriteCoil(\$_IPS['TARGET'], false);IPS_SetEventActive(\$_IPS['EVENT'],false);"); } IPS_SetEventCyclicTimeFrom($eid, date("H"), date("i"), date("s")); IPS_SetEventCyclic($eid, 0, 0, 0, 0, 1, $this->ReadPropertyInteger("SwitchDuration")); IPS_SetEventActive($eid, true); } return $resultat; } else { trigger_error("Invalid DataType!", E_USER_WARNING); } }
protected function RegisterTimer($Name, $Interval, $Script) { $id = @IPS_GetObjectIDByIdent($Name, $this->InstanceID); if ($id === false) { $id = 0; } if ($id > 0) { if (!IPS_EventExists($id)) { throw new Exception("Ident with name " . $Name . " is used for wrong object type"); } if (IPS_GetEvent($id)['EventType'] != 1) { IPS_DeleteEvent($id); $id = 0; } } if ($id == 0) { $id = IPS_CreateEvent(1); IPS_SetParent($id, $this->InstanceID); IPS_SetIdent($id, $Name); } IPS_SetName($id, $Name); IPS_SetHidden($id, true); IPS_SetEventScript($id, $Script); if ($Interval > 0) { IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, $Interval); IPS_SetEventActive($id, true); } else { IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, 1); IPS_SetEventActive($id, false); } }
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; }
protected function CreateLink($Ident, $Name, $Target = 0) { if (!($LinkID = @IPS_GetObjectIdByIdent($Ident, $this->InstanceID))) { $LinkID = IPS_CreateLink(); IPS_SetName($LinkID, $Name); IPS_SetParent($LinkID, $this->InstanceID); IPS_SetIdent($LinkID, $Ident); if ($Target) { IPS_SetLinkTargetID($LinkID, $Target); $EventID = IPS_CreateEvent(0); IPS_SetParent($EventID, $this->InstanceID); // $LinkID); IPS_SetEventTrigger($EventID, 1, $Target); IPS_SetEventScript($EventID, 'PJ_UpdateColor($_IPS[\'TARGET\']);'); } } }
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; } }
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); } }
private function Registerevent121($var5_id, $TargetID) { if (!isset($_IPS)) { global $_IPS; } $EreignisID = @IPS_GetEventIDByName("E_TW", $TargetID); if ($EreignisID == true) { if (IPS_EventExists(IPS_GetEventIDByName("E_TW", $TargetID))) { IPS_DeleteEvent(IPS_GetEventIDByName("E_TW", $TargetID)); } } $eid = IPS_CreateEvent(0); //Ausgelöstes Ereignis IPS_SetName($eid, "E_TW"); IPS_SetEventTrigger($eid, 0, $var5_id); //Bei Änderung von Variable Wandtemp IPS_SetParent($eid, $TargetID); //Ereignis zuordnen IPS_SetEventScript($eid, 'SetValue($_IPS[\'TARGET\'], $_IPS[\'VALUE\']);'); IPS_SetEventActive($eid, true); //Ereignis aktivieren }
public function ApplyChanges() { // get instance id $instanceid = IPS_GetInstance($this->InstanceID)['InstanceID']; // rename instance $room = $this->ReadPropertyString("Room"); if ($room != "") { IPS_SetName($instanceid, $room); } // check device $deviceip = $this->ReadPropertyString("DeviceIP"); $timeout = $this->ReadPropertyString("Timeout"); if ($deviceip != "") { // check device availability if ($timeout && Sys_Ping($deviceip, $timeout) != true) { // throw new Exception("Device ".$deviceip." is not available"); die("Unable to connect to device {$deviceip}"); } include_once __DIR__ . "/bose_soundtouch_api.php"; $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->getDeviceNowPlayingAPI(); // get device id for multiroom $deviceid = $this->ReadPropertyString("DeviceID"); if ($deviceid == "" and $deviceip != "") { $deviceid = $result['deviceid']; IPS_SetProperty($instanceid, "DeviceID", "" . $deviceid . ""); if (IPS_HasChanges($instanceid)) { IPS_ApplyChanges($instanceid); } } } // never delete this line! parent::ApplyChanges(); ///////////////////////////////////////////////////////////////////////////////////////////////////////// // create profiles ///////////////////////////////////////////////////////////////////////////////////////////////////////// //create zone profiles for multiroom $allboseinstances = IPS_GetInstanceListByModuleID("{4836EF46-FF79-4D6A-91C9-FE54F1BDF2DB}"); // create profile for each instance / device foreach ($allboseinstances as $key => $instanceid) { $multiroomprofilename = "bose.Device" . $instanceid . "MasterZones"; // delete zone profiles if (IPS_VariableProfileExists($multiroomprofilename)) { IPS_DeleteVariableProfile($multiroomprofilename); } IPS_CreateVariableProfile($multiroomprofilename, 1); // set values for profile foreach ($allboseinstances as $key => $value) { if ($instanceid == $value) { IPS_SetVariableProfileAssociation($multiroomprofilename, "0", "Off", "", 0xff); } else { $instancename = IPS_GetName($value); if ($instancename != "") { IPS_SetVariableProfileAssociation($multiroomprofilename, "" . ($key + 1) . "", "" . $instancename . "", "", 0xff); } } } } // create volume slider profile $volumesliderprofilename = "bose.VolumeSlider"; if (!IPS_VariableProfileExists($volumesliderprofilename)) { IPS_CreateVariableProfile($volumesliderprofilename, 1); } IPS_SetVariableProfileValues($volumesliderprofilename, 0, 100, 1); IPS_SetVariableProfileText($volumesliderprofilename, "", "%"); IPS_SetVariableProfileIcon($volumesliderprofilename, "Speaker"); // play pause preset $playpauseprofilename = "bose.PlayPause"; if (!IPS_VariableProfileExists($playpauseprofilename)) { IPS_CreateVariableProfile($playpauseprofilename, 1); } IPS_SetVariableProfileAssociation($playpauseprofilename, "0", "Pause", "", 0xff); IPS_SetVariableProfileAssociation($playpauseprofilename, "1", "Play", "", 0xff); IPS_SetVariableProfileIcon($playpauseprofilename, "HollowArrowRight"); // create presets and radiolocations profiles $instanceid = IPS_GetInstance($this->InstanceID)['InstanceID']; $radiostationsprofilename = "bose.Device" . $instanceid . "RadioStations"; if (!IPS_VariableProfileExists($radiostationsprofilename)) { IPS_CreateVariableProfile($radiostationsprofilename, 1); } $radiolocationsprofilename = "bose.Device" . $instanceid . "RadioLocations"; if (!IPS_VariableProfileExists($radiolocationsprofilename)) { IPS_CreateVariableProfile($radiolocationsprofilename, 1); } // get device presets if ($deviceip != "") { include_once __DIR__ . "/bose_soundtouch_api.php"; $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->getDevicePresetsAPI(); for ($i = 0; $i < 6; $i++) { $value = $i + 1; $radiostationname = $result->preset[$i]->ContentItem->itemName; $radiostationlocation = $result->preset[$i]->ContentItem["location"]; IPS_SetVariableProfileAssociation($radiostationsprofilename, "" . $value . "", "" . $radiostationname . "", "", 0xff); IPS_SetVariableProfileAssociation($radiolocationsprofilename, "" . $value . "", "" . $radiostationlocation . "", "", 0xff); } IPS_SetVariableProfileIcon($radiostationsprofilename, "Cloud"); } // create timer hour profile $timerhourprofilename = "bose.TimerHour"; if (!IPS_VariableProfileExists($timerhourprofilename)) { IPS_CreateVariableProfile($timerhourprofilename, 1); } $i = 0; for ($i = 0; $i < 24; $i++) { IPS_SetVariableProfileAssociation($timerhourprofilename, $i, $i, "", 0xff); } IPS_SetVariableProfileIcon($timerhourprofilename, "Clock"); // create timer minute profile $timerminuteprofilename = "bose.TimerMinute"; if (!IPS_VariableProfileExists($timerminuteprofilename)) { IPS_CreateVariableProfile($timerminuteprofilename, 1); } $i = 0; for ($i = 0; $i <= 55; $i = $i + 5) { IPS_SetVariableProfileAssociation($timerminuteprofilename, $i, $i, "", 0xff); } IPS_SetVariableProfileIcon($timerminuteprofilename, "Clock"); ///////////////////////////////////////////////////////////////////////////////////////////////////////// // register variables ///////////////////////////////////////////////////////////////////////////////////////////////////////// // device power $this->RegisterVariableBoolean("DevicePower", "Device Power", "~Switch", 1); $this->EnableAction("DevicePower"); SetValue($this->GetIDForIdent("DevicePower"), 0); // volume slider $this->RegisterVariableInteger("VolumeSlider", "Volume", "bose.VolumeSlider", 2); $this->EnableAction("VolumeSlider"); SetValue($this->GetIDForIdent("VolumeSlider"), 10); // play pause $this->RegisterVariableInteger("PlayPause", "Play / Pause", "bose.PlayPause", 3); $this->EnableAction("PlayPause"); SetValue($this->GetIDForIdent("PlayPause"), true); // join zone (multiroom) $instanceid = IPS_GetInstance($this->InstanceID)['InstanceID']; $this->RegisterVariableInteger("JoinZone", "Join Zone (MultiRoom)", "bose.Device" . $instanceid . "MasterZones", 4); $this->EnableAction("JoinZone"); IPS_SetIcon($this->GetIDForIdent("JoinZone"), "Network"); SetValue($this->GetIDForIdent("JoinZone"), 0); // radio $this->RegisterVariableInteger("Radio", "Radio", "bose.Device" . $instanceid . "RadioStations", 5); $this->EnableAction("Radio"); SetValue($this->GetIDForIdent("Radio"), 1); // device mode $this->RegisterVariableString("DeviceMode", "Device Mode", "", 7); IPS_SetIcon($this->GetIDForIdent("DeviceMode"), "Information"); // device state $this->RegisterVariableString("DeviceState", "Device State", "", 8); IPS_SetIcon($this->GetIDForIdent("DeviceState"), "Information"); // now playing $this->RegisterVariableString("NowPlaying", "Now Playing", "", 9); IPS_SetIcon($this->GetIDForIdent("NowPlaying"), "Information"); // description $this->RegisterVariableString("Description", "Description", "", 10); IPS_SetIcon($this->GetIDForIdent("Description"), "Information"); // logo $this->RegisterVariableString("Logo", "Logo", "~HTMLBox", 11); IPS_SetIcon($this->GetIDForIdent("Logo"), "Information"); // timer hour $this->RegisterVariableInteger("TimerHour", "Timer Hour", "bose.TimerHour", 12); $this->EnableAction("TimerHour"); SetValue($this->GetIDForIdent("TimerHour"), 12); // timer minute $this->RegisterVariableInteger("TimerMinute", "Timer Minute", "bose.TimerMinute", 13); $this->EnableAction("TimerMinute"); SetValue($this->GetIDForIdent("TimerMinute"), 0); // alarm clock $this->RegisterVariableBoolean("AlarmClock", "Alarm Clock", "~Switch", 14); $this->EnableAction("AlarmClock"); SetValue($this->GetIDForIdent("AlarmClock"), false); // volume fade in $this->RegisterVariableBoolean("VolumeFadeIn", "Volume Fade In (15 min)", "~Switch", 15); $this->EnableAction("VolumeFadeIn"); SetValue($this->GetIDForIdent("VolumeFadeIn"), false); // next power on $this->RegisterVariableString("NextPowerOn", "Next Power On", "", 16); IPS_SetIcon($this->GetIDForIdent("NextPowerOn"), "Information"); // alarm cycle IPS_SetHidden($this->RegisterVariableString("AlarmCycle", "Alarm Cycle", "", 17), true); SetValue($this->GetIDForIdent("AlarmCycle"), 0); // alarm radio station IPS_SetHidden($this->RegisterVariableString("AlarmRadioStation", "Alarm Radio Station", "", 18), true); SetValue($this->GetIDForIdent("VolumeFadeIn"), false); // alarm clock volume IPS_SetHidden($this->RegisterVariableInteger("AlarmClockVolume", "Alarm Clock Volume", "bose.VolumeSlider", 19), true); SetValue($this->GetIDForIdent("AlarmRadioStation"), ""); // sleep timer $this->RegisterVariableBoolean("SleepTimer", "Sleep Timer", "~Switch", 20); $this->EnableAction("SleepTimer"); SetValue($this->GetIDForIdent("SleepTimer"), false); // volume fade out $this->RegisterVariableBoolean("VolumeFadeOut", "Volume Fade Out (15 min)", "~Switch", 21); $this->EnableAction("VolumeFadeOut"); SetValue($this->GetIDForIdent("VolumeFadeOut"), false); // good night $this->RegisterVariableBoolean("GoodNight", "Good Night (30 min)", "~Switch", 22); IPS_SetIcon($this->GetIDForIdent("GoodNight"), "Moon"); $this->EnableAction("GoodNight"); SetValue($this->GetIDForIdent("GoodNight"), false); // next power off $this->RegisterVariableString("NextPowerOff", "Next Power Off", "", 23); IPS_SetIcon($this->GetIDForIdent("NextPowerOff"), "Information"); SetValue($this->GetIDForIdent("NextPowerOff"), ""); // sleep cycle IPS_SetHidden($this->RegisterVariableString("SleepCycle", "Sleep Cycle", "", 24), true); SetValue($this->GetIDForIdent("SleepCycle"), 0); ///////////////////////////////////////////////////////////////////////////////////////////////////////// // create scripts ///////////////////////////////////////////////////////////////////////////////////////////////////////// // device information script $DeviceInformationControlScript = '<? /* SymconBoseSoundTouch Bose SoundTouch Module for IP-Symcon filename: DeviceInformationControl.php description: Device Information Control Script version 1.0.1 date: 13.01.2016 publisher: Copyright (c) 2015, 2016 Ulrich Bittner license: CC BY-NC 4.0 Creative Commons Attribution-NonCommercial 4.0 International License environment: IP-Symcon 4.0 (beta) on RPi changelog: version 1.0.1 13.01.2016 multiroom fix for single device version 1.0.0 28.12.2015 initialscript todo: (none) github: https://github.com/ubittner/SymconBoseSoundTouch.git symcon forum: https://www.symcon.de/forum/threads/29922-Bose-SoundTouch-Modul */ if ($_IPS["SENDER"] == "Execute") { addRadioStations(); } if ($_IPS["SENDER"] == "TimerEvent") { getDeviceInformation(); } function addRadioStations() { // Radio Stations // if you want less radio stations, delete the unnecessary positions // if you want to have more radio stations, add positions // get the radio station location id from www.vtuner.com // http://vtuner.com/setupapp/guide/asp/BrowseStations/startpage.asp // example for WDR 2 Ruhrgebiet // url: http://www.vtuner.com/vtunerweb/mms/m3u32760.m3u // location = 32760 // Radio Station 7 $RadioStations["station7"]["name"] = "AH.FM"; $RadioStations["station7"]["location"] = "24836"; // Radio Station 8 $RadioStations["station8"]["name"] = "Sunshine Live Classics"; $RadioStations["station8"]["location"] = "44882"; // Radio Station 9 $RadioStations["station9"]["name"] = "Sunshine Live Trance"; $RadioStations["station9"]["location"] = "48651"; // Radio Station 10 $RadioStations["station10"]["name"] = "Sunshine Live Be Easy"; $RadioStations["station10"]["location"] = "44879"; // Radio Station 11 $RadioStations["station11"]["name"] = "Sunshine Live Be DJ"; $RadioStations["station11"]["location"] = "44881"; // Radio Station 12 $RadioStations["station12"]["name"] = "Sunshine Live Radioclub"; $RadioStations["station12"]["location"] = "62373"; // Radio Station 13 $RadioStations["station13"]["name"] = "SPORT1.fm"; $RadioStations["station13"]["location"] = "52773"; // Radio Station 14 $RadioStations["station14"]["name"] = "SPORT1.fm Spiel1"; $RadioStations["station14"]["location"] = "53341"; // Radio Station 15 $RadioStations["station15"]["name"] = "SPORT1.fm Spiel2"; $RadioStations["station15"]["location"] = "53343"; // Radio Station 16 $RadioStations["station16"]["name"] = "SPORT1.fm Spiel3"; $RadioStations["station16"]["location"] = "53344"; // Radio Station 17 $RadioStations["station17"]["name"] = "SPORT1.fm Spiel4"; $RadioStations["station17"]["location"] = "53346"; // Radio Station 18 $RadioStations["station18"]["name"] = "SPORT1.fm Spiel5"; $RadioStations["station18"]["location"] = "53347"; // Radio Station 19 $RadioStations["station19"]["name"] = "SPORT1.fm Spiel6"; $RadioStations["station19"]["location"] = "53349"; // Radio Station 20 $RadioStations["station20"]["name"] = "WDR2 Ruhrgebiet"; $RadioStations["station20"]["location"] = "32760"; // Radio Station 21 $RadioStations["station21"]["name"] = "BFBS Germany"; $RadioStations["station21"]["location"] = "35142"; // extend radio station and radio location profile $instanceid = IPS_GetParent($_IPS["SELF"]); $presetprofilename = "bose.Device".$instanceid."RadioStations"; $radiolocationsprofilename = "bose.Device".$instanceid."RadioLocations"; $variable = $RadioStations; $i = 7; foreach ($variable as $key => $value) { $radiostationname = $value["name"]; $radiostationlocation = $value["location"]; IPS_SetVariableProfileAssociation($presetprofilename, "".$i."", "".$radiostationname."", "", 0x0000FF); IPS_SetVariableProfileAssociation($radiolocationsprofilename, "".$i."", "".$radiostationlocation."", "", 0x0000FF); $i++; } } function getDeviceInformation() { $deviceip = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "DeviceIP"); $timeout = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "Timeout"); $instanceid = IPS_GetParent($_IPS["SELF"]); if ($deviceip == "") { die; } try { // check device availibility if ($timeout && Sys_Ping($deviceip, $timeout) != true) { throw new Exception("Device ".$deviceip." is not available"); } include_once("../modules/SymconBoseSoundTouch/Bose/bose_soundtouch_api.php"); $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->getDeviceNowPlayingAPI(); // power switch if ($result["devicemode"] == "Standby") { $powerstate = false; } else { $powerstate = true; } $powerswitch = GetValue(IPS_GetObjectIDByName("Device Power", IPS_GetParent($_IPS["SELF"]))); if ($powerstate <> $powerswitch) { SetValue(IPS_GetObjectIDByName("Device Power", IPS_GetParent($_IPS["SELF"])), $powerstate); } // device mode $devicemode = GetValue(IPS_GetObjectIDByName("Device Mode", IPS_GetParent($_IPS["SELF"]))); if ($result["devicemode"] <> $devicemode) { SetValue(IPS_GetObjectIDByName("Device Mode", IPS_GetParent($_IPS["SELF"])), $result["devicemode"]); } // device state $devicestate = GetValue(IPS_GetObjectIDByName("Device State", IPS_GetParent($_IPS["SELF"]))); if ($result["devicestate"] <> $devicestate) { SetValue(IPS_GetObjectIDByName("Device State", IPS_GetParent($_IPS["SELF"])), $result["devicestate"]); } // now playing $nowplaying = GetValue(IPS_GetObjectIDByName("Now Playing", IPS_GetParent($_IPS["SELF"]))); if ($result["nowplaying"] <> $nowplaying) { SetValue(IPS_GetObjectIDByName("Now Playing", IPS_GetParent($_IPS["SELF"])), $result["nowplaying"]); $instanceid = IPS_GetParent($_IPS["SELF"]); $associations = IPS_GetVariableProfile("bose.Device".$instanceid."RadioStations")["Associations"]; $index = 0; foreach($associations as $key => $value) { if ($value["Name"] == $result["nowplaying"]) { $index = $value["Value"]; } } if ($index <> 0){ SetValue(IPS_GetObjectIDByName("Radio", IPS_GetParent($_IPS["SELF"])), $index); } } // description $description = GetValue(IPS_GetObjectIDByName("Description", IPS_GetParent($_IPS["SELF"]))); if ($result["description"] <> $description) { SetValue(IPS_GetObjectIDByName("Description", IPS_GetParent($_IPS["SELF"])), $result["description"]); } // logo $logo = GetValue(IPS_GetObjectIDByName("Logo", IPS_GetParent($_IPS["SELF"]))); if ($result["logourl"] <> $logo) { SetValue(IPS_GetObjectIDByName("Logo", IPS_GetParent($_IPS["SELF"])), $result["logourl"]); } // volume $result = $bosedevice->getDeviceVolumeAPI(); $volumeslider = GetValue(IPS_GetObjectIDByName("Volume", IPS_GetParent($_IPS["SELF"]))); if ($result["actualvolume"] <> $volumeslider) { SetValue(IPS_GetObjectIDByName("Volume", IPS_GetParent($_IPS["SELF"])), $result["actualvolume"]); } // zone $allboseinstances = IPS_GetInstanceListByModuleID("{4836EF46-FF79-4D6A-91C9-FE54F1BDF2DB}"); $numberofdevices = count($allboseinstances); if ($numberofdevices >1) { $result = $bosedevice->getDeviceZoneAPI(); $zonemasterid = $result["zonemasterid"]; $zonememberid = $result["zonememberid"]; $deviceid = IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "DeviceID"); $zonemembers = $result["zonememberid"]; $zonemember = false; $masterzone = 0; foreach ($zonemembers as $key => $value) { // device is member if ($value == $deviceid) { // device is the master if ($zonemasterid == $deviceid) { $masterzone = 0; } // get zone master else { $allboseinstances = IPS_GetInstanceListByModuleID("{4836EF46-FF79-4D6A-91C9-FE54F1BDF2DB}"); foreach ($allboseinstances as $key => $value) { $masterdeviceid = IPS_GetProperty($value, "DeviceID"); if ($masterdeviceid == $zonemasterid) { $zonemastername = IPS_GetName($value); } } $associations = IPS_GetVariableProfile("bose.Device".$instanceid."MasterZones")["Associations"]; foreach($associations as $key => $value) { if ($value["Name"] == $zonemastername) { $masterzone = $value["Value"]; } } } } } $zonestate = GetValue(IPS_GetObjectIDByName("Join Zone (MultiRoom)", IPS_GetParent($_IPS["SELF"]))); if ($masterzone <> $zonestate) { SetValue(IPS_GetObjectIDByName("Join Zone (MultiRoom)", IPS_GetParent($_IPS["SELF"])), $masterzone); } } } // error message catch (Exception $e) { echo $e->getMessage(); } } ?>'; // create script $deviceinformationcontrolscriptid = @$this->GetIDForIdent("DeviceInformationControl"); if ($deviceinformationcontrolscriptid === false) { $deviceinformationcontrolscriptid = $this->RegisterScript("DeviceInformationControl", "DeviceInformationControl", $DeviceInformationControlScript, 0); } else { IPS_SetScriptContent($deviceinformationcontrolscriptid, $DeviceInformationControlScript); } IPS_SetHidden($deviceinformationcontrolscriptid, true); IPS_SetScriptTimer($deviceinformationcontrolscriptid, 5); // alarm clock script $AlarmClockControlScript = '<? /* SymconBoseSoundTouch Bose SoundTouch Module for IP-Symcon filename: AlarmClockControl.php description: Alarm Clock Control Script version 1.0.0 date: 28.12.2015 publisher: Copyright (c) 2015, 2016 Ulrich Bittner license: CC BY-NC 4.0 Creative Commons Attribution-NonCommercial 4.0 International License environment: IP-Symcon 4.0 (beta) on RPi changelog: version 1.0.0 28.12.2015 initialscript todo: (none) github: https://github.com/ubittner/SymconBoseSoundTouch.git symcon forum: https://www.symcon.de/forum/threads/29922-Bose-SoundTouch-Modul */ // variable definitions $instanceid = IPS_GetParent(IPS_GetParent($_IPS["SELF"])); $deviceip = IPS_GetProperty($instanceid, "DeviceIP"); $timeout = IPS_GetProperty($instanceid, "Timeout"); $alarmclockscriptid = IPS_GetScriptIDByName("AlarmClockControl", IPS_GetParent($_IPS["SELF"])); $alarmclockeventid = @IPS_GetEventIDByName("AlarmClockEvent", $alarmclockscriptid); $alarmclockcycleseconds = GetValue(IPS_GetObjectIDByName("Alarm Cycle", $instanceid)); // get actual device mode try { // check device availibility if ($timeout && Sys_Ping($deviceip, $timeout) != true) { throw new Exception("Device ".$deviceip." is not available"); } include_once("../modules/SymconBoseSoundTouch/Bose/bose_soundtouch_api.php"); $bosedevice = new BoseSoundTouchAPI($deviceip); // get device mode $result = $bosedevice->getDeviceNowPlayingAPI(); $devicemode = $result["devicemode"]; // get volume $result = $bosedevice->getDeviceVolumeAPI(); SetValue(IPS_GetObjectIDByName("Volume", $instanceid), $result["actualvolume"]); // power device on if ($devicemode == "Standby"){ $result = $bosedevice->powerDeviceAPI(); // set radio station $alarmradiostation = GetValue(IPS_GetObjectIDByName("Alarm Radio Station", $instanceid)); SetValue(IPS_GetObjectIDByName("Radio", $instanceid), $alarmradiostation); $associations = IPS_GetVariableProfile("bose.Device".$instanceid."RadioLocations")["Associations"]; foreach($associations as $key => $value) { if ($value["Value"] == $alarmradiostation) { $location = $value["Name"]; } } $result = $bosedevice->setDeviceRadioStationAPI($location); if ($alarmclockcycleseconds <> 0) { $volume = 1; $result = $bosedevice->setDeviceVolumeAPI($volume); SetValue(IPS_GetObjectIDByName("Volume", $instanceid), $volume); setNewEventCycleTime(); } else { switchAlarmClockOff(); } SetValue(IPS_GetObjectIDByName("Device Power", $instanceid), true); // get now playing getnowplaying: $result = $bosedevice->getDevicenowPlayingAPI(); if ($result["devicestate"] == "Reload") { goto getnowplaying; } SetValue(IPS_GetObjectIDByName("Device Mode", $instanceid), $result["devicemode"]); SetValue(IPS_GetObjectIDByName("Device State", $instanceid), $result["devicestate"]); SetValue(IPS_GetObjectIDByName("Now Playing", $instanceid), $result["nowplaying"]); SetValue(IPS_GetObjectIDByName("Description", $instanceid), $result["description"]); SetValue(IPS_GetObjectIDByName("Logo", $instanceid), $result["logourl"]); } // device is already on else { if ($alarmclockcycleseconds <> 0) { $actualvolume = GetValue(IPS_GetObjectIDByName("Volume", $instanceid)); $alarmclockvolume = GetValue(IPS_GetObjectIDByName("Alarm Clock Volume", $instanceid)); if ($actualvolume < $alarmclockvolume) { $targetvolume = ($actualvolume+1); $result = $bosedevice->setDeviceVolumeAPI($targetvolume); SetValue(IPS_GetObjectIDByName("Volume", $instanceid), $targetvolume); setNewEventCycleTime(); } else { switchAlarmClockOff(); } } } } // error message catch (Exception $e) { echo $e->getMessage(); } // set new event cycle time function setNewEventCycleTime() { global $alarmclockeventid, $alarmclockcycleseconds; $eventinfo = IPS_GetEvent($alarmclockeventid); $eventtimestamp = ($eventinfo["NextRun"]); $neweventtimestamp = strtotime("+ " .$alarmclockcycleseconds. " seconds", $eventtimestamp); $newhour = date("H",$neweventtimestamp); $newminute = date("i",$neweventtimestamp); $newsecond = date("s",$neweventtimestamp); IPS_SetEventCyclicTimeFrom($alarmclockeventid, $newhour, $newminute, $newsecond); IPS_SetEventActive($alarmclockeventid, true); } // switch alarm clock off function switchAlarmClockOff() { global $instanceid, $alarmclockeventid; SetValue(IPS_GetObjectIDByName("Alarm Clock", $instanceid), false); IPS_SetEventActive($alarmclockeventid, false); SetValue(IPS_GetObjectIDByName("Alarm Cycle", $instanceid), 0); SetValue(IPS_GetObjectIDByName("Next Power On", $instanceid), ""); } ?>'; // create script $alarmclockvariableid = @$this->GetIDForIdent("AlarmClock"); $alarmclockcontrolscriptid = @IPS_GetScriptIDByName("AlarmClockControl", $alarmclockvariableid); if ($alarmclockcontrolscriptid === false) { $alarmclockcontrolscriptid = $this->RegisterScript("AlarmClockControl", "AlarmClockControl", $AlarmClockControlScript, 0); } else { IPS_SetScriptContent($alarmclockcontrolscriptid, $AlarmClockControlScript); } IPS_SetParent($alarmclockcontrolscriptid, $alarmclockvariableid); IPS_SetHidden($alarmclockcontrolscriptid, true); $alarmclockscripteventid = @IPS_GetEventIDByName("AlarmClockEvent", $alarmclockcontrolscriptid); if ($alarmclockscripteventid == false) { $alarmclockscripteventid = IPS_CreateEvent(1); IPS_SetParent($alarmclockscripteventid, $alarmclockcontrolscriptid); IPS_SetName($alarmclockscripteventid, "AlarmClockEvent"); } // SleepTimer Script $SleepTimerControlScript = '<? /* SymconBoseSoundTouch Bose SoundTouch Module for IP-Symcon filename: SleepTimerControl.php description: Sleep Timer Control Script version 1.0.0 date: 28.12.2015 publisher: Copyright (c) 2015, 2016 Ulrich Bittner license: CC BY-NC 4.0 Creative Commons Attribution-NonCommercial 4.0 International License environment: IP-Symcon 4.0 (beta) on RPi changelog: version 1.0.0 28.12.2015 initialscript todo: (none) github: https://github.com/ubittner/SymconBoseSoundTouch.git symcon forum: https://www.symcon.de/forum/threads/29922-Bose-SoundTouch-Modul */ $instanceid = IPS_GetParent(IPS_GetParent($_IPS["SELF"])); $deviceip = IPS_GetProperty($instanceid, "DeviceIP"); $timeout = IPS_GetProperty($instanceid, "Timeout"); $sleepcycle = GetValue(IPS_GetObjectIDByName("Sleep Cycle", $instanceid)); $sleeptimerscriptid = IPS_GetScriptIDByName("SleepTimerControl", IPS_GetParent($_IPS["SELF"])); $sleeptimereventid = @IPS_GetEventIDByName("SleepTimerEvent", $sleeptimerscriptid); include_once("../modules/SymconBoseSoundTouch/Bose/bose_soundtouch_api.php"); try { // check device availibility if ($timeout && Sys_Ping($deviceip, $timeout) != true) { throw new Exception("Device ".$deviceip." is not available"); } $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->getDevicenowPlayingAPI(); // device is on if ($result["devicestate"] == "Play"){ if ($sleepcycle <> 0) { decreaseVolume(); } else { switchDeviceOff(); } } // device is already off else { resetValues(); } } // error message catch (Exception $e) { echo $e->getMessage(); } // decrease volume function decreaseVolume() { global $deviceip, $timeout, $sleeptimereventid, $instanceid, $sleepcycle; try { // check device availibility if ($timeout && Sys_Ping($deviceip, $timeout) != true) { throw new Exception("Device ".$deviceip." is not available"); } $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->getDeviceVolumeAPI(); if ($result["actualvolume"] == 1) { switchDeviceOff(); IPS_SetEventActive($sleeptimereventid, false); } else { $volume = ($result["actualvolume"])-1; $setvolume = $bosedevice->setDeviceVolumeAPI($volume); SetValue(IPS_GetObjectIDByName("Volume", $instanceid), $volume); $eventinfo = IPS_GetEvent($sleeptimereventid); $eventtimestamp = ($eventinfo["NextRun"]); $neweventtimestamp = strtotime("+ " . $sleepcycle . " seconds", $eventtimestamp); $newhour = date("H",$neweventtimestamp); $newminute = date("i",$neweventtimestamp); $newsecond = date("s",$neweventtimestamp); IPS_SetEventCyclicTimeFrom($sleeptimereventid, $newhour, $newminute, $newsecond); } } // error message catch (Exception $e) { echo $e->getMessage(); } } // switch device off function switchDeviceOff() { global $deviceip, $timeout; // power off try { if ($timeout && Sys_Ping($deviceip, $timeout) != true) { throw new Exception("Device ".$deviceip." is not available"); } $bosedevice = new BoseSoundTouchAPI($deviceip); $result = $bosedevice->powerDeviceAPI(); resetValues(); } // error message catch (Exception $e) { echo $e->getMessage(); } } // reset values function resetValues() { global $instanceid, $sleeptimereventid; SetValue(IPS_GetObjectIDByName("Device Power", $instanceid), false); SetValue(IPS_GetObjectIDByName("Device Mode", $instanceid), ""); SetValue(IPS_GetObjectIDByName("Device State", $instanceid), ""); SetValue(IPS_GetObjectIDByName("Now Playing", $instanceid), ""); SetValue(IPS_GetObjectIDByName("Description", $instanceid), ""); SetValue(IPS_GetObjectIDByName("Logo", $instanceid), ""); SetValue(IPS_GetObjectIDByName("Sleep Timer", $instanceid), false); SetValue(IPS_GetObjectIDByName("Volume Fade Out (15 min)", $instanceid), false); SetValue(IPS_GetObjectIDByName("Good Night (30 min)", $instanceid), false); SetValue(IPS_GetObjectIDByName("Sleep Cycle", $instanceid), 0); SetValue(IPS_GetObjectIDByName("Next Power Off", $instanceid), ""); IPS_SetEventActive($sleeptimereventid, false); } ?>'; $sleeptimervariableid = @$this->GetIDForIdent("SleepTimer"); $sleeptimercontrolscriptid = @IPS_GetScriptIDByName("SleepTimerControl", $sleeptimervariableid); if ($sleeptimercontrolscriptid === false) { $sleeptimercontrolscriptid = $this->RegisterScript("SleepTimerControl", "SleepTimerControl", $SleepTimerControlScript, 0); } else { IPS_SetScriptContent($sleeptimercontrolscriptid, $SleepTimerControlScript); } IPS_SetParent($sleeptimercontrolscriptid, $sleeptimervariableid); IPS_SetHidden($sleeptimercontrolscriptid, true); $sleeptimerscripteventid = @IPS_GetEventIDByName("SleepTimerEvent", $sleeptimercontrolscriptid); if ($sleeptimerscripteventid == false) { $sleeptimerscripteventid = IPS_CreateEvent(1); IPS_SetParent($sleeptimerscripteventid, $sleeptimercontrolscriptid); IPS_SetName($sleeptimerscripteventid, "SleepTimerEvent"); } }
/** * 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; }
/** * 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; } }
/** * constructor * * @throws Exception if $type is not valid * @access public */ public function __construct($parentId, $trigger, $type, $name, $debug = false) { if (!($type == self::tUPDATE || $type == self::tCHANGE || $type == self::tCAP || $type == self::tFLOOR || $type == self::tVALUE)) { throw new Exception("Parameter \$type must be a valid trigger event type, see ip symcon documentation"); } if ($type == self::tCAP || $type == self::tFLOOR || $type == self::tVALUE) { throw new Exception("Only TriggerEvents of type UPDATE and CHANGE are implemented yet."); } $this->parentId = $parentId; $this->trigger = $trigger; $this->type = $type; $this->name = $name; $this->debug = $debug; $this->id = @IPS_GetEventIDByName($this->name, $this->parentId); //check if event does already exist if ($this->id == false) { if ($this->debug) { echo "INFO - create IPS event {$name}\n"; } $this->id = IPS_CreateEvent(0); //create trigger event and store id IPS_SetName($this->id, $this->name); //set event name IPS_SetEventTrigger($this->id, $this->type, $this->trigger); //configure event trigger IPS_SetParent($this->id, $this->parentId); //move event to parent (this will be called when trigger occurs) IPS_SetInfo($this->id, "this event was created by script " . $_IPS['SELF'] . " which is part of the ips-library (https://github.com/florianprobst/ips-library)"); $this->activate(); } }
function GetOrCreateScript($parent, $ident) { $ObjId = @IPS_GetObjectIDByIdent($ident, $parent); if ($ObjId === false) { $ObjId = IPS_CreateScript(0); IPS_SetParent($ObjId, $parent); IPS_SetIdent($ObjId, $ident); IPS_SetName($ObjId, $ident); IPS_SetScriptContent($ObjId, ScriptContent($ident)); } return $ObjId; }
protected function RegisterTimer($Name, $Interval, $Script) { $id = @IPS_GetObjectIDByIdent($Name, $this->InstanceID); if ($id === false) { $id = IPS_CreateEvent(1); IPS_SetParent($id, $this->InstanceID); IPS_SetIdent($id, $Name); } IPS_SetName($id, $Name); IPS_SetHidden($id, true); IPS_SetEventScript($id, $Script); if ($Interval > 0) { IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, $Interval); IPS_SetEventActive($id, true); } else { IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, 1); IPS_SetEventActive($id, false); } }
public function GenerateMediaObjectEx(string $Text, int $MediaID, string $Format, string $Codec, string $Language) { if ($MediaID == 0) { $MediaID = @IPS_GetObjectIDByIdent('Voice', $this->InstanceID); } if ($MediaID > 0) { if (IPS_MediaExists($MediaID) === false) { trigger_error('MediaObject not exists.', E_USER_NOTICE); } return false; if (IPS_GetMedia($MediaID)['MediaType'] != 2) { trigger_error('Wrong MediaType', E_USER_NOTICE); } return false; } $raw = $this->LoadTTSFile($Text, '', 0, $Format, $Codec, $Language, true); if ($raw === false) { return false; } if ($MediaID === false) { $MediaID = IPS_CreateMedia(2); IPS_SetMediaCached($MediaID, true); IPS_SetName($MediaID, 'Voice'); IPS_SetParent($MediaID, $this->InstanceID); IPS_SetIdent($MediaID, 'Voice'); } $Filename = 'media' . DIRECTORY_SEPARATOR . $MediaID . '.' . strtolower($Codec); IPS_SetMediaFile($MediaID, $Filename, False); IPS_SetMediaContent($MediaID, base64_encode($raw)); IPS_SetInfo($MediaID, $Text); return $MediaID; }
/** * 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; }