コード例 #1
0
ファイル: module.php プロジェクト: Vansdan/SymconHUE
  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);
    }
  }
コード例 #2
0
ファイル: module.php プロジェクト: Nall-chan/IPSSqueezeBox
 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);
         }
     }
 }
コード例 #3
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);
     }
 }
コード例 #4
0
 public function setSleepTimer()
 {
     $hour = GetValue($this->GetIDForIdent("TimerHour"));
     $minute = GetValue($this->GetIDForIdent("TimerMinute"));
     $sleeptimervariableid = $this->GetIDForIdent("SleepTimer");
     $sleeptimerstate = GetValue($sleeptimervariableid);
     $sleeptimerscriptid = IPS_GetScriptIDByName("SleepTimerControl", $sleeptimervariableid);
     $sleeptimereventid = @IPS_GetEventIDByName("SleepTimerEvent", $sleeptimerscriptid);
     $goodnightstate = GetValue($this->GetIDForIdent("GoodNight"));
     $volumefadeout = GetValue($this->GetIDForIdent("VolumeFadeOut"));
     if ($sleeptimerstate == false and $goodnightstate == false) {
         //toogle switch
         SetValue($this->GetIDForIdent("SleepTimer"), true);
         // set event
         IPS_SetEventCyclicTimeFrom($sleeptimereventid, $hour, $minute, 0);
         IPS_SetEventActive($sleeptimereventid, true);
         // set next power off
         $eventinfo = IPS_GetEvent($sleeptimereventid);
         $eventtimestamp = $eventinfo["NextRun"];
         $day = date("l", $eventtimestamp);
         $date = date("d.m.Y", $eventtimestamp);
         $time = date("H:i:s", $eventtimestamp);
         $nextpoweroff = $day . ", " . $date . ", " . $time;
         SetValue($this->GetIDForIdent("NextPowerOff"), $nextpoweroff);
         // check volumefadeout time
         $timenow = ceil(time() / 60) * 60;
         $volumefadouttime = $eventtimestamp - $timenow;
         if ($volumefadouttime < 900) {
             SetValue($this->GetIDForIdent("VolumeFadeOut"), false);
         }
         if ($volumefadeout == true) {
             $fadeoutseconds = 900;
             $neweventtimestamp = strtotime('-' . $fadeoutseconds . ' seconds', $eventtimestamp);
             $newhour = date("H", $neweventtimestamp);
             $newminute = date("i", $neweventtimestamp);
             // set new event time
             IPS_SetEventCyclicTimeFrom($sleeptimereventid, $newhour, $newminute, 0);
             // calculate cycle time
             $actualvolume = GetValue($this->GetIDForIdent("VolumeSlider"));
             $cycletime = floor(900 / ($actualvolume - 1));
             SetValue($this->GetIDForIdent("SleepCycle"), $cycletime);
         }
     }
     if ($sleeptimerstate == true and $goodnightstate == false) {
         SetValue($this->GetIDForIdent("SleepTimer"), false);
         SetValue($this->GetIDForIdent("VolumeFadeOut"), false);
         IPS_SetEventActive($sleeptimereventid, false);
         SetValue($this->GetIDForIdent("SleepCycle"), 0);
         SetValue($this->GetIDForIdent("NextPowerOff"), "");
     }
 }
コード例 #5
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);
     }
 }
コード例 #6
0
ファイル: module.php プロジェクト: Nall-chan/paresyMisc
 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);
         }
     }
 }
コード例 #7
0
 protected function SetTimerIntervalTime($Name, $startzeith, $startzeitm, $stopzeith, $stopzeitm)
 {
     $id = @IPS_GetObjectIDByIdent($Name, $this->InstanceID);
     if ($id === false) {
         throw new Exception('Timer not present', E_USER_WARNING);
     }
     if (!IPS_EventExists($id)) {
         throw new Exception('Timer not present', E_USER_WARNING);
     }
     $Event = IPS_GetEvent($id);
     if ($startzeith > 23) {
         if ($Event['EventActive']) {
             IPS_SetEventActive($id, false);
         }
     } else {
         IPS_SetEventCyclicTimeFrom($id, $startzeith, $startzeitm, 0);
         IPS_SetEventCyclicTimeTo($id, $stopzeith, $stopzeitm, 0);
     }
 }