示例#1
0
  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();
     }
 }
示例#3
0
 protected function SetTimerInterval($Name, $Interval)
 {
     $id = @IPS_GetObjectIDByIdent($Name, $this->InstanceID);
     if ($id === false) {
         throw new Exception('Timer not present');
     }
     if (!IPS_EventExists($id)) {
         throw new Exception('Timer not present');
     }
     $Event = IPS_GetEvent($id);
     if ($Interval < 1) {
         if ($Event['EventActive']) {
             IPS_SetEventActive($id, false);
         }
     } else {
         if ($Event['CyclicTimeValue'] != $Interval) {
             IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, $Interval);
         }
         if (!$Event['EventActive']) {
             IPS_SetEventActive($id, true);
         }
     }
 }
示例#4
0
	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);
			}
		}
	}
示例#5
0
 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", E_USER_WARNING);
         }
         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);
     }
 }
示例#6
0
 private function Registerevent22($TargetID)
 {
     if (!isset($_IPS)) {
         global $_IPS;
     }
     $EreignisID = @IPS_GetEventIDByName("E_wand", $TargetID);
     if ($EreignisID == true) {
         if (IPS_EventExists(IPS_GetEventIDByName("E_wand", $TargetID))) {
             IPS_DeleteEvent(IPS_GetEventIDByName("E_wand", $TargetID));
         }
     }
     $eid = IPS_CreateEvent(1);
     //Ausgelöstes Ereignis
     IPS_SetName($eid, "E_wand");
     IPS_SetEventCyclic($eid, 2, 1, 0, 0, 3, 1);
     IPS_SetParent($eid, $TargetID);
     //Ereignis zuordnen
     IPS_SetEventActive($eid, true);
     //Ereignis aktivieren
 }
示例#7
0
 /**
  * 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);
     }
 }
	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;
	}
示例#9
0
 protected function SetTimer($Name, $TargetTime)
 {
     $id = @IPS_GetObjectIDByIdent($Name, $this->InstanceID);
     if ($id === false) {
         throw new Exception('Timer not present');
     }
     if (!IPS_EventExists($id)) {
         throw new Exception('Timer not present');
     }
     $Event = IPS_GetEvent($id);
     if ($TargetTime < time()) {
         if ($Event['EventActive']) {
             IPS_SetEventActive($id, false);
         }
     } else {
         IPS_SetEventCyclic($id, 1, 0, 0, 0, 0, 0);
         IPS_SetEventCyclicDateFrom($id, (int) date("j", $TargetTime), (int) date("n", $TargetTime), (int) date("o", $TargetTime));
         IPS_SetEventCyclicDateTo($id, (int) date("j", $TargetTime), (int) date("n", $TargetTime), (int) date("o", $TargetTime));
         IPS_SetEventCyclicTimeFrom($id, (int) date("H", $TargetTime), (int) date("i", $TargetTime), (int) date("s", $TargetTime));
         IPS_SetEventCyclicTimeTo($id, (int) date("H", $TargetTime), (int) date("i", $TargetTime), (int) date("s", $TargetTime));
         if (!$Event['EventActive']) {
             IPS_SetEventActive($id, true);
         }
     }
 }