/** * 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 * * @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(); } }
/** * overloaded function to maintain variables and timer */ protected function SetStatusVariables() { parent::SetStatusVariables(); $caps = $this->GetCaps(); if (count($caps) < 1) { return; } if (!isset($caps['Timer'])) { $tid = @IPS_GetEventIDByName("DeviceTimer", $this->InstanceID); if ($tid > 0) { IPS_LogMessage(__CLASS__, __FUNCTION__ . "Drop DeviceTimer ({$tid})"); IPS_DeleteEvent($tid); } } }
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 toogleGoodNight() { $goodnightstate = GetValue($this->GetIDForIdent("GoodNight")); $sleeptimerstate = GetValue($this->GetIDForIdent("SleepTimer")); $sleeptimervariableid = @$this->GetIDForIdent("SleepTimer"); $sleeptimercontrolscriptid = @IPS_GetScriptIDByName("SleepTimerControl", $sleeptimervariableid); $sleeptimercontrolscripteventid = @IPS_GetEventIDByName("SleepTimerEvent", $sleeptimercontrolscriptid); if ($goodnightstate == false and $sleeptimerstate == false) { SetValue($this->GetIDForIdent("GoodNight"), true); SetValue($this->GetIDForIdent("VolumeFadeOut"), true); // set event $timenow = time(); $timestamp = strtotime('+900 seconds', $timenow); $nextpowerofftime = strtotime('+1800 seconds', $timenow); $hour = date("H", $timestamp); $minute = date("i", $timestamp); $second = date("s", $timestamp); IPS_SetEventCyclicTimeFrom($sleeptimercontrolscripteventid, $hour, $minute, $second); IPS_SetEventActive($sleeptimercontrolscripteventid, true); // set next power off $day = date("l", $nextpowerofftime); $date = date("d.m.Y", $nextpowerofftime); $time = date("H:i:s", $nextpowerofftime); $nextpoweroff = $day . ", " . $date . ", " . $time; SetValue($this->GetIDForIdent("NextPowerOff"), $nextpoweroff); // calculate cycle time $fadeoutseconds = 900; $actualvolume = GetValue($this->GetIDForIdent("VolumeSlider")); $cycletime = floor(900 / ($actualvolume - 1)); SetValue($this->GetIDForIdent("SleepCycle"), $cycletime); } if ($goodnightstate == true and $sleeptimerstate == false) { IPS_SetEventActive($sleeptimercontrolscripteventid, false); SetValue($this->GetIDForIdent("VolumeFadeOut"), false); SetValue($this->GetIDForIdent("GoodNight"), false); SetValue($this->GetIDForIdent("SleepCycle"), 0); SetValue($this->GetIDForIdent("NextPowerOff"), ""); } }
function CreateTimer ($Name, $Parent, $Hour) { $TimerId = @IPS_GetEventIDByName($Name, $Parent); if ($TimerId === false) { $TimerId = IPS_CreateEvent(1 /*Cyclic Event*/); IPS_SetName($TimerId, $Name); IPS_SetParent($TimerId, $Parent); if (!IPS_SetEventCyclic($TimerId, 2 /**Daily*/, 1,0,0,0,0)) { echo "IPS_SetEventCyclic failed !!!\n"; } if (!IPS_SetEventCyclicTimeBounds($TimerId, mktime($Hour, 0, 0), 0)) { echo "IPS_SetEventCyclicTimeBounds failed !!!\n"; } IPS_SetEventActive($TimerId, true); echo 'Created Timer '.$Name.'='.$TimerId."\n"; } return $TimerId; }