public function RequestAction($Ident, $Value) { switch ($Ident) { case "Dooya": switch ($Value) { case 0: //Down $state = false; SetValueInteger($this->GetIDForIdent('Dooya'), $Value); $this->Down(); break; case 1: //Stop $this->Stop(); SetValueInteger($this->GetIDForIdent('Dooya'), $Value); break; case 2: //Up $this->Up(); SetValueInteger($this->GetIDForIdent('Dooya'), $Value); break; } break; default: throw new Exception("Invalid ident"); } }
protected function SetValueInteger($Ident, $Value) { $ID = $this->GetIDForIdent($Ident); if (GetValueInteger($ID) != $Value) { SetValueInteger($ID, intval($Value)); return true; } return false; }
private function SetValueInteger($Ident, $value) { $id = $this->GetIDForIdent($Ident); if (GetValueInteger($id) != $value) { SetValueInteger($id, $value); return true; } return false; }
function SetVariable($VarID, $Type, $Value) { switch ($Type) { case 0: // boolean SetValueBoolean($VarID, $Value); break; case 1: // integer SetValueInteger($VarID, $Value); break; case 2: // float SetValueFloat($VarID, $Value); break; case 3: // string SetValueString($VarID, $Value); break; } }
private function UpdateVariable(ISCP_API_Data $APIData) { if ($APIData->Data == "N/A") { return; } switch ($APIData->Mapping->VarType) { case IPSVarType::vtBoolean: $VarID = $this->GetVariable($APIData->APICommand, $APIData->Mapping->VarType, $APIData->Mapping->VarName, $APIData->Mapping->Profile, $APIData->Mapping->EnableAction); $Value = ISCP_API_Commands::$BoolValueMapping[$APIData->Data]; SetValueBoolean($VarID, $Value); break; case IPSVarType::vtFloat: $VarID = $this->GetVariable($APIData->APICommand, $APIData->Mapping->VarType, $APIData->Mapping->VarName, $APIData->Mapping->Profile, $APIData->Mapping->EnableAction); $Value = $APIData / 100; SetValueFloat($VarID, $Value); // throw new Exception("Float VarType not implemented."); break; case IPSVarType::vtInteger: $VarID = $this->GetVariable($APIData->APICommand, $APIData->Mapping->VarType, $APIData->Mapping->VarName, $APIData->Mapping->Profile, $APIData->Mapping->EnableAction); $Value = hexdec($APIData->Data); SetValueInteger($VarID, $Value); break; case IPSVarType::vtString: $VarID = $this->GetVariable($APIData->APICommand, $APIData->Mapping->VarType, $APIData->Mapping->VarName, $APIData->Mapping->Profile, $APIData->Mapping->EnableAction); $Value = $APIData->Data; SetValueString($VarID, $Value); break; case IPSVarType::vtDualInteger: $Prefix = substr($APIData->Data, 0, 1); $VarID = $this->GetVariable($APIData->APICommand . $APIData->Mapping->ValuePrefix[$Prefix], IPSVarType::vtInteger, $APIData->Mapping->VarName[$Prefix], $APIData->Mapping->Profile, $APIData->Mapping->EnableAction); $Value = $APIData->Mapping->ValueMapping[substr($APIData->Data, 1, 2)]; SetValueInteger($VarID, $Value); if (strlen($APIData->Data) > 3) { $Prefix = substr($APIData->Data, 3, 1); $VarID = $this->GetVariable($APIData->APICommand . $APIData->Mapping->ValuePrefix[$Prefix], IPSVarType::vtInteger, $APIData->Mapping->VarName[$Prefix], $APIData->Mapping->Profile, $APIData->Mapping->EnableAction); $Value = $APIData->Mapping->ValueMapping[substr($APIData->Data, 4, 2)]; SetValueInteger($VarID, $Value); } } }
public function SetInput($input) { SetValueInteger($this->GetIDForIdent('INPUT'), $this->GetInputId($input)); return $this->Request("<Input><Input_Sel>{$input}</Input_Sel></Input>", 'PUT'); }
public function SendRFCode(integer $Value) { //RF Code auslesen Value 0 entspricht RFCode 1 $RFCode = "RFCode" . $Value; if ($Value <= 32 && !null == $this->GetIDForIdent('RFCODES1')) { $setvalue = $Value - 1; SetValueInteger($this->GetIDForIdent('RFCODES1'), $setvalue); } elseif ($Value <= 64 && $Value > 32 && !null == $this->GetIDForIdent('RFCODES2')) { $setvalue = $Value - 33; SetValueInteger($this->GetIDForIdent('RFCODES2'), $setvalue); } elseif ($Value <= 96 && $Value > 64 && !null == $this->GetIDForIdent('RFCODES3')) { $setvalue = $Value - 65; SetValueInteger($this->GetIDForIdent('RFCODES3'), $setvalue); } elseif ($Value <= 100 && $Value > 96 && !null == $this->GetIDForIdent('RFCODES4')) { $setvalue = $Value - 97; SetValueInteger($this->GetIDForIdent('RFCODES4'), $setvalue); } $RF_send = $this->ReadPropertyString($RFCode); return $this->Send_RF($RF_send); }
protected function SendCommand($command) { $FS20 = $this->Calculate(); $ip_aiogateway = $this->GetIPGateway(); IPS_LogMessage("FS20 Adresse:", $FS20); IPS_LogMessage("FS20 Command:", $command); $GatewayPassword = $this->GetPassword(); switch ($command) { case "1000": //An SetValueBoolean($this->GetIDForIdent('Status'), true); if (IPS_StatusVariableExists($this->InstanceID, "Dimmer")) { SetValueInteger($this->GetIDForIdent('Dimmer'), 10); } break; case "0000": //Aus SetValueBoolean($this->GetIDForIdent('Status'), false); if (IPS_StatusVariableExists($this->InstanceID, "Dimmer")) { SetValueInteger($this->GetIDForIdent('Dimmer'), 0); } break; case "DIM0": //0 SetValueBoolean($this->GetIDForIdent('Status'), false); SetValueInteger($this->GetIDForIdent('Dimmer'), 0); $command = "0000"; break; case "0200": //10 SetValueInteger($this->GetIDForIdent('Dimmer'), 1); break; case "0300": //20 SetValueInteger($this->GetIDForIdent('Dimmer'), 2); break; case "0500": //30 SetValueInteger($this->GetIDForIdent('Dimmer'), 3); break; case "0600": //40 SetValueInteger($this->GetIDForIdent('Dimmer'), 4); break; case "0800": //50 SetValueInteger($this->GetIDForIdent('Dimmer'), 5); break; case "0900": //60 SetValueInteger($this->GetIDForIdent('Dimmer'), 6); break; case "0B00": //70 SetValueInteger($this->GetIDForIdent('Dimmer'), 7); break; case "0D00": //80 SetValueInteger($this->GetIDForIdent('Dimmer'), 8); break; case "0E00": //90 SetValueInteger($this->GetIDForIdent('Dimmer'), 9); break; case "DIM100": //100 SetValueBoolean($this->GetIDForIdent('Status'), true); SetValueInteger($this->GetIDForIdent('Dimmer'), 10); $command = "1000"; break; } if ($GatewayPassword !== "") { $gwcheck = file_get_contents("http://" . $this->GetIPGateway() . "/command?XC_USER=user&XC_PASS="******"&XC_FNC=SendSC&type=FS20&data=" . $FS20 . $command); IPS_LogMessage("AIOGateway:", "Senden an Gateway mit Passwort"); } else { $gwcheck = file_get_contents("http://" . $this->GetIPGateway() . "/command?XC_FNC=SendSC&type=FS20&data=" . $FS20 . $command); } if ($gwcheck == "{XC_SUC}") { $this->response = true; } elseif ($gwcheck == "{XC_AUTH}") { $this->response = false; echo "Keine Authentifizierung möglich. Das Passwort für das Gateway ist falsch."; } return $this->response; }
public function SendIRCode(integer $Value) { //IR Code auslesen Value 0 entspricht IRCode 1 $IRCode = "IRCode" . $Value; if ($Value <= 32 && !null == $this->GetIDForIdent('IRCODES1')) { $setvalue = $Value - 1; SetValueInteger($this->GetIDForIdent('IRCODES1'), $setvalue); } elseif ($Value <= 64 && $Value > 32 && !null == $this->GetIDForIdent('IRCODES2')) { $setvalue = $Value - 33; SetValueInteger($this->GetIDForIdent('IRCODES2'), $setvalue); } elseif ($Value <= 96 && $Value > 64 && !null == $this->GetIDForIdent('IRCODES3')) { $setvalue = $Value - 65; SetValueInteger($this->GetIDForIdent('IRCODES3'), $setvalue); } elseif ($Value <= 100 && $Value > 96 && !null == $this->GetIDForIdent('IRCODES4')) { $setvalue = $Value - 97; SetValueInteger($this->GetIDForIdent('IRCODES4'), $setvalue); } $IR_send = $this->ReadPropertyString($IRCode); $this->Send_IR($IR_send, $this->GetIRDiode(), $this->GetExtIRDiode()); return true; }
/** * 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); } }
/** * handle incoming data along capabilities * @param array $data */ private function ParseData($data) { // $this->debug(__FUNCTION__, 'Parse'); $caps = $this->GetCaps(); 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]; $this->debug(__FUNCTION__, "Handle {$cap} ({$vid}) = {$s}"); switch ($cap) { //boolean types case 'Alert': //Status $state = $s != 'YES'; //reversed display SetValueBoolean($vid, $state); break; //Counter types with factor //Counter types with factor case 'Counter': $iv = (int) $s; switch ($this->GetType()) { case 'EMWZ': $last = GetValueInteger($vid); $opid = $this->GetIDForIdent('OCounter'); if ($opid) { $offset = GetValueInteger($opid); if ($last > $iv) { $offset += 65535; $this->debug(__FUNCTION__, "EMWZ:Increase Offset by 65535: {$offset}"); SetValueInteger($opid, $offset); } $iv = $iv + $offset; } else { $this->debug(__FUNCTION__, "EMWZ:No vid for OCounter"); } $pvid = $this->GetIDForIdent('TPower'); if ($pvid) { $factor = $this->GetCounterFactor(); if ($factor == 0) { $factor = 150; } $val = $iv * (1 / $factor); //counter%ticks pro kw SetValueFloat($pvid, $val); $this->debug(__FUNCTION__, "EMWZ:TPower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")"); } else { $this->debug(__FUNCTION__, "EMWZ:No vid for TPower"); } break; case 'EMEM': $last = GetValueInteger($vid); $opid = $this->GetIDForIdent('OCounter'); if ($opid) { $offset = GetValueInteger($opid); if ($last > $iv) { $offset += 65535; $this->debug(__FUNCTION__, "EMEM:Increase Offset by 65535: {$offset}"); SetValueInteger($opid, $offset); } $iv = $iv + $offset; } else { $this->debug(__FUNCTION__, "EMEM:No vid for OCounter"); } $pvid = $this->GetIDForIdent('TPower'); if ($pvid) { $factor = $this->GetCounterFactor(); if ($factor == 0) { $factor = 100; } $val = $iv * (1 / $factor); //counter%ticks pro kw SetValueFloat($pvid, $val); $this->debug(__FUNCTION__, "EMEM:TPower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")"); } else { $this->debug(__FUNCTION__, "EMEM:No vid for TPower"); } break; case 'EMGZ': $pvid = $this->GetIDForIdent('TGas'); if ($pvid) { $factor = $this->GetCounterFactor(); if ($factor == 0) { $factor = 100; } $val = $iv * (1 / $factor); //Counter%ticks pro m3 SetValueFloat($pvid, $val); $this->debug(__FUNCTION__, "EMGZ:TGas:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")"); } else { $this->debug(__FUNCTION__, "EMGZ:No vid for TGas"); } break; } SetValueInteger($vid, $iv); break; case 'ACounter': $iv = (int) $s; switch ($this->GetType()) { case 'EMWZ': $pvid = $this->GetIDForIdent('APower'); if ($pvid) { $factor = $this->GetCounterFactor(); if ($factor == 0) { $factor = 150; } $val = $iv * (1 / $factor) * 1000; //W statt KW SetValueFloat($pvid, $val); $this->debug(__FUNCTION__, "EMWZ:APower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")"); } else { $this->debug(__FUNCTION__, "EMWZ:No vid for APower"); } break; case 'EMEM': $pvid = $this->GetIDForIdent('APower'); if ($pvid) { $factor = $this->GetCounterFactor(); if ($factor == 0) { $factor = 100; } $val = $iv * (1 / $factor) * 1000; //W statt KW SetValueFloat($pvid, $val); $this->debug(__FUNCTION__, "EMEM:APower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")"); } else { $this->debug(__FUNCTION__, "EMEM:No vid for APower"); } break; case 'EMGZ': $pvid = $this->GetIDForIdent('AGas'); if ($pvid) { $factor = $this->GetCounterFactor(); if ($factor == 0) { $factor = 100; } $val = $iv * (1 / $factor); //m3 SetValueFloat($pvid, $val); $this->debug(__FUNCTION__, "EMGZ:AGas:({$pvid})=" . $val . " F:{$factor}(" . $this->GetCounterFactor() . ")"); } else { $this->debug(__FUNCTION__, "EMGZ:No vid for AGas"); } break; } SetValueInteger($vid, $iv); break; case 'PCounter': $iv = (int) $s; switch ($this->GetType()) { case 'EMWZ': $pvid = $this->GetIDForIdent('PPower'); if ($pvid) { $factor = $this->GetCounterFactor(); if ($factor == 0) { $factor = 150; } $val = $iv * (1 / $factor) * 1000; //W statt KW SetValueFloat($pvid, $val); $this->debug(__FUNCTION__, "EMWZ:PPower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")"); } else { $this->debug(__FUNCTION__, "EMWZ:No vid for PPower"); } break; case 'EMEM': $pvid = $this->GetIDForIdent('PPower'); if ($pvid) { $factor = $this->GetCounterFactor(); if ($factor == 0) { $factor = 100; } $val = $iv * (1 / $factor) * 1000; //W statt KW SetValueFloat($pvid, $val); $this->debug(__FUNCTION__, "EMEM:PPower:({$pvid})=" . $val . " F:{$factor}(" . $this->GetCounterFactor() . ")"); } else { $this->debug(__FUNCTION__, "EMEM:No vid for PPower"); } break; case 'EMGZ': $pvid = $this->GetIDForIdent('PGas'); if ($pvid) { $factor = $this->GetCounterFactor(); if ($factor == 0) { $factor = 100; } $val = $iv * (1 / $factor); //m3 SetValueFloat($pvid, $val); $this->debug(__FUNCTION__, "EMGZ:PGas:({$pvid})=" . $val . " F:{$factor}(" . $this->GetCounterFactor() . ")"); } else { $this->debug(__FUNCTION__, "EMGZ:No vid for PGas"); } break; } SetValueInteger($vid, $iv); break; //int types //int types case 'Signal': //RSSI //RSSI case 'LoadPct': //Load in Pct //Load in Pct case 'Charged': //Charged in Pct //Charged in Pct case 'OCounter': //old counter //old counter case 'TS': //Timestamp $iv = (int) $s; SetValueInteger($vid, $iv); break; //float types with factor //float types with factor case 'AGas': //Actual //Actual case 'TGas': //Total //Total case 'PGas': //Peak //Peak case 'APower': //Actual //Actual case 'PPower': //Peak //Peak case 'TPower': //Total //Total case 'AWater': //Actual //Actual case 'TWater': //Total //Total case 'PWater': //Peak $fv = (double) $s; $factor = $this->GetCounterFactor(); $val = $fv * $factor; SetValueFloat($vid, $val); break; //float types //float types case 'VoltIn': //InputVolt //InputVolt case 'VoltOut': //Output Volt //Output Volt case 'Nominal': //Nominal Power //Nominal Power case 'Watt': //Absolute Load //Absolute Load case 'Freq': //Frequency //Frequency case 'TimeLeft': //TimeLeft $fv = (double) $s; SetValueFloat($vid, $fv); break; //string types //string types case 'Name': case 'Status': $st = utf8_decode($s); SetValueString($vid, $st); break; default: $this->debug(__FUNCTION__, "{$cap} not handled"); } //switch $this->debug(__FUNCTION__, "{$cap}:({$vid})=" . $s); } //for }
public function Colorselect(integer $Value) { SetValueInteger($this->GetIDForIdent('Farbauswahl'), $Value); // HEX-Wert in einzelne Werte für Rot / Grün / Blau zerlegen $r = $Value >> 16 & 0xff; $g = $Value >> 8 & 0xff; $b = $Value >> 0 & 0xff; // Farbsättigung /** Berechnung der Helligkeit aus den RGB-Werten mit fs = 255 http://www.w3.org/TR/2006/WD-WCAG20-20060427/appendixA.html#luminosity-contrastdef Der Controller hat insgesamt 9 Helligkeitsstufen. */ $fs = 255; $Helligkeit = 0.2126 * pow($r / $fs, 2.2) + 0.7151999999999999 * pow($g / $fs, 2.2) + 0.0722 * pow($b / $fs, 2.2); $Helligkeitsstufe = intval($Helligkeit * 9 + 1); $Helligkeitsstufe_alt = $this->ReadPropertyInteger("Helligkeit"); $Anzahl = $Helligkeitsstufe - $Helligkeitsstufe_alt; SetValue($this->GetIDForIdent("Helligkeit"), $Helligkeitsstufe); // Umwandeln der RGB Werte $hsv = $this->RGBtoHSV($r, $g, $b); $address = $this->ReadPropertyString("LEDAdresse"); /** Holen der 6-stelligen Hex Stringadresse des LM II Controllers Diese muss um 0X ergänzt und mit 00 verlängert werden ---> 0xAdresse00. Ferner werden für die Helligkeitsregelung die Hex Adressen für Up (+3) und Down (+) benötigt. Buchstaben der Hex Werte müssen in Grossbuchstaben umgewandelt werden. */ $Adresse_Hex = "0x" . $address . "00"; $Adresse_Int = hexdec($Adresse_Hex); $Adresse_Up_Hex = strtoupper(dechex($Adresse_Int + 3)); $Adresse_Down_Hex = strtoupper(dechex($Adresse_Int + 4)); /** Der Controller hat insgesamt 128 Farbcodes ---> es gibt 128 Raster mit je 2.8125°. Aufgrund des hsv Wertes wird das Raster bestimmt. Der Farbkreis beginnt mit Rot bei 0°. Innerhalb der Codesequenz des Controllers befindet sich Rot auf Index = 103. Deshalb müssen die Werte bis zum Index 103 jeweils verringert werden, um den Übergang zu Gelb, Orange ... zu erhalten. Ab Index 104 muss mit dem letzten Index 128 angefangen werden (lila) und dann immer verringert werden bis rot erreicht ist. Dabei ist zu beachten, dass die gültigen Codes nur die Endstellen 0, 7, 8 und F haben und somit entweder 7 oder 1 zu addieren ist. */ $hsv = intval($hsv / 2.8125) + 1; if ($hsv > 103) { $hsv = 232 - $hsv; } else { $hsv = 104 - $hsv; } $Int1 = intval(($hsv - 1) / 4) * 16; $Rest = ($hsv - 1) % 4; switch ($Rest) { case 0: $Int2 = 0; break; case 1: $Int2 = 7; break; case 2: $Int2 = 8; break; case 3: $Int2 = 15; break; } // Adresse zum Senden des Farbcodes bilden $Adresse_Int = $Adresse_Int + $Int1 + $Int2; $address = strtoupper(dechex($Adresse_Int)); $command = ""; // command ist schon in address enthalten return $this->Send_LED($address, $command, $this->GetIPGateway()); // Setzen der Helligkeit nachdem die Farbe eingestellt worden ist if ($Anzahl > 0) { for ($i = 1; $i <= $Anzahl; $i++) { $this->Up(); } } if ($Anzahl < 0) { for ($i = -1; $i >= $Anzahl; $i--) { $this->Down(); } } }
/** * parses an record string * * @param $data string * @param $status string * @return array */ private function Parse($data, $status) { /** * @par Status * @code * #----Status (te923con -s -i '') * 0x29 :0x17 :0x14 :0x10 :0x26 :1 :1 :1 :1 :1 :1 :1 :1 * SYSSW:BARSW:EXTSW:RCCSW:WINSW:BATR:BATU:BATW:BAT5:BAT4:BAT5:BAT2:BAT1 * @endcode * - SYSSW - software version of system controller * - BARSW - software version of barometer * - EXTSW - software version of UV and channel controller * - RCCSW - software version of rain controller * - WINSW - software version of wind controller * - BATR - battery of rain sensor (1-good (not present), 0-low) * - BATU - battery of UV sensor (1-good (not present), 0-low) * - BATW - battery of wind sensor (1-good (not present), 0-low) * - BAT5 - battery of sensor 5 (1-good (not present), 0-low) * - BAT4 - battery of sensor 4 (1-good (not present), 0-low) * - BAT3 - battery of sensor 3 (1-good (not present), 0-low) * - BAT2 - battery of sensor 2 (1-good (not present), 0-low) * - BAT1 - battery of sensor 1 (1-good (not present), 0-low) * * @par Data * @code * #------Data (te923con -i 'i') * * 1356207784:22.95:41:7.70:91:8.00:83:i :i :i :i :i :i :1001.9:i :3 :0 :9 :0.1:0.0:7.2:356 * T0 :H0:T1 :H1:T2 :H2:T3:H3:T4:H4:T5:H5:PRESS :UV:FC:STORM:WD:WS :WG :WC :RC * @endcode * - T0 - temperature from internal sensor in °C * - H0 - humidity from internal sensor in % rel * - T1..5 - temperature from external sensor 1..4 in °C * - H1..5 - humidity from external sensor 1...4 in % rel * - PRESS - air pressure in mBar * - UV - UV index from UV sensor * - FC - station forecast, see below for more details * - STORM - stormwarning; 0 - no warning, 1 - fix your dog * - WD - wind direction in n x 22.5°; 0 -> north * - WS - wind speed in m/s * - WG - wind gust speed in m/s * - WC - windchill temperature in °C * - RC - rain counter (maybe since station starts measurement) as value * * * weather forecast means (as precisely as possible) * - 0 - heavy snow * - 1 - little snow * - 2 - heavy rain * - 3 - little rain * - 4 - cloudy * - 5 - some clouds * - 6 - sunny */ $te_data = array(); $status = explode(":", $status); $data = explode(":", $data); $cdata = count($data); $cstatus = count($status); $this->debug(__FUNCTION__, "Entered: Data:{$cdata},Status: {$cstatus}"); //if (($cdata == 22) && ($cstatus == 13)) { $date = $data[0]; $tsid = @$this->GetIDForIdent('TimeStamp'); if ($tsid > 0) { SetValueInteger($tsid, $date); } $te_data['date'] = $date; //Indoor and Sensor1-5 T/H for ($s = 0; $s < self::MAXSENSORS; $s++) { $f = $s * 2 + 1; if (trim($data[$f]) == 'i') { continue; } $te_data[$s]['Id'] = "{$s}"; $te_data[$s]['Temp'] = (double) $data[$f]; if ($s > 0) { $batf = 13 - $s; if (isset($status[$batf])) { $stat = $status[$batf] == '0' ? 'LOW' : 'OK'; $te_data[$s]['Battery'] = $stat; } } if (trim($data[$f + 1]) != 'i') { $te_data[$s]['Hum'] = (int) $data[$f + 1]; } //todo $te_data[$s]['Typ'] = 'T/F'; if ($s == 0) { $te_data[$s]['Typ'] = 'Indoor'; } else { if (!isset($te_data[$s]['Hum'])) { $te_data[$s]['Typ'] = 'T'; } } } //indoor specioa if (trim($data[13]) != 'i') { $te_data[0]['Press'] = (int) $data[13]; } if (trim($data[15]) != 'i') { $te_data[0]['Forecast'] = (int) $data[15]; } //uv if (trim($data[14]) != 'i') { $te_data['UV']['UV'] = $data[14]; $te_data['UV']['Bat'] = $status[6]; } //wind if (trim($data[18]) != 'i') { $te_data['Wind']['Wind'] = $data[18] * self::ms_to_kmh; $te_data['Wind']['Storm'] = $data[16] != 0 ? 'YES' : 'No'; $te_data['Wind']['WindDir'] = $data[17] * 22.5; $te_data['Wind']['WindGust'] = $data[19] * self::ms_to_kmh; $te_data['Wind']['WindChill'] = (double) $data[20]; $te_data['Wind']['Bat'] = $status[7]; } //rain if (trim($data[21]) != 'i') { $new = (int) $data[21]; $factor = $this->GetRainPerCount() / 1000; $rcid = @$this->GetIDForIdent('LastRainCounter'); $dailyid = @$this->GetIDForIdent('NewDayRainCounter'); $old = GetValueInteger($rcid); $daily = GetValueInteger($dailyid); $diff = $new - $old; $dailydiff = $new - $daily; $rain = $diff * $factor; $raindaily = $dailydiff * $factor; $te_data['Rain']['RainLastDay'] = ''; $dailyvar = IPS_GetVariable($dailyid); $dailyupdated = $dailyvar['VariableUpdated']; if (is_new_day($dailyupdated)) { //set last day sum SetValueInteger($dailyid, $old); //calculate rain last day $lastday = ($old - $daily) * $factor; if ($lastday < 0 or $lastday > 500) { $lastday = 0; } $te_data['Rain']['RainLastDay'] = $lastday; $this->debug(__FUNCTION__, "::NewDay, Store old Counter({$old}) and Daily({$lastday})"); } if ($new > $old) { SetValueInteger($rcid, $new); } if ($rain < 0 or $rain > 100) { $rain = 0; } $te_data['Rain']['Rain'] = $rain; if ($raindaily < 0 or $raindaily > 500) { $raindaily = 0; } $te_data['Rain']['RainDaily'] = $raindaily; $te_data['Rain']['Bat'] = $status[5]; } //fill standard fields foreach (array('Wind', 'Rain', 'UV', 'Indoor') as $dev) { if (isset($te_data[$dev])) { $te_data[$dev]['Typ'] = $dev . "Sensor"; $te_data[$dev]['Id'] = $dev; if (isset($te_data[$dev]['Bat'])) { $stat = trim($te_data[$dev]['Bat']) == '0' ? 'LOW' : 'OK'; $te_data[$dev]['Battery'] = $stat; unset($te_data[$dev]['Bat']); } } } $this->debug(__FUNCTION__, 'OK'); /* } else { $this->debug(__FUNCTION__, "Field Error (22 data and 14 status fields expected"); } */ $this->debug(__FUNCTION__, " Parsed Data:" . print_r($te_data, true)); if (count($te_data) == 0) { IPS_LogMessage(__CLASS__, __FUNCTION__ . " Error: Parsing returned no data"); } return $te_data; }
/** * inc Error counter */ private function incError() { $vid = $this->GetIDForIdent('Errors'); if ($vid) { $val = GetValueInteger($vid); SetValueInteger($vid, $val + 1); } }
public function ReceiveData($JSONString) { $Data = json_decode($JSONString); // Nur API Daten annehmen. // IPS_LogMessage('ReceiveDataFromGateway:'.$this->InstanceID, print_r($Data,1)); if ($Data->DataID != '{0C541DDF-CE0F-4113-A76F-B4836015212B}') { return false; } $APIData = new TXB_API_Data(); $APIData->GetDataFromJSONObject($Data); // Auf NodeNamen prüfen if ($APIData->NodeName != $this->ReadPropertyString('NodeName')) { return false; } switch ($APIData->APICommand) { case TXB_API_Command::XB_API_Transmit_Status: $TransmitStatusID = $this->GetIDForIdent("TransmitStatus"); if (!$this->lock('Transmit_Status')) { throw new Exception('Receive Transmit Status is locked'); } $this->SendDebug('TX_Status_Received(8B)', $APIData->Data, 1); SetValueInteger($TransmitStatusID, ord($APIData->Data[1])); $this->unlock('Transmit_Status'); break; case TXB_API_Command::XB_API_Receive_Paket: $Receive_Status = $APIData->Data[0]; if ((ord($Receive_Status) & TXB_Receive_Status::XB_Receive_Packet_Acknowledged) == TXB_Receive_Status::XB_Receive_Packet_Acknowledged) { $this->SendDebug('Receive_Paket(OK)', substr($APIData->Data, 1), 1); $this->SendDataToChild(substr($APIData->Data, 1)); } else { $this->SendDebug('ReceivePaket(Error:' . bin2hex($Receive_Status) . ')', substr($APIData->Data, 1), 1); } break; case TXB_API_Command::XB_API_Remote_AT_Command_Responde: $ATData = new TXB_Command_Data(); $ATData->ATCommand = substr($APIData->Data, 0, 2); $ATData->Status = $APIData->Data[2]; $ATData->Data = substr($APIData->Data, 3); $this->SendDebug('Remote_AT_Command_Responde(' . $ATData->ATCommand . ')', $ATData->Data, 1); $this->SendDataToDevice($ATData); break; case TXB_API_Command::XB_API_IO_Data_Sample_Rx: $IOSample = new TXB_API_IO_Sample(); $IOSample->Status = $APIData->Data[0]; $IOSample->Sample = substr($APIData->Data, 1); $this->SendDebug('IO_Data_Sample_Rx(' . $APIData->APICommand . ')', $APIData->Data, 1); $this->SendDataToDevice($IOSample); break; default: /* SendData('unhandle('+inttohex(ord(APIData.APICommand),2)+')',APIdata.Data); */ break; } return true; }
protected function DoBlutdruck($ModulID, $data) { $diastolic = 0; $systolic = 0; $pulse = 0; $CatID = @IPS_GetCategoryIDByName("Blutdruck", $ModulID); if ($CatID === false) { return; } $time = @$data['measuregrps'][0]['date']; $data = @$data['measuregrps'][0]['measures']; if (count($data) != 3) { $this->Logging("Fehler bei DoBlutdruck " . count($data)); //return; } $id = @IPS_GetVariableIDByName("DatumUhrzeit", $CatID); if ($id > 0) { $old = GetValueInteger($id); if ($old == $time) { // keine neue Daten return false; } SetValueInteger($id, $time); } foreach ($data as $messung) { $val = $messung['value']; if ($messung['type'] == 9) { $diastolic = $val; } if ($messung['type'] == 10) { $systolic = $val; } if ($messung['type'] == 11) { $pulse = $val; } } $id = IPS_GetVariableIDByName("Diastolic", $CatID); if ($id > 0) { SetValueInteger($id, $diastolic); } $id = IPS_GetVariableIDByName("Systolic", $CatID); if ($id > 0) { SetValueInteger($id, $systolic); } $id = IPS_GetVariableIDByName("Puls", $CatID); if ($id > 0) { SetValueInteger($id, $pulse); } }
public function SetDefaultGroupVolume() { if (!$this->ReadPropertyBoolean("GroupCoordinator")) { die("This function is only allowed for GroupCoordinators"); } $groupMembers = GetValueString(IPS_GetObjectIDByName("GroupMembers", $this->InstanceID)); $groupMembersArray = array(); if ($groupMembers) { $groupMembersArray = array_map("intval", explode(",", $groupMembers)); } $groupMembersArray[] = $this->InstanceID; foreach ($groupMembersArray as $key => $ID) { try { SNS_SetDefaultVolume($ID); } catch (Exception $e) { } } $GroupVolume = 0; foreach ($groupMembersArray as $key => $ID) { $GroupVolume += GetValueInteger(IPS_GetObjectIDByName("Volume", $ID)); } SetValueInteger(IPS_GetObjectIDByName("GroupVolume", $this->InstanceID), intval(round($GroupVolume / sizeof($groupMembersArray)))); }
public function LEDOff() { $adress = $this->ReadPropertyString("Host"); $command = "0101"; SetValueInteger($this->GetIDForIdent('Farbe'), 4); IPS_LogMessage("LED Gateway:", "Aus"); return $this->Set_LEDGW($adress, $command); }
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); }
public function SpeedDown() { $adress = $this->ReadPropertyString("LEDAdresse"); $command = "C00"; SetValueInteger($this->GetIDForIdent('Speed'), 1); return $this->Send_LED($adress, $command); }
if ($sleeptimer) { $SleeptimerArray = explode(":", $sonos->GetSleeptimer()); $SleeptimerMinutes = $SleeptimerArray[0] * 60 + $SleeptimerArray[1]; if ($SleeptimerArray[2]) { $SleeptimerMinutes = $SleeptimerMinutes + 1; } } else { $SleeptimerMinutes = 0; } SetValueInteger(IPS_GetObjectIDByName("Sleeptimer", IPS_GetParent($_IPS["SELF"])), $SleeptimerMinutes); } } $nowPlaying = GetValueString(IPS_GetObjectIDByName("nowPlaying", IPS_GetParent($_IPS["SELF"]))); if ($actuallyPlaying != $nowPlaying) { SetValueString(IPS_GetObjectIDByName("nowPlaying", IPS_GetParent($_IPS["SELF"])), $actuallyPlaying); } } // Set Group Volume if (IPS_GetProperty(IPS_GetParent($_IPS["SELF"]), "GroupCoordinator")) { $groupMembers = GetValueString(IPS_GetObjectIDByName("GroupMembers", IPS_GetParent($_IPS["SELF"]))); $groupMembersArray = array(); if ($groupMembers) { $groupMembersArray = array_map("intval", explode(",", $groupMembers)); } $groupMembersArray[] = IPS_GetParent($_IPS["SELF"]); $GroupVolume = 0; foreach ($groupMembersArray as $key => $ID) { $GroupVolume += GetValueInteger(IPS_GetObjectIDByName("Volume", $ID)); } SetValueInteger(IPS_GetObjectIDByName("GroupVolume", IPS_GetParent($_IPS["SELF"])), intval(round($GroupVolume / sizeof($groupMembersArray)))); }
protected function SendCommand(string $command) { $address = $this->ReadPropertyString('Adresse'); $GatewayPassword = $this->GetPassword(); switch ($command) { case "20": //Up SetValueInteger($this->GetIDForIdent('Somfy'), 2); break; case "40": //Down SetValueInteger($this->GetIDForIdent('Somfy'), 0); break; case "10": //Stop SetValueInteger($this->GetIDForIdent('Somfy'), 1); break; } IPS_LogMessage("Adresse:", $address); IPS_LogMessage("RTS Command:", $command); //IPS_LogMessage( "AIO Gateway:" , "http://".$this->GetIPGateway()."/command?XC_FNC=SendSC&type=RT&data=".$command.$address ); if ($GatewayPassword !== "") { $gwcheck = file_get_contents("http://" . $this->GetIPGateway() . "/command?XC_USER=user&XC_PASS="******"&XC_FNC=SendSC&type=RT&data=" . $command . $address); } else { $gwcheck = file_get_contents("http://" . $this->GetIPGateway() . "/command?XC_FNC=SendSC&type=RT&data=" . $command . $address); } if ($gwcheck == "{XC_SUC}") { $this->response = true; } elseif ($gwcheck == "{XC_AUTH}") { $this->response = false; echo "Keine Authentifizierung möglich. Das Passwort für das Gateway ist falsch."; } return $this->response; }
protected function SetValueInteger($Ident, $value) { $id = $this->GetIDForIdent($Ident); SetValueInteger($id, $value); }
private function SetValueInteger($Ident, $value) { $id = $this->GetIDForIdent($Ident); if (GetValueInteger($id) != $value) { SetValueInteger($id, $value); } }
/** * Query Sensors * @param $branch string * @param $url string * @param $map array */ private function Query($branch, $url, $map) { $last_id = @$this->GetIDForIdent('LastUpdate'); $max = 0; if ($last_id) { $max = GetValueInteger($last_id); } $answer = chop(@file_get_contents($url)); $response = $http_response_header[0]; if (preg_match("/200\\s+OK\$/", $response) && strlen($answer) > 0) { $json = preg_replace('/list\\((\\{.*\\})\\)/s', '\\1', $answer); $data = json_decode($json); switch ($branch) { case 'Sensor': $data = $data->{'sensor'}; break; case 'Actor': $data = $data->{'actuator'}; break; } if (!$data) { IPS_LogMessage("XS1", "no sensor data returned"); return; } $n = 0; foreach ($data as $dev) { $n++; //xs1 number parameter is serialno of sensor list $data = array(); $caps = ''; $type = $dev->{'type'}; if ($type == 'disabled') { continue; } if (isset($map[$type])) { $mod = $map[$type]['typ']; $cap = $map[$type]['cap']; } else { IPS_LogMessage(__CLASS__, __FUNCTION__ . "::{$branch}: Unsupported type {$type}"); continue; } $devname = $dev->{'name'}; $val = $dev->{'value'}; $unit = utf8_decode($dev->{'unit'}); $utime = $dev->{'utime'}; //id needs protocol V15+ $id = isset($dev->{'id'}) ? $dev->{'id'} : $n; //get ips varids $data['Branch'] = $branch; $data['Id'] = $n; $data['Name'] = utf8_encode($devname); $data['Typ'] = $type; $data['TS'] = $utime; $data[$cap] = $val; //actur functions if ($branch == "Actor") { $fun = ''; $fl = array(); $fl[$cap] = 0; if (isset($dev->{'function'})) { $fun = 'Functions:'; foreach ($dev->{'function'} as $f) { $ft = $f->{'type'}; switch ($ft) { case 'off_wait_on': case 'on_wait_off': //$fl["Timer"]=1; //timer not implemented yet break; case 'on': case 'off': $fl["Switch"] = 1; break; case 'dimmer': //$fl["Dimmer"]=1; //dimmer not implemented yet break; case 'long_on': case 'long_off': //$fl["Shutter"]=1; //shutter not implemeted yet break; case 'disabled': break; default: $this->debug(__FUNCTION__, "Unimplemented function '{$ft}''"); } $fun .= "{$ft},"; } //collect caps foreach ($fl as $ft => $val) { $caps .= "{$ft}"; if ($val == 1) { $caps .= ':1'; } $caps .= ";"; } } $this->debug(__FUNCTION__, "{$branch}: {$n}({$id}) Name: {$devname}, Type: {$type}, Val: {$val}, {$fun}"); } elseif ($branch == "Sensor") { $caps = "{$cap};TS"; $this->debug(__FUNCTION__, "{$branch}: {$n}({$id}) Name: {$devname}, Type: {$type}, Val: {$val}, Unit: '{$unit}'"); } $this->debug(__FUNCTION__, "{$branch}: {$n} Mod:{$mod}, Caps: {$caps}"); switch ($mod) { case 'WSDEV': $this->SendWSData($caps, $data); break; case 'EnergyDev': $this->SendENData($caps, $data); break; case 'SwitchDev': $this->SendSwitchData($caps, $data); break; default: IPS_LogMessage(__CLASS__, __FUNCTION__ . "::{$branch}: Unsupported Mod '{$mod}''"); } //store max timestamp value if ($utime > $max) { $max = $utime; } } //for //set max timestamp info SetValueInteger($last_id, $max); } else { IPS_LogMessage(__CLASS__, __FUNCTION__ . "::Error Answer calling {$url}"); } }
public function Set90() { SetValueInteger($this->GetIDForIdent('Dimmer'), 9); $command = "E80"; return $this->SendCommand($command); }
private function SendCommand(TXB_Command_Data $ATData) { if (!$this->HasActiveParent()) { throw new Exception("Instance has no active Parent."); } // $ReplayATData = new TXB_Command_Data(); $FrameID = $this->GetIDForIdent('FrameID'); $ReplyATDataID = $this->GetIDForIdent('ReplyATData'); if (!$this->lock('RequestSendData')) { throw new Exception('RequestSendData is locked'); } $Frame = GetValueInteger($FrameID); if ($Frame == 255) { $Frame = 1; } else { $Frame++; } SetValueInteger($FrameID, $Frame); if (!$this->lock('ReplyATData')) { $this->unlock('RequestSendData'); throw new Exception('ReplyATData is locked'); } SetValueString($ReplyATDataID, ''); $this->unlock('ReplyATData'); $ATData->FrameID = $Frame; try { $this->SendDataToParent($ATData); } catch (Exception $exc) { $this->unlock('RequestSendData'); throw new Exception($exc); } $ReplayATData = $this->WaitForResponse(); // IPS_LogMessage('ReplayATData:'.$this->InstanceID,print_r($ReplayATData,1)); if ($ReplayATData === false) { // Senddata('TX_Status','Timeout'); $this->unlock('RequestSendData'); throw new Exception('Send Data Timeout'); } if ($ReplayATData->Status == TXB_Command_Status::XB_Command_OK) { // Senddata('TX_Status','OK') $this->unlock('RequestSendData'); return $ReplayATData; } // Senddata('TX_Status','Error: '+ XB_Transmit_Status_to_String(fTransmitStatus)); $this->unlock('RequestSendData'); throw new Exception('Error on Transmit:' . ord($ReplayATData->Status)); }
/** * Initialization sequence */ private function init() { $this->debug(__FUNCTION__, 'executing Init'); $this->SyncParent(); $this->SetBuffer(''); SetValueInteger($this->GetIDForIdent('RecCount'), 0); $i = $this->GetWS300pcInterval(); $this->SetTimerInterval('Update', $i * 1000); //ms $this->SetTimerInterval('ReInit', 61200); //odd time to prevent clash with update //$this->ReadConfig(); $this->debug(__FUNCTION__, 'Init leaved'); }
/** * parsing 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 'Hum': //hum //hum case 'RainCounter': //raincounter //raincounter case 'Press': //pressure //pressure case 'Forecast': //willi //willi case 'UV': //UVIndex //UVIndex case 'Light': //Brightness //Brightness case 'Level': //level //level case 'TS': //TimeStamp //TimeStamp case 'Lost': //lost //lost case 'Signal': if (strlen($s) == 0) { continue; } $iv = (int) $s; SetValueInteger($vid, $iv); break; //float //float case 'Temp': //temp //temp case 'Wind': //wind //wind case 'WindChill': //wind //wind case 'WindGust': //wind //wind case 'WindDir': //wind //wind case 'Rain': //rain //rain case 'RainDaily': //rain this day //rain this day case 'RainHourly': //rain 1h //rain 1h case 'RainLastDay': //rain 24h if (strlen($s) == 0) { continue; } $fv = (double) $s; SetValueFloat($vid, $fv); break; //String //String case 'Name': // $st = utf8_decode($s); SetValueString($vid, $st); break; //special //special case 'IsRaining': //israining if ($s == 'YES') { SetValueBoolean($vid, true); $s = "Its Raining"; } else { SetValueBoolean($vid, false); $s = "{$cap}({$vid}): No Rain"; } break; //special //special case 'Storm': //israining if ($s == 'YES') { //is reversed SetValueBoolean($vid, false); $s = "Its Storm"; } else { SetValueBoolean($vid, true); $s = "OK"; } break; case 'Battery': //battery $state = !preg_match("/LOW|WARN/i", $s); //reversed SetValueBoolean($vid, $state); break; default: $this->debug(__FUNCTION__, "{$cap} not handled"); } $this->debug(__FUNCTION__, "{$cap}:({$vid})" . $s); } }
/** * parses an record string * * @param $txt string Output from ws2500 program * @return array */ private function Parse($txt) { /* # Sensorname[-number] (drop outs): values of sensor ## Blocknumber: Block(1) ## Date: Cal(date), time(sec) ## Station: Id(1) ## THS(Temp/humidity): Temperatur(�C), Humidity(%), New(1) ## PS(Pressure): Pressure-relativ(hPa), New ## RS(Rain): Counter(1), OneCount(mm/1000), Rain(mm/1000), Tol(1), New(1) ## WS(Wind): Speed(Km/h), Direction(�), Variance(�), New(1) ## LS(Light): Light(lux), Factor(1), Flag(1), Duration(h), DeltaDuration(min), New(1) ## PYS(Pyranometer): Energy(W/m), Factor(1) # Blocknumber: 348 Date: Sun May 8 06:56:17 2016, 1462690577 Station: 1 THS-1 (0): 24.9, 20, h THS-2 (1): 20.4, 44, 1 THS-3 (0): 23.7, 21, 1 THS-4 (0): 23.0, 31, 1 THS-5 (0): 22.1, 32, 1 THS-6 (0): 24.5, 28, 1 THS-7 (1): 17.3, 45, 1 THS-8 (1): 17.0, 51, 1 THS-17 (0): 23.2, 32, 1 PS (0): 1009, 1 LS (0): 479, 100, 0, 52.27, -1, 1 */ $lines = explode("\n", $txt); if (count($lines) < 4) { $this->debug(__FUNCTION__, 'Not enough data'); return; } foreach ($lines as $line) { if (!isset($line[0])) { continue; } if ($line[0] == '#') { continue; } if ($line[0] == '+') { continue; } $result = array(); $datum = date('Y-m-d H:i:s'); if (preg_match_all("/^([\\w-]+).*?:\\s+(.*)\$/", $line, $result)) { $dev = $result[1][0]; $typ = $dev; $id = 0; $p = strpos($dev, '-'); if ($p > 0) { $typ = substr($dev, 0, $p); $id = substr($dev, $p + 1); } $values = $result[2][0]; //$values=str_replace(" ",'',$values); $data = array(); $data['Id'] = $dev; $caps = ''; switch ($typ) { case 'Date': list($d, $ts) = explode(',', $values); $tsid = @$this->GetIDForIdent('TimeStamp'); if ($tsid > 0) { $old = GetValueInteger($tsid); if ($ts > $old) { SetValueInteger($tsid, $ts); } } $datum = date('Y-m-d H:i:s', $ts); $this->debug(__FUNCTION__, "Date: {$d}, TS {$ts}, Datum {$datum}"); break; case 'Blocknumber': $block = $values; $blid = @$this->GetIDForIdent('Block'); if ($blid > 0) { $old = GetValueInteger($blid); if ($block != $old) { SetValueInteger($blid, $block); } else { $this->debug(__FUNCTION__, "BlockNumber ({$block}) is the same, skipping"); return; } } $this->debug(__FUNCTION__, "Blocknumber: {$block}"); break; case 'Station': break; case 'THS': $values = str_replace(" ", "", $values); list($temp, $hum, $new) = explode(',', $values); $new = trim($new); if ($new != '0') { $data['Date'] = $datum; $data['Typ'] = 'T/F'; $caps .= 'Temp;Hum;'; if ($id == 17) { $data['Typ'] = 'Indoor'; $data['Id'] = 'Indoor'; $caps .= 'Press;'; } $data['Temp'] = $temp; $data['Hum'] = $hum; $this->debug(__FUNCTION__, "{$dev}: Temp:{$temp}, Hum:{$hum}"); $this->SendWSData($data, $caps); } break; case 'RS': $values = str_replace(" ", "", $values); list($rc, $cf, $rain, $tol, $new) = explode(',', $values); if ($new == 1) { $rcid = @$this->GetIDForIdent('LastRainCounter'); $dailyid = @$this->GetIDForIdent('NewDayRainCounter'); //build diffs $old = GetValueInteger($rcid); $daily = GetValueInteger($dailyid); $diff = $new - $old; //counter overflow 4096 if ($diff < 0) { $diff += 4096; } $dailydiff = $new - $daily; if ($dailydiff < 0) { $dailydiff += 4096; } $crain = $diff * $this->GetRainPerCount() / 1000; if ($crain != $rain) { $this->debug(__FUNCTION__, "Rain different c:{$crain},d:{$rain} "); } $raindaily = $dailydiff * $this->GetRainPerCount() / 1000; $dailyvar = IPS_GetVariable($dailyid); $dailyupdated = $dailyvar['VariableUpdated']; if (is_new_day($dailyupdated)) { //new day routine,set //$rcvar=IPS_GetVariable($rcid); //$updated=$rcvar['VariableUpdated']; //if($updated<$date) { //set last day sum $this->debug(__FUNCTION__, 'NewDay, Store old Counter'); SetValueInteger($dailyid, $old); //} } if ($new > $old) { SetValueInteger($rcid, $new); } if ($rain < 0 or $rain > 100) { $rain = 0; } if ($raindaily < 0 or $raindaily > 500) { $raindaily = 0; } $data['Date'] = $datum; $data['Typ'] = 'Rain'; $data['Rain'] = $rain; $data['RainCounter'] = $rc; $data['RainDaily'] = $raindaily; $data['CounterFactor'] = $cf; $caps .= 'RainCounter;Rain;RainDaily;'; $this->debug(__FUNCTION__, "Rain Counter:{$rc}, Rain:{$rain}, cf: {$cf}, daily: {$raindaily} ,TOL:{$tol}"); $this->SendWSData($data, $caps); } break; case 'WS': $values = str_replace(" ", "", $values); list($speed, $dir, $var, $new) = explode(',', $values); if ($new == 1) { $data['Date'] = $datum; $data['Typ'] = 'Wind'; $data['WindSpeed'] = $speed; $data['WindDir'] = $dir; $data['WindVar'] = $var; $caps .= 'WindSpeed;WindDir;WindVar'; $this->debug(__FUNCTION__, "Wind Speed:{$speed}, Dir:{$dir}, Var: {$var}"); $this->SendWSData($data, $caps); } break; case 'LS': $values = str_replace(" ", "", $values); list($light, $factor, $flag, $dur, $deltadur, $new) = explode(',', $values); if ($new == 1) { $data['Date'] = $datum; $data['Typ'] = 'Light'; $data['Light'] = $light * $factor; $caps .= 'Light;'; $this->debug(__FUNCTION__, "Light {$light} factor: {$factor}, Flag:{$flag}, Dur:{$dur}, Deltadur:{$deltadur}"); $this->SendWSData($data, $caps); } break; case 'PYS': $values = str_replace(" ", "", $values); list($light, $factor, $new) = explode(',', $values); if ($new == 1) { $data['Date'] = $datum; $data['Typ'] = 'Pyrano'; $data['UV'] = $light * $factor; $caps .= 'UV;'; $this->debug(__FUNCTION__, "PYR {$light} factor: {$factor} "); $this->SendWSData($data, $caps); } break; case 'PS': $values = str_replace(" ", "", $values); list($press, $new) = explode(',', $values); if ($new == 1) { $data['Date'] = $datum; $data['Typ'] = 'Indoor'; $data['Id'] = 'Indoor'; $data['Press'] = $press; $caps .= 'Press;'; $this->debug(__FUNCTION__, "Press {$press}"); $this->SendWSData($data, $caps); } break; default: $this->debug(__FUNCTION__, "Unknown type '{$typ}'"); break; } //switch } //match line } //for lines }