protected function SetValueBoolean($Ident, $Value)
 {
     $ID = $this->GetIDForIdent($Ident);
     if (GetValueBoolean($ID) != $Value) {
         SetValueBoolean($ID, boolval($Value));
         return true;
     }
     return false;
 }
Beispiel #2
0
 public function RequestData() {
   $data = array();
   // Read data
   $this->ReadState();
   $this->ReadService();
   // Build hash for return
   $data['state'] = GetValueBoolean($this->GetIDForIdent('STATE'));
   $data['service']['name'] = GetValueString($this->GetIDForIdent('SERVICE_NAME'));
   $data['service']['reference'] = GetValueString($this->GetIDForIdent('SERVICE_REFERENCE'));
   return $data;
 }
Beispiel #3
0
 private function WriteResponse($Command, $Value)
 {
     if (is_array($Command)) {
         $Command = implode(' ', $Command);
     }
     if (is_array($Value)) {
         $Value = implode(' ', $Value);
     }
     $EventID = $this->GetIDForIdent('WaitForResponse');
     if (!GetValueBoolean($EventID)) {
         return false;
     }
     $BufferID = $this->GetIDForIdent('BufferOUT');
     if ($Command == GetValueString($BufferID)) {
         if ($this->lock('BufferOut')) {
             SetValueString($BufferID, trim($Value));
             SetValueBoolean($EventID, false);
             $this->unlock('BufferOut');
             return true;
         }
         return 'Error on write ResponseBuffer';
     }
     return false;
 }
Beispiel #4
0
 private function SetValueBoolean($Ident, $value)
 {
     $id = $this->GetIDForIdent($Ident);
     if (GetValueBoolean($id) != $value) {
         SetValueBoolean($id, $value);
     }
 }
 /**
  * handle incoming data along capabilities
  * @param array $data
  */
 private function ParseData($data)
 {
     //
     $caps = $this->GetCaps();
     //$this->debug(__FUNCTION__,print_r($this->all_caps,true));
     foreach (array_keys($caps) as $cap) {
         $ident = $caps[$cap];
         $vid = @$this->GetIDForIdent($ident);
         if ($vid == 0) {
             $this->debug(__FUNCTION__, "Cap {$cap} Ident {$ident}: Variable missed");
             continue;
         }
         if (!isset($data[$cap])) {
             continue;
         }
         $s = $data[$cap];
         switch ($cap) {
             //integer
             case 'TS':
                 //Timestamp
             //Timestamp
             case 'Signal':
                 //RSSI
             //RSSI
             case 'Timer':
                 //Duration code
             //Duration code
             case 'Dimmer':
                 //intensity 100%
             //intensity 100%
             case 'Shutter':
                 //intensity 100%
                 $iv = (int) $s;
                 SetValueInteger($vid, $iv);
                 break;
                 //String
             //String
             case 'Name':
                 //Duration code
                 $st = utf8_decode($s);
                 SetValueString($vid, $st);
                 break;
                 //special
             //special
             case 'Switch':
                 //Status
                 $state = $this->SwitchStatus($s);
                 SetValueBoolean($vid, $state);
                 break;
             case 'Lock':
                 //Status
                 $state = preg_match("/YES|CLOSE|OK/i", $s);
                 //reversed
                 SetValueBoolean($vid, $state);
                 break;
             case 'Alert':
                 //Status
                 $state = !preg_match("/YES|ALERT/i", $s);
                 //reversed
                 SetValueBoolean($vid, $state);
                 break;
             case 'Battery':
                 //battery
                 $state = !preg_match("/LOW|WARN/i", $s);
                 //reversed
                 SetValueBoolean($vid, $state);
                 break;
             case 'FS20':
                 //fs20 mode decoding
                 $state = false;
                 $intensity = 0;
                 $timer = 0;
                 $acode = '';
                 $actioncode = '';
                 $code = utf8_decode($s);
                 $this->debug(__FUNCTION__, "FS20 Code " . strToHex($code));
                 $action = $code[0];
                 $ext = ord($code[1]);
                 $tvid = @$this->GetIDForIdent($caps['Timer']);
                 $dvid = @$this->GetIDForIdent($caps['Dimmer']);
                 $swid = @$this->GetIDForIdent($caps['Switch']);
                 $avid = @$this->GetIDForIdent($caps['TimerActionCode']);
                 $this->debug(__FUNCTION__, "FS20 Vars S:{$swid},D:{$dvid},T:{$tvid},A:{$avid}");
                 if ($dvid) {
                     $intensity = GetValueInteger($dvid);
                 }
                 if ($swid) {
                     $state = GetValueBoolean($swid);
                 }
                 if ($tvid) {
                     $timer = GetValueInteger($tvid);
                 }
                 if ($avid) {
                     $acode = GetValueString($avid);
                 }
                 $ac = ord($action) & 0x1f;
                 $timed = ($action & 0x20) > 0;
                 $this->debug(__FUNCTION__, "FS20 AC:" . $ac . "PrevD:{$intensity}, PrevS:" . ($state ? "On" : "Off"));
                 switch ($ac) {
                     case 0:
                         //off
                         if ($timed) {
                             $actioncode = 'Switch:Off';
                         } else {
                             $state = false;
                         }
                         break;
                     case $ac < 0xf:
                         //Dim to value
                         $intensity = FHZ_helper::fs20_intensity_percent($action & 0xf);
                         $state = true;
                         if ($timed) {
                             $actioncode = 'Switch:Off';
                         }
                         break;
                     case 0x10:
                         //on full
                         $state = true;
                         $intensity = 100;
                         if ($timed) {
                             $actioncode = 'Switch:Off';
                         }
                         break;
                     case 0x11:
                         //on with old value
                         $state = true;
                         if ($intensity == 0) {
                             $intensity = 100;
                         }
                         if ($timed) {
                             $actioncode = 'Switch:Off';
                         }
                         break;
                     case 0x12:
                         $state = !GetValueBoolean($swid);
                         //toggle
                         break;
                     case 0x13:
                         //dimup
                         $steps = FHZ_helper::fs20_intensity_steps($intensity);
                         $intensity = FHZ_helper::fs20_intensity_percent($steps + 1);
                         $state = true;
                         break;
                     case 0x14:
                         //dimdown
                         if ($intensity == 0) {
                             $intensity = 100;
                         }
                         $steps = FHZ_helper::fs20_intensity_steps($intensity);
                         $intensity = FHZ_helper::fs20_intensity_percent($steps - 1);
                         if ($intensity == 0) {
                             $state = false;
                         }
                         break;
                     case 0x18:
                         //off-for-timer
                         $state = 'Off';
                         $actioncode = 'Switch:On';
                         break;
                     case 0x19:
                         //on-for-timer than out
                         $state = true;
                         $actioncode = 'Switch:Off';
                         break;
                     case 0x1a:
                         //on-old-for-timer than out
                         $state = true;
                         $actioncode = 'Switch:Off';
                         break;
                     case 0x1c:
                         //ramp-on-time (time to reach the desired dim value on dimmers)
                         $state = true;
                         $actioncode = "Dimmer:{$intensity}";
                         break;
                     case 0x1d:
                         //ramp-off-time (time to reach the off state on dimmers)
                         $actioncode = 'Switch:Off;Dimmer:0';
                         break;
                     case 0x1e:
                         //on-old-for-timer-prev", // old val for timer, then go to prev. state
                         $actioncode = "Switch:" . ($state ? 'On' : 'Off');
                         $state = true;
                         break;
                     case 0x1f:
                         //on-100-for-timer-prev", // 100% for timer, then go to previous state
                         //new intensity will be the old one
                         $action = "Switch:" . ($state ? 'On' : 'Off') . ";Dimmer:{$intensity}";
                         $intensity = 100;
                         $state = true;
                         break;
                     case 0x15:
                         //dimupdown, no value changes
                     //dimupdown, no value changes
                     case 0x16:
                         //Set Timer
                     //Set Timer
                     case 0x17:
                         //nop
                     //nop
                     case 0x1b:
                         //rese
                         break;
                 }
                 $new_timer = FHZ_helper::fs20_times($ext);
                 $this->debug(__FUNCTION__, "State:" . ($state ? "ON" : "OFF") . ", Dimmer:{$intensity}%,Timer: {$new_timer},ActionCode: '{$actioncode}'");
                 //state
                 if ($swid) {
                     SetValueBoolean($swid, $state);
                 }
                 //dimmer
                 if ($dvid) {
                     SetValueInteger($dvid, $intensity);
                 }
                 //timer
                 if ($tvid) {
                     $this->SetTimerInterval('DeviceTimer', $new_timer * 1000);
                     SetValueInteger($tvid, $new_timer);
                 }
                 //action
                 if ($avid && $acode != $actioncode) {
                     SetValueString($avid, $actioncode);
                 }
                 //log
                 $actiontext = FHZ_helper::$fs20_codes[strToHex($action)];
                 if ($ext > 0) {
                     $actiontext .= ', Timer:' . $timer;
                 }
                 $text = sprintf('%s (%s)', $actiontext, strToHex($code));
                 if ($vid) {
                     SetValueString($vid, $text);
                 }
                 $this->debug(__FUNCTION__, "Action:" . $text);
                 break;
             default:
                 $this->debug(__FUNCTION__, "{$cap} not handled");
         }
         $this->debug(__FUNCTION__, "{$cap}:({$vid})" . $s);
     }
 }
Beispiel #6
0
 private function SetValueBoolean($Ident, $value)
 {
     $id = $this->GetIDForIdent($Ident);
     if (GetValueBoolean($id) != $value) {
         SetValueBoolean($id, $value);
         return true;
     }
     return false;
 }
Beispiel #7
0
 protected function GetValueBoolean($Ident)
 {
     $ID = is_numeric($Ident) ? $Ident : $this->GetIDForIdent($Ident);
     return GetValueBoolean($ID);
 }
 /**
  * Get status variable isPolling
  * indicates a running query
  * ToDo: Replace with semaphore
  * @return bool
  */
 private function isPolling()
 {
     $id = $this->GetIDForIdent('isPolling');
     $val = GetValueBoolean($id);
     return $val;
 }
Beispiel #9
0
  public function SetValue($key, $value) {
    $stateId = IPS_GetObjectIDByIdent('STATE', $this->InstanceID);
    $cmId = IPS_GetObjectIDByIdent('COLOR_MODE', $this->InstanceID);
    $ctId = @IPS_GetObjectIDByIdent('COLOR_TEMPERATURE', $this->InstanceID);
    $briId = IPS_GetObjectIDByIdent('BRIGHTNESS', $this->InstanceID);
    $satId = @IPS_GetObjectIDByIdent('SATURATION', $this->InstanceID);
    $hueId = @IPS_GetObjectIDByIdent('HUE', $this->InstanceID);
    $colorId = @IPS_GetObjectIDByIdent('COLOR', $this->InstanceID);

    $stateValue = GetValueBoolean($stateId);
    $cmValue = $cmId ? GetValueInteger($cmId) : 0;
    $ctValue = $ctId ? (500 - round(347 * GetValueInteger($ctId) / 100)) : 0;
    $briValue = round(GetValueInteger($briId)*2.54);
    $satValue = $satId ? round(GetValueInteger($satId)*2.54) : 0;
    $hueValue = $hueId ? GetValueInteger($hueId) : 0;
    $colorValue = $colorId ? GetValueInteger($colorId) : 0;

    switch ($key) {
      case 'STATE':
        $stateNewValue = $value;
        break;
      case 'COLOR':
        $colorNewValue = $value;
        $stateNewValue = true;
        $hex = str_pad(dechex($value), 6, 0, STR_PAD_LEFT);
        $hsv = $this->HEX2HSV($hex);
        SetValueInteger($colorId, $value);
        $hueNewValue = $hsv['h'];
        $briNewValue = $hsv['v'];
        $satNewValue = $hsv['s'];
        $cmNewValue = 0;
        break;
      case 'BRIGHTNESS':
        $briNewValue = $value;
        $stateNewValue = true;
        if (IPS_GetProperty($this->InstanceID, 'LightFeatures') != 3) {
          if ($cmValue == '0') {
            $newHex = $this->HSV2HEX($hueValue, $satValue, $briNewValue);
            SetValueInteger($colorId, hexdec($newHex));
            $hueNewValue = $hueValue;
            $satNewValue = $satValue;
          } else {
            $ctNewValue = $ctValue;
          }
        }
        break;
      case 'SATURATION':
        $cmNewValue = 0;
        $satNewValue = $value;
        $stateNewValue = true;
        $newHex = $this->HSV2HEX($hueValue, $satNewValue, $briValue);
        SetValueInteger($colorId, hexdec($newHex));
        $hueNewValue = $hueValue;
        $briNewValue = $briValue;
        break;
      case 'COLOR_TEMPERATURE':
        $cmNewValue = 1;
        $ctNewValue = $value;
        $briNewValue = $briValue;
        break;
      case 'COLOR_MODE':
        $cmNewValue = $value;
        $stateNewValue = true;
        if ($cmNewValue == 1) {
          $ctNewValue = $ctValue;
          IPS_SetHidden($colorId, true);
          IPS_SetHidden($ctId, false);
          IPS_SetHidden($satId, true);
        } else {
          $hueNewValue = $hueValue;
          $satNewValue = $satValue;
          $briNewValue = $briValue;
          $newHex = $this->HSV2HEX($hueValue, $satValue, $briValue);
          SetValueInteger($colorId, hexdec($newHex));
          IPS_SetHidden($colorId, false);
          IPS_SetHidden($ctId, true);
          IPS_SetHidden($satId, false);
        }
        break;
    }

    $changes = array();
    if (isset($stateNewValue)) {
      SetValueBoolean($stateId, $stateNewValue);
      $changes['on'] = $stateNewValue;
    }
    if (isset($hueNewValue)) {
      SetValueInteger($hueId, $hueNewValue);
      $changes['hue'] = $hueNewValue;
    }
    if (isset($satNewValue)) {
      SetValueInteger($satId, round($satNewValue * 100 / 254));
      $changes['sat'] = $satNewValue;
    }
    if (isset($briNewValue)) {
      SetValueInteger($briId, round($briNewValue * 100 / 254));
      $changes['bri'] = $briNewValue;
    }
    if (isset($ctNewValue)) {
      SetValueInteger($ctId, 100 - round(($ctNewValue - 153) * 100 / 347));
      $changes['ct'] = $ctNewValue;
    }
    if (isset($cmNewValue)) {
      SetValueInteger($cmId, $cmNewValue);
      $changes['colormode'] = $cmNewValue == 1 ? 'ct' : 'hs';
    }

    $lightId = $this->ReadPropertyInteger("LightId");
    return HUE_Request($this->GetBridge(), "/lights/$lightId/state", $changes);
  }
Beispiel #10
0
 /**
  * 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:
  *
  * KP_RequestInfo($id);
  *
  */
 public function RequestInfo()
 {
     $locationisday = IPS_GetInstanceListByModuleID("{45E97A63-F870-408A-B259-2933F7EABF74}");
     $locationisday = IPS_GetObjectIDByName('Is Day', $locationisday[0]);
     $IsDay = $this->ReadPropertyBoolean("IsDay");
     if ($IsDay == true and GetValueBoolean($locationisday) == false) {
         return;
     } else {
         $url = $this->ReadPropertyString("url");
         $Ausgabe = file_get_contents("{$url}", "r");
         //AC-Leistung_Aktuell
         $pos1 = strpos($Ausgabe, "aktuell</td>");
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 65, $pos2 - $pos1 - 65);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("ACLeistungAktuell"), $data1);
         //AC_Leistung_Status
         $pos1 = strpos($Ausgabe, "Status</td>");
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 33, $pos2 - $pos1 - 33);
         SetValue($this->GetIDForIdent("ACLeistungStatus"), $data);
         //Energie_Gesamtertrag
         $pos1 = strpos($Ausgabe, "Gesamtenergie</td>");
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 30);
         $data = substr($Ausgabe, $pos1 + 70, $pos2 - $pos1 - 70);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("Gesamtertrag"), $data1);
         //Energie_Tagesertrag_Aktuell
         $pos1 = strpos($Ausgabe, "Tagesenergie</td>");
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 70, $pos2 - $pos1 - 70);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("Tagesertrag"), $data1);
         //PV_Generator_String1_Spannung
         $pos1 = strpos($Ausgabe, "Spannung</td>", $pos2);
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("SpannungString1"), $data1);
         //Ausgangsleistung_L1_Spannung
         $pos1 = strpos($Ausgabe, "Spannung</td>", $pos2);
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("L1Spannung"), $data1);
         //PV_Generator_String1_Strom
         $pos1 = strpos($Ausgabe, "Strom</td>", $pos2);
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 63, $pos2 - $pos1 - 63);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("StromString1"), $data1);
         //Ausgangsleistung_L1_Leistung
         $pos1 = strpos($Ausgabe, "Leistung</td>", $pos2);
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("L1Leistung"), $data1);
         //PV_Generator_String2_Spannung
         $pos1 = strpos($Ausgabe, "Spannung</td>", $pos2);
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("SpannungString2"), $data1);
         //Ausgangsleistung_L2_Spannung
         $pos1 = strpos($Ausgabe, "Spannung</td>", $pos2);
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("L2Spannung"), $data1);
         //PV_Generator_String2_Strom
         $pos1 = strpos($Ausgabe, "Strom</td>", $pos2);
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 63, $pos2 - $pos1 - 63);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("StromString2"), $data1);
         //Ausgangsleistung_L2_Leistung
         $pos1 = strpos($Ausgabe, "Leistung</td>", $pos2);
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("L2Leistung"), $data1);
         //PV_Generator_String3_Spannung
         $pos1 = strpos($Ausgabe, "Spannung</td>", $pos2);
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("SpannungString3"), $data1);
         //Ausgangsleistung_L3_Spannung
         $pos1 = strpos($Ausgabe, "Spannung</td>", $pos2);
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("L3Spannung"), $data1);
         //PV_Generator_String3_Strom
         $pos1 = strpos($Ausgabe, "Strom</td>", $pos2);
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 63, $pos2 - $pos1 - 63);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("StromString3"), $data1);
         //Ausgangsleistung_L3_Leistung
         $pos1 = strpos($Ausgabe, "Leistung</td>", $pos2);
         $pos2 = strpos($Ausgabe, "</td>", $pos1 + 20);
         $data = substr($Ausgabe, $pos1 + 66, $pos2 - $pos1 - 66);
         $data1 = (double) $data;
         SetValue($this->GetIDForIdent("L3Leistung"), $data1);
     }
 }