Class properties:
Class methods:
$volume=round(65535*$params['VALUE']/100); $this->setProperty('volumeLevel',$params['VALUE']); safe_exec('..\\apps\\nircmd\\nircmdc setsysvolume '.$volume); say("Изменилась громкость до ".$params['VALUE']." процентов");
Class objects:
say("Отключено питание");
$command=$params['command']; $short_command=''; $dt=recognizeTime($command,$short_command); if (preg_match('/скажи сколько врем/is',$command)) { if ($dt>0) { addScheduledJob("command".$dt,"processCommand('".$short_command."');",$dt); say('Задача принята',2); return; } global $voicemode; $voicemode='on'; say('Сейчас '.timeNow(),2); } elseif (preg_match('/сколько время/is',$command)) { if ($dt>0) { addScheduledJob("command".$dt,"processCommand('".$short_command."');",$dt); say('Задача принята'); echo $short_command; return; } say('Сейчас '.timeNow()); } elseif (preg_match('/повтори (.+)/is',$command,$m) || preg_match('/скажи (.+)/is',$command,$m)) { if ($dt>0) { addScheduledJob("command".$dt,"processCommand('".$short_command."');",$dt); say('Задача принята',2); return; } global $voicemode; $voicemode='on'; say($m[1],2); } else { say('Повтори',2); }
Class properties:
Class methods:
//$params['t'] $this->setProperty("updated",time()); $this->setProperty("updatedTime",date("H:i",time())); $this->setProperty("alive",1); $ot=$this->object_title; $alive_timeout=(int)$this->getProperty("aliveTimeOut"); if (!$alive_timeout) { $alive_timeout=30*60; } clearTimeOut($ot."_alive"); setTimeOut($ot."_alive","sg('".$ot.".alive',0);",$alive_timeout); if (!isset($params['h'])) { return; } $old_temp=$this->getProperty('humidity'); $t=round($params['h'],1); if ($t>100) return; $this->setProperty('humidity',$t); if ($params['uptime']) { $this->setProperty('uptime',$params['uptime']); } if ($t>$old_temp) { $d=1; } elseif ($t<$old_temp) { $d=-1; } else { $d=0; } $this->setProperty('direction',$d); $linked_room=$this->getProperty("LinkedRoom"); if ($linked_room) { setGlobal($linked_room.'.Humidity',$t); }
Class objects:
Class properties:
Class methods:
if ($params['status']) { $this->setProperty('status',$params['status']); } $this->setProperty('updatedTimestamp',time()); $this->setProperty("alive",1); $ot=$this->object_title; $alive_timeout=(int)$this->getProperty("aliveTimeOut"); if (!$alive_timeout) { $alive_timeout=12*60*60; } clearTimeOut($ot."_alive"); setTimeOut($ot."_alive","sg('".$ot.".alive',0);",$alive_timeout);
Class properties:
Class methods:
$this->setProperty('status',$params['status']); // выставляем статус сенсора $this->setProperty('updatedTimestamp',time()); // выставляем время срабатывания сенсора $this->setProperty('alive',1); $ot=$this->object_title; $alive_timeout=(int)$this->getProperty("aliveTimeOut"); if (!$alive_timeout) { $alive_timeout=24*60*60; } clearTimeOut($ot."_alive"); setTimeOut($ot."_alive","sg('".$ot.".alive',0);",$alive_timeout); if ($params['status']) { $this->setProperty('motionDetected',1); clearTimeOut($this->object_title.'_detected'); setTimeOut($this->object_title.'_detected',"setGlobal('".$this->object_title.".motionDetected',0);",30); $linked_room=$this->getProperty('LinkedRoom'); if ($linked_room!='') { callMethod($linked_room.'.onActivity'); } if ($this->object_title=='sensorMovement3' || $this->object_title=='sensorMovementRemote1' || $this->object_title=='sensorMovementRemote2') { //|| $this->object_title=='sensorMovement5' return; // не реагируем на движение в спальне, по ip-сенсорам и по сенсору на втром этаже } ClearTimeOut("nobodyHome"); SetTimeOut("nobodyHome","callMethod('NobodyHomeMode.activate');", 1*60*60); // выполняем если целый час никого не было if (getGlobal('NobodyHomeMode.active')) { callMethod('NobodyHomeMode.deactivate'); } $last_register=registeredEventTime('inhouseMovement'); // проверяем когда в последний раз срабатывало событие "движение внутри дома" registerEvent('inhouseMovement',$this->name,2); // регистрируем событие "движение внутри дома" if (timeBetween('05:00', '12:00') && ((time()-$last_register)>2*60*60)) { runScript('Greeting'); // запускаем скрипт "доброе утро" } }
Class objects:
Class properties:
Class methods:
$command=$params['command']; $value=$params['value']; $host=$this->getProperty('Host'); $type=(int)$this->getProperty('LampType'); $zone=(int)$this->getProperty('Zone'); $milight = new Milight($host); $commands=''; if ($type==0) { if ($zone==1) { if ($command=='on') { $milight->whiteGroup1On(); } if ($command=='off') { $milight->whiteGroup1Off(); } } if ($zone==2) { if ($command=='on') { $milight->whiteGroup2On(); } if ($command=='off') { $milight->whiteGroup2Off(); } } if ($zone==3) { if ($command=='on') { $milight->whiteGroup3On(); } if ($command=='off') { $milight->whiteGroup3Off(); } } if ($zone==4) { if ($command=='on') { $milight->whiteGroup4On(); } if ($command=='off') { $milight->whiteGroup4Off(); } } } if ($type==1) { if ($command=='level') { $milight->setRgbwActiveGroup($zone); $milight->rgbwBrightnessPercent($value); } if ($command=='color') { $milight->setRgbwActiveGroup($zone); $milight->rgbwSetColorHexString($value); } if ($zone==1) { if ($command=='on') { $milight->rgbwGroup1On(); } if ($command=='off') { $milight->rgbwGroup1Off(); } if ($command=='white') { $milight->rgbwGroup1SetToWhite(); } } if ($zone==2) { if ($command=='on') { $milight->rgbwGroup2On(); } if ($command=='off') { $milight->rgbwGroup2Off(); } if ($command=='white') { $milight->rgbwGroup2SetToWhite(); } } if ($zone==3) { if ($command=='on') { $milight->rgbwGroup3On(); } if ($command=='off') { $milight->rgbwGroup3Off(); } if ($command=='white') { $milight->rgbwGroup3SetToWhite(); } } if ($zone==4) { if ($command=='on') { $milight->rgbwGroup4On(); } if ($command=='off') { $milight->rgbwGroup4Off(); } if ($command=='white') { $milight->rgbwGroup4SetToWhite(); } } } /* * Milight/LimitlessLED/EasyBulb PHP API * The MIT License (MIT) * * Copyright (c) 2014 Yashar Rashedi <info@rashedi.com> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ class Milight { private $host; private $port; private $delay = 100000; //microseconds private $rgbwActiveGroup = 0; // 0 means all private $whiteActiveGroup = 0; // 0 means all private $commandCodes = array( //RGBW Bubls commands 'rgbwAllOn' => array(0x42, 0x00), 'rgbwAllOff' => array(0x41, 0x00), 'rgbwGroup1On' => array(0x45, 0x00), 'rgbwGroup2On' => array(0x47, 0x00), 'rgbwGroup3On' => array(0x49, 0x00), 'rgbwGroup4On' => array(0x4B, 0x00), 'rgbwGroup1Off' => array(0x46, 0x00), 'rgbwGroup2Off' => array(0x48, 0x00), 'rgbwGroup3Off' => array(0x4a, 0x00), 'rgbwGroup4Off' => array(0x4c, 0x00), 'rgbwBrightnessMax' => array(0x4e, 0x1b), 'rgbwBrightnessMin' => array(0x4e, 0x02), 'rgbwDiscoMode' => array(0x4d, 0x00), 'rgbwDiscoSlower' => array(0x43, 0x00), 'rgbwDiscoFaster' => array(0x44, 0x00), 'rgbwAllSetToWhite' => array(0xc2, 0x00), 'rgbwGroup1SetToWhite' => array(0xc5, 0x00), 'rgbwGroup2SetToWhite' => array(0xc7, 0x00), 'rgbwGroup3SetToWhite' => array(0xc9, 0x00), 'rgbwGroup4SetToWhite' => array(0xcb, 0x00), 'rgbwSetColorToViolet' => array(0x40, 0x00), 'rgbwSetColorToRoyalBlue' => array(0x40, 0x10), 'rgbwSetColorToBabyBlue' => array(0x40, 0x20), 'rgbwSetColorToAqua' => array(0x40, 0x30), 'rgbwSetColorToRoyalMint' => array(0x40, 0x40), 'rgbwSetColorToSeafoamGreen' => array(0x40, 0x50), 'rgbwSetColorToGreen' => array(0x40, 0x60), 'rgbwSetColorToLimeGreen' => array(0x40, 0x70), 'rgbwSetColorToYellow' => array(0x40, 0x80), 'rgbwSetColorToYellowOrange' => array(0x40, 0x90), 'rgbwSetColorToOrange' => array(0x40, 0xa0), 'rgbwSetColorToRed' => array(0x40, 0xb0), 'rgbwSetColorToPink' => array(0x40, 0xc0), 'rgbwSetColorToFusia' => array(0x40, 0xd0), 'rgbwSetColorToLilac' => array(0x40, 0xe0), 'rgbwSetColorToLavendar' => array(0x40, 0xf0), //white Bulb commands 'whiteAllOn' => array(0x35, 0x00), 'whiteAllOff' => array(0x39, 0x00), 'whiteBrightnessUp' => array(0x3c, 0x00), 'whiteBrightnessDown' => array(0x34, 0x00), 'whiteAllBrightnessMax' => array(0xb5, 0x00), 'whiteAllNightMode' => array(0xbb, 0x00), 'whiteWarmIncrease' => array(0x3e, 0x00), 'whiteCoolIncrease' => array(0x3f, 0x00), 'whiteGroup1On' => array(0x38, 0x00), 'whiteGroup1Off' => array(0x3b, 0x00), 'whiteGroup2On' => array(0x3d, 0x00), 'whiteGroup2Off' => array(0x33, 0x00), 'whiteGroup3On' => array(0x3a, 0x00), 'whiteGroup3Off' => array(0x32, 0x00), 'whiteGroup4On' => array(0x32, 0x00), 'whiteGroup4Off' => array(0x36, 0x00), 'whiteGroup1BrightnessMax' => array(0xb8, 0x00), 'whiteGroup2BrightnessMax' => array(0xbd, 0x00), 'whiteGroup3BrightnessMax' => array(0xb7, 0x00), 'whiteGroup4BrightnessMax' => array(0xb2, 0x00), 'whiteGroup1NightMode' => array(0xbb, 0x00), 'whiteGroup2NightMode' => array(0xb3, 0x00), 'whiteGroup3NightMode' => array(0xba, 0x00), 'whiteGroup4NightMode' => array(0xb6, 0x00), ); /** * @param int $delay */ public function setDelay($delay) { $this->delay = $delay; } /** * @return int */ public function getDelay() { return $this->delay; } /** * @param int $rgbwActiveGroup * @throws Exception */ public function setRgbwActiveGroup($rgbwActiveGroup) { if ($rgbwActiveGroup < 0 || $rgbwActiveGroup > 4) { throw new \Exception('Active RGBW Group must be between or equal 0 to 4, note: 0 means all groups'); } $this->rgbwActiveGroup = $rgbwActiveGroup; } //the same as setRgbwActiveGroup just to make method invocation easier according to convention public function rgbwSetActiveGroup($rgbwActiveGroup) { $this->setRgbwActiveGroup($rgbwActiveGroup); } /** * @throws Exception * @return int */ public function getRgbwActiveGroup() { return $this->rgbwActiveGroup; } /** * @param int $whiteActiveGroup * @throws Exception */ public function setWhiteActiveGroup($whiteActiveGroup) { if ($whiteActiveGroup < 0 || $whiteActiveGroup > 4) { throw new \Exception('Active White Group must be between or equal 0 to 4, note: 0 means all groups'); } $this->whiteActiveGroup = $whiteActiveGroup; } //the same as setWhiteActiveGroup just to make method invocation easier according to convention public function whiteSetActiveGroup($whiteActiveGroup) { $this->setWhiteActiveGroup($whiteActiveGroup); } /** * @throws Exception * @return int */ public function getWhiteActiveGroup() { return $this->whiteActiveGroup; } public function __construct($host = '10.10.100.254', $port = 8899) { $this->host = $host; $this->port = $port; } public function sendCommand(Array $command) { $command[] = 0x55; //last byte always 0x55, will appended to all commands $message = vsprintf(str_repeat('%c', count($command)), $command); if ($socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) { socket_sendto($socket, $message, strlen($message), 0, $this->host, $this->port); socket_close($socket); usleep($this->getDelay()); //wait 100ms before sending next command } } public function command($commandName) { $this->sendCommand($this->commandCodes[$commandName]); } public function rgbwSendOnToActiveGroup() { if ($this->getRgbwActiveGroup() > 0) { $activeGroupOnCommand = 'rgbwGroup' . $this->getRgbwActiveGroup() . 'On'; $this->command($activeGroupOnCommand); return true; } $this->rgbwAllOn(); return true; } public function whiteSendOnToActiveGroup() { if ($this->getWhiteActiveGroup() > 0) { $activeGroupOnCommand = 'whiteGroup' . $this->getWhiteActiveGroup() . 'On'; $this->command($activeGroupOnCommand); return true; } $this->whiteAllOn(); return true; } public function rgbwAllOn() { $this->command('rgbwAllOn'); } public function rgbwAllOff() { $this->command('rgbwAllOff'); } public function rgbwGroup1On() { $this->command('rgbwGroup1On'); } public function rgbwGroup2On() { $this->command('rgbwGroup2On'); } public function rgbwGroup3On() { $this->command('rgbwGroup3On'); } public function rgbwGroup4On() { $this->command('rgbwGroup4On'); } public function rgbwGroup1Off() { $this->command('rgbwGroup1Off'); } public function rgbwGroup2Off() { $this->command('rgbwGroup2Off'); } public function rgbwGroup3Off() { $this->command('rgbwGroup3Off'); } public function rgbwGroup4Off() { $this->command('rgbwGroup4Off'); } public function rgbwBrightnessMax() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwBrightnessMax'); } public function rgbwBrightnessMin() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwBrightnessMin'); } public function rgbwAllBrightnessMin() { $this->setRgbwActiveGroup(0); $this->rgbwSendOnToActiveGroup(); $this->command('rgbwBrightnessMin'); } public function rgbwAllBrightnessMax() { $this->setRgbwActiveGroup(0); $this->rgbwSendOnToActiveGroup(); $this->command('rgbwBrightnessMax'); } public function rgbwGroup1BrightnessMax() { $this->setRgbwActiveGroup(1); $this->rgbwSendOnToActiveGroup(); $this->command('rgbwBrightnessMax'); } public function rgbwGroup2BrightnessMax() { $this->setRgbwActiveGroup(2); $this->rgbwSendOnToActiveGroup(); $this->command('rgbwBrightnessMax'); } public function rgbwGroup3BrightnessMax() { $this->setRgbwActiveGroup(3); $this->rgbwSendOnToActiveGroup(); $this->command('rgbwBrightnessMax'); } public function rgbwGroup4BrightnessMax() { $this->setRgbwActiveGroup(4); $this->rgbwSendOnToActiveGroup(); $this->command('rgbwBrightnessMax'); } public function rgbwGroup1BrightnessMin() { $this->setRgbwActiveGroup(1); $this->rgbwSendOnToActiveGroup(); $this->command('rgbwBrightnessMin'); } public function rgbwGroup2BrightnessMin() { $this->setRgbwActiveGroup(2); $this->rgbwSendOnToActiveGroup(); $this->command('rgbwBrightnessMin'); } public function rgbwGroup3BrightnessMin() { $this->setRgbwActiveGroup(3); $this->rgbwSendOnToActiveGroup(); $this->command('rgbwBrightnessMin'); } public function rgbwGroup4BrightnessMin() { $this->setRgbwActiveGroup(4); $this->rgbwSendOnToActiveGroup(); $this->command('rgbwBrightnessMin'); } public function rgbwBrightnessPercent($brightnessPercent) { if ($brightnessPercent < 0 || $brightnessPercent > 100) { throw new \Exception('Brightness percent must be between 0 and 100'); } $brightness = 0x02; $this->rgbwSendOnToActiveGroup(); if ($brightnessPercent < 14) { $brightness = 0x02; } if ($brightnessPercent >= 14 && $brightnessPercent < 17) { $brightness = 0x03; } if ($brightnessPercent >= 17 && $brightnessPercent < 21) { $brightness = 0x04; } if ($brightnessPercent >= 21 && $brightnessPercent < 24) { $brightness = 0x05; } if ($brightnessPercent >= 24 && $brightnessPercent < 28) { $brightness = 0x06; } if ($brightnessPercent >= 28 && $brightnessPercent < 32) { $brightness = 0x07; } if ($brightnessPercent >= 32 && $brightnessPercent < 35) { $brightness = 0x08; } if ($brightnessPercent >= 35 && $brightnessPercent < 39) { $brightness = 0x09; } if ($brightnessPercent >= 39 && $brightnessPercent < 42) { $brightness = 0xa0; } if ($brightnessPercent >= 42 && $brightnessPercent < 46) { $brightness = 0xb0; } if ($brightnessPercent >= 46 && $brightnessPercent < 50) { $brightness = 0xc0; } if ($brightnessPercent >= 50 && $brightnessPercent < 53) { $brightness = 0xd0; } if ($brightnessPercent >= 53 && $brightnessPercent < 57) { $brightness = 0xe0; } if ($brightnessPercent >= 57 && $brightnessPercent < 60) { $brightness = 0xf0; } if ($brightnessPercent >= 60 && $brightnessPercent < 64) { $brightness = 0x10; } if ($brightnessPercent >= 64 && $brightnessPercent < 68) { $brightness = 0x11; } if ($brightnessPercent >= 68 && $brightnessPercent < 71) { $brightness = 0x12; } if ($brightnessPercent >= 71 && $brightnessPercent < 75) { $brightness = 0x13; } if ($brightnessPercent >= 75 && $brightnessPercent < 78) { $brightness = 0x14; } if ($brightnessPercent >= 78 && $brightnessPercent < 82) { $brightness = 0x15; } if ($brightnessPercent >= 82 && $brightnessPercent < 86) { $brightness = 0x16; } if ($brightnessPercent >= 86 && $brightnessPercent < 89) { $brightness = 0x17; } if ($brightnessPercent >= 89 && $brightnessPercent < 93) { $brightness = 0x18; } if ($brightnessPercent >= 93 && $brightnessPercent < 96) { $brightness = 0x19; } if ($brightnessPercent >= 96 && $brightnessPercent < 100) { $brightness = 0x1a; } if ($brightnessPercent >= 96 && $brightnessPercent <= 100) { $brightness = 0x1b; } $this->sendCommand(array(0x4e, $brightness)); } public function rgbwDiscoMode() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwDiscoMode'); } public function rgbwDiscoSlower() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwDiscoSlower'); } public function rgbwDiscoFaster() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwDiscoFaster'); } public function rgbwAllSetToWhite() { $this->command('rgbwAllSetToWhite'); } public function rgbwGroup1SetToWhite() { $this->command('rgbwGroup1SetToWhite'); } public function rgbwGroup2SetToWhite() { $this->command('rgbwGroup2SetToWhite'); } public function rgbwGroup3SetToWhite() { $this->command('rgbwGroup3SetToWhite'); } public function rgbwGroup4SetToWhite() { $this->command('rgbwGroup4SetToWhite'); } public function rgbwSetColorToViolet() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToViolet'); } public function rgbwSetColorToRoyalBlue() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToRoyalBlue'); } public function rgbwSetColorToBabyBlue() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToBabyBlue'); } public function rgbwSetColorToAqua() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToAqua'); } public function rgbwSetColorToRoyalMint() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToRoyalMint'); } public function rgbwSetColorToSeafoamGreen() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToSeafoamGreen'); } public function rgbwSetColorToGreen() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToGreen'); } public function rgbwSetColorToLimeGreen() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToLimeGreen'); } public function rgbwSetColorToYellow() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToYellow'); } public function rgbwSetColorToYellowOrange() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToYellowOrange'); } public function rgbwSetColorToOrange() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToOrange'); } public function rgbwSetColorToRed() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToRed'); } public function rgbwSetColorToPink() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToPink'); } public function rgbwSetColorToFusia() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToFusia'); } public function rgbwSetColorToLilac() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToLilac'); } public function rgbwSetColorToLavendar() { $this->rgbwSendOnToActiveGroup(); $this->command('rgbwSetColorToLavendar'); } public function whiteAllOn() { $this->command('whiteAllOn'); } public function whiteAllOff() { $this->command('whiteAllOff'); } public function whiteBrightnessUp() { $this->whiteSendOnToActiveGroup(); $this->command('whiteBrightnessUp'); } public function whiteBrightnessDown() { $this->whiteSendOnToActiveGroup(); $this->command('whiteBrightnessDown'); } public function whiteAllBrightnessMax() { $this->command('whiteAllBrightnessMax'); } public function whiteAllBrightnessMin() { $this->setWhiteActiveGroup(0); $this->whiteSendOnToActiveGroup(); for ($i = 0; $i < 10; $i++) { $this->command('whiteBrightnessDown'); } } public function whiteAllNightMode() { $this->command('whiteAllNightMode'); } public function whiteWarmIncrease() { $this->whiteSendOnToActiveGroup(); $this->command('whiteWarmIncrease'); } public function whiteCoolIncrease() { $this->whiteSendOnToActiveGroup(); $this->command('whiteCoolIncrease'); } public function whiteGroup1On() { $this->command('whiteGroup1On'); } public function whiteGroup1Off() { $this->command('whiteGroup1Off'); } public function whiteGroup2On() { $this->command('whiteGroup2On'); } public function whiteGroup2Off() { $this->command('whiteGroup2Off'); } public function whiteGroup3On() { $this->command('whiteGroup3On'); } public function whiteGroup3Off() { $this->command('whiteGroup3Off'); } public function whiteGroup4On() { $this->command('whiteGroup4On'); } public function whiteGroup4Off() { $this->command('whiteGroup4Off'); } public function whiteGroup1BrightnessMax() { $this->command('whiteGroup1BrightnessMax'); } public function whiteGroup2BrightnessMax() { $this->command('whiteGroup2BrightnessMax'); } public function whiteGroup3BrightnessMax() { $this->command('whiteGroup3BrightnessMax'); } public function whiteGroup4BrightnessMax() { $this->command('whiteGroup4BrightnessMax'); } public function whiteGroup1BrightnessMin() { $this->setWhiteActiveGroup(1); $this->whiteSendOnToActiveGroup(); for ($i = 0; $i < 10; $i++) { $this->command('whiteBrightnessDown'); } } public function whiteGroup2BrightnessMin() { $this->setWhiteActiveGroup(2); $this->whiteSendOnToActiveGroup(); for ($i = 0; $i < 10; $i++) { $this->command('whiteBrightnessDown'); } } public function whiteGroup3BrightnessMin() { $this->setWhiteActiveGroup(3); $this->whiteSendOnToActiveGroup(); for ($i = 0; $i < 10; $i++) { $this->command('whiteBrightnessDown'); } } public function whiteGroup4BrightnessMin() { $this->setWhiteActiveGroup(4); $this->whiteSendOnToActiveGroup(); for ($i = 0; $i < 10; $i++) { $this->command('whiteBrightnessDown'); } } public function whiteGroup1NightMode() { $this->command('whiteGroup1NightMode'); } public function whiteGroup2NightMode() { $this->command('whiteGroup2NightMode'); } public function whiteGroup3NightMode() { $this->command('whiteGroup3NightMode'); } public function whiteGroup4NightMode() { $this->command('whiteGroup4NightMode'); } public function rgbwSetColorHsv(Array $hsvColor) { $milightColor = $this->hslToMilightColor($hsvColor); $activeGroupOnCommand = 'rgbwGroup' . $this->getRgbwActiveGroup() . 'On'; $this->command($activeGroupOnCommand); $this->sendCommand(array(0x40, $milightColor)); } public function rgbwSetColorHexString($color) { $rgb = $this->rgbHexToIntArray($color); $hsl = $this->rgbToHsl($rgb[0], $rgb[1], $rgb[2]); $milightColor = $this->hslToMilightColor($hsl); $this->rgbwSendOnToActiveGroup(); $this->sendCommand(array(0x40, $milightColor)); } public function rgbHexToIntArray($hexColor) { $hexColor = ltrim($hexColor, '#'); $hexColorLenghth = strlen($hexColor); if ($hexColorLenghth != 8 && $hexColorLenghth != 6) { throw new \Exception('Color hex code must match 8 or 6 characters'); } if ($hexColorLenghth == 8) { $r = hexdec(substr($hexColor, 2, 2)); $g = hexdec(substr($hexColor, 4, 2)); $b = hexdec(substr($hexColor, 6, 2)); if (($r == 0 && $g == 0 && $b == 0) || ($r == 255 && $g == 255 && $b == 255)) { throw new \Exception('Color cannot be black or white'); } return array($r, $g, $b); } $r = hexdec(substr($hexColor, 0, 2)); $g = hexdec(substr($hexColor, 2, 2)); $b = hexdec(substr($hexColor, 4, 2)); if (($r == 0 && $g == 0 && $b == 0) || ($r == 255 && $g == 255 && $b == 255)) { throw new \Exception('Color cannot be black or white'); } return array($r, $g, $b); } public function rgbToHsl($r, $g, $b) { $r = $r / 255; $g = $g / 255; $b = $b / 255; $max = max($r, $g, $b); $min = min($r, $g, $b); $l = ($max + $min) / 2; $d = $max - $min; $h = ''; if ($d == 0) { $h = $s = 0; } else { $s = $d / (1 - abs(2 * $l - 1)); switch ($max) { case $r: $h = 60 * fmod((($g - $b) / $d), 6); if ($b > $g) { $h += 360; } break; case $g: $h = 60 * (($b - $r) / $d + 2); break; case $b: $h = 60 * (($r - $g) / $d + 4); break; } } return array($h, $s, $l); } public function hslToMilightColor($hsl) { $color = (256 + 176 - (int)($hsl[0] / 360.0 * 255.0)) % 256; return $color + 0xfa; } }
$this->setProperty('status',0); $this->callMethod('sendCommand',array('command'=>'off'));
$this->setProperty('status',1); $this->callMethod('sendCommand',array('command'=>'on'));
$status=$this->getProperty("status"); if ($status) { $this->callMethod('turnOn'); } else { $this->callMethod('turnOff'); }
$level=$this->getProperty("Level"); if ($level>0) { $this->callMethod('setLevel',array('level'=>$level)); } else { $this->callMethod('turnOff'); }
$colors=array( '#ff0000', '#00ff00', '#0000ff'); $color=$colors[rand(0,count($colors)-1)]; $this->callMethod('setColor',array('color'=>$color));
$this->setProperty('Mode','C'); $this->setProperty('Color',$params['color']); $this->callMethod('sendCommand',array('command'=>'color','value'=>$params['color']));
$this->setProperty('Level',$params['level']); $this->callMethod('sendCommand',array('command'=>'level','value'=>$params['level']));
$this->setProperty('Mode','W'); $this->callMethod('sendCommand',array('command'=>'white'));
Class objects:
Class properties:
Class methods:
$sunrise=gg("openweather.ow_fact.sunrise"); $sunset=gg("openweather.ow_fact.sunset"); sg("ThisComputer.SunSetTime", date("H:i", $sunset)); sg("ThisComputer.SunRiseTime", date("H:i", $sunrise));
Class objects:
Class properties:
Class methods:
$this->setProperty('active',1);
$this->setProperty('active',0);
$this->setProperty("updated",time()); $this->setProperty("updatedTime",date('H:i')); if ($this->getProperty('active')) { say("Режим ".$this->getProperty('title')." активирован."); } else { say("Режим ".$this->getProperty('title')." выключен."); }
Class objects:
setGlobal('minMsgLevel','2');
setGlobal('minMsgLevel','1');
Class objects:
include_once(DIR_MODULES.'app_radio/app_radio.class.php'); $app_radio=new app_radio(); if(is_array($params)) { if(isset($params['sta'])) $app_radio->change_station($params['sta'],$app_radio); if(isset($params['cmd'])) $app_radio->control($params['cmd']); if(isset($params['vol'])) $app_radio->set_volume($params['vol'],$app_radio); } else { if($params=='play' || $params=='stop') $app_radio->control($params); else if(strpos($params, "vol")===0) $app_radio->set_volume((int)substr($params,3),$app_radio); else if(strpos($params, "sta:")===0) $app_radio->change_station(substr($params,4),$app_radio); }
Class properties:
Class methods:
$status=$this->getProperty("status"); if ($status) { $this->callMethod('turnOn'); } else { $this->callMethod('turnOff'); }
$status=$this->getProperty("status"); if ($status) { $this->callMethod('turnOff'); } else { $this->callMethod('turnOn'); }
$this->setProperty("status",0);
$this->setProperty("status",1);
Class objects:
Class properties:
Class methods:
$cmdline='"/usr/local/bin/nooLite.exe" -api '.$params['command']; $last_called=gg('NoolightCommandSend'); $min_delay=3; $now=time(); if (($now-$last_called)>$min_delay) { //safe_exec($cmdline); $last_callled=$now; sg('NoolightCommandSend',$last_called); DebMes("Noolite instant exec: ".$cmdline); //system($cmdline); exec($cmdline); } else { if ($last_callled<$now) { $last_callled=$now; } $last_called+=$min_delay; sg('NoolightCommandSend',$last_called); DebMes("Noolite scheduled job for ".date('H:i:s',$last_called)); AddScheduledJob("noolight".md5($cmdline),"safe_exec('".$cmdline."');",$last_called); }
$this->setProperty("status",0); //safe_exec('"c:\Program Files\nooLite\noolite.exe" -api -off_ch'.$this->getProperty("channel")); $this->callMethod("sendCommand",array('command'=>'-off_ch'.$this->getProperty("channel")));
$this->setProperty("status",1); $this->callMethod("sendCommand",array('command'=>'-on_ch'.$this->getProperty("channel")));
Class properties:
Class methods:
$code1=$this->getProperty('Code1'); $code2=$this->getProperty('Code2'); safe_exec("c:\_majordomo\apps\arduino_gw\arduino_gw.exe rcon$code1:$code2;"); $this->setProperty("status",1);
$code1=$this->getProperty('Code1'); $code2=$this->getProperty('Code2'); safe_exec("c:\_majordomo\apps\arduino_gw\arduino_gw.exe rcoff$code1:$code2;"); $this->setProperty("status",0);
Class properties:
Class methods:
$latestActivity=$this->getProperty('LatestActivity'); $this->setProperty('LatestActivity',time()); $this->setProperty('LatestActivityTime',date('H:i')); $this->setProperty('SomebodyHere',1); $ot=$this->object_title; if ($this->getProperty("IdleDelay")) { $activity_timeout=(int)$this->getProperty("IdleDelay"); } else { $activity_timeout=10*60; } clearTimeOut($ot."_activity_timeout"); setTimeOut($ot."_activity_timeout","callMethod('".$ot.".onIdle');",$activity_timeout); $this->callMethod("updateActivityStatus");
$this->setProperty('SomebodyHere',0);
$rooms=getObjectsByClass("Rooms"); $total=count($rooms); for($i=0;$i<$total;$i++) { $rooms[$i]['room']=getGlobal($rooms[$i]['TITLE'].'.Title'); if (!$rooms[$i]['room']) { $rooms[$i]['room']=$rooms[$i]['TITLE']; } $rooms[$i]['active']=getGlobal($rooms[$i]['TITLE'].'.SomebodyHere'); $rooms[$i]['time']=getGlobal($rooms[$i]['TITLE'].'.LatestActivity'); $rooms[$i]['diff']=time()-$rooms[$i]['time']; } function cmp($a, $b) { if ($a['diff'] == $b['diff']) { return 0; } return ($a['diff'] < $b['diff']) ? -1 : 1; } usort($rooms,"cmp"); if (!$rooms[0]['active']) { $somebodyHomeText="Никого нет дома. Были в ".date('H:i',$rooms[0]['time'])." (".$rooms[0]['room'].")"; } else { $res_rooms=array(); for($i=0;$i<$total;$i++) { if ($rooms[$i]['active']) { $res_rooms[]=$rooms[$i]['room']; } } $somebodyHomeText="Кто-то дома: ".implode(", ",$res_rooms); } setGlobal('somebodyHomeText',$somebodyHomeText); //echo "Updated";
Class objects:
Class methods:
Class objects:
echo "status received: ".$params['status'];
global $voicemode; $voicemode='off'; processCommand($params['message']);
Class properties:
Class methods:
$status=$this->getProperty("status"); if ($status) { $this->setProperty("status",0) } else { $this->setProperty("status",1); }
$status=$this->getProperty("status"); $recv_status=$this->getProperty("recv_status"); if ($recv_status == "ON" && !$status) { $this->setProperty('status',1); } else if ($recv_status == "OFF" && $status) { $this->setProperty('status',0); }
Class objects:
Class properties:
Class methods:
Class objects:
$details=array(); $red_state=0; $yellow_state=0; if (!isOnline('Internet')) { $yellow_state=1; $details[]=LANG_GENERAL_NO_INTERNET_ACCESS; } if ($red_state) { $state='red'; $state_title=LANG_GENERAL_RED; } elseif ($yellow_state) { $state='yellow'; $state_title=LANG_GENERAL_YELLOW; } else { $state='green'; $state_title=LANG_GENERAL_GREEN; } $new_details=implode(". ",$details); if ($this->getProperty("stateDetails")!=$new_details) { $this->setProperty('stateDetails',$new_details); } if ($this->getProperty('stateColor')!=$state) { $this->setProperty('stateColor',$state); $this->setProperty('stateTitle',$state_title); if ($state!='green') { say(LANG_GENERAL_COMMUNICATION_STATE." ".LANG_GENERAL_CHANGED_TO." ".$state_title."."); say(implode(". ",$details)); } else { say(LANG_GENERAL_COMMUNICATION_STATE." ".LANG_GENERAL_RESTORED_TO." ".$state_title); } $this->callMethod('stateChanged'); }
$details=array(); $red_state=0; $yellow_state=0; $cycles=array('states'=>'states','main'=>'main','execs'=>'exec','scheduler'=>'scheduler'); foreach($cycles as $k=>$v) { $tm=getGlobal('ThisComputer.cycle_'.$k.'Run'); if (time()-$tm>5*60) { $red_state=1; $details[]=$v." ".LANG_GENERAL_CYCLE." ".LANG_GENERAL_STOPPED."."; } } $cycles=array('ping'=>'ping','webvars'=>'webvars'); foreach($cycles as $k=>$v) { $tm=getGlobal('ThisComputer.cycle_'.$k.'Run'); if (time()-$tm>10*60) { $yellow_state=1; $details[]=$v." ".LANG_GENERAL_CYCLE." ".LANG_GENERAL_STOPPED."."; } } if ($red_state) { $state='red'; $state_title=LANG_GENERAL_RED; } elseif ($yellow_state) { $state='yellow'; $state_title=LANG_GENERAL_YELLOW; } else { $state='green'; $state_title=LANG_GENERAL_GREEN; } $new_details=implode(". ",$details); if ($this->getProperty("stateDetails")!=$new_details) { $this->setProperty('stateDetails',$new_details); } if ($this->getProperty('stateColor')!=$state) { $this->setProperty('stateColor',$state); $this->setProperty('stateTitle',$state_title); if ($state!='green') { say(LANG_GENERAL_SYSTEM_STATE." ".LANG_GENERAL_CHANGED_TO." ".$state_title."."); say(implode(". ",$details)); } else { say(LANG_GENERAL_SYSTEM_STATE." ".LANG_GENERAL_RESTORED_TO." ".$state_title); } $this->callMethod('stateChanged'); }
$details=array(); $red_state=0; $yellow_state=0; if ($red_state) { $state='red'; $state_title=LANG_GENERAL_RED; } elseif ($yellow_state) { $state='yellow'; $state_title=LANG_GENERAL_YELLOW; } else { $state='green'; $state_title=LANG_GENERAL_GREEN; } $new_details=implode(". ",$details); if ($this->getProperty("stateDetails")!=$new_details) { $this->setProperty('stateDetails',$new_details); } if ($this->getProperty('stateColor')!=$state) { $this->setProperty('stateColor',$state); $this->setProperty('stateTitle',$state_title); if ($state!='green') { say(LANG_GENERAL_SECURITY_STATE." ".LANG_GENERAL_CHANGED_TO." ".$state_title."."); say(implode(". ",$details)); } else { say(LANG_GENERAL_SECURITY_STATE." ".LANG_GENERAL_RESTORED_TO." ".$state_title); } $this->callMethod('stateChanged'); }
Class methods:
Class objects:
$command = $params['command']; $option = $params['option']; $amihost = $this->getProperty('amihost'); $amiport = $this->getProperty('amiport'); $amiusername = $this->getProperty('amiusername'); $amipassword = $this->getProperty('amipassword'); include_once ('./lib/phpagi/phpagi-asmanager.php'); if (!$params['command']) { DebMes (" Asterisk : Can't process empty command"); exit; }; if (!$amihost) { DebMes (" Asterisk : Can't process command - AMI is not configured"); exit; }; $com_man = new AGI_AsteriskManager(); if (!$com_man->connect($amihost.":".$amiport, $amiusername, $amipassword)) { DebMes (" Asterisk : Can't connect to AMI "); exit; }; $response = $com_man->$command($option); $com_man->disconnect(); if ($response['Response'] != 'Success') { DebMes (" Asterisk : Can't process command => ".$response['Message']); }; return $response; // For debug // DebMes (" Asterisk : Process command $command"); // DebMes ($response);
Class properties:
Class methods:
//$params['t'] $this->setProperty("updated",time()); $this->setProperty("updatedTime",date("H:i",time())); $this->setProperty("alive",1); $ot=$this->object_title; $alive_timeout=(int)$this->getProperty("aliveTimeOut"); if (!$alive_timeout) { $alive_timeout=30*60; } clearTimeOut($ot."_alive"); setTimeOut($ot."_alive","sg('".$ot.".alive',0);",$alive_timeout); if ($this->getProperty("min") > $this->getProperty('temp')){ say($this->description." ниже ".$this->getProperty("min")." градусов", 2); } /* if ($this->getProperty("max") < $params['t']){ say("Температура на ".$ot." выше ".$this->getProperty("min")." градусов", 2); } */ if (!isset($params['t'])) { return; } $old_temp=$this->getProperty('temp'); $t=round($params['t'],1); if ($t>110) return; $this->setProperty('temp',$t); if ($params['uptime']) { $this->setProperty('uptime',$params['uptime']); } if ($t>$old_temp) { $d=1; } elseif ($t<$old_temp) { $d=-1; } else { $d=0; } $this->setProperty('direction',$d); $linked_room=$this->getProperty("LinkedRoom"); if ($linked_room) { setGlobal($linked_room.'.Temperature',$t); } /* */
Class objects:
Class properties:
Class methods:
/* START yaWeather module*/ $updateTime = gg('yw_setting.updateTime'); if($updateTime > 0){ $count = gg('yw_setting.countTime'); if($count >= $updateTime){ include_once(DIR_MODULES.'app_yaweather/app_yaweather.class.php'); $app_yaweather=new app_yaweather(); $app_yaweather->get_weather(gg('yw_setting.city_id')); sg('yw_setting.countTime',1); } else { $count++; sg('yw_setting.countTime',$count); } }/* END yaWeather*///START openweather module $updateTime = gg('ow_setting.updateTime'); if($updateTime > 0) { $count = gg('ow_setting.countTime'); if($count >= $updateTime) { include_once(DIR_MODULES . 'app_openweather/app_openweather.class.php'); $app_openweather = new app_openweather(); $app_openweather->get_weather(gg('ow_city.id')); sg('ow_setting.countTime', 1); } else { $count++; sg('ow_setting.countTime', $count); } } // END openweather module//START openweather module $updateTime = gg('ow_setting.updateTime'); if($updateTime > 0) { $count = gg('ow_setting.countTime'); if($count >= $updateTime) { include_once(DIR_MODULES . 'app_openweather/app_openweather.class.php'); $app_openweather = new app_openweather(); $app_openweather->get_weather(gg('ow_city.id')); sg('ow_setting.countTime', 1); } else { $count++; sg('ow_setting.countTime', $count); } } // END openweather module//START openweather module $updateTime = gg('ow_setting.updateTime'); if($updateTime > 0) { $count = gg('ow_setting.countTime'); if($count >= $updateTime) { include_once(DIR_MODULES . 'app_openweather/app_openweather.class.php'); $app_openweather = new app_openweather(); $app_openweather->get_weather(gg('ow_city.id')); sg('ow_setting.countTime', 1); } else { $count++; sg('ow_setting.countTime', $count); } } // END openweather module//START openweather module $updateTime = gg('ow_setting.updateTime'); if($updateTime > 0) { $count = gg('ow_setting.countTime'); if($count >= $updateTime) { include_once(DIR_MODULES . 'app_openweather/app_openweather.class.php'); $app_openweather = new app_openweather(); $app_openweather->get_weather(gg('ow_city.id')); sg('ow_setting.countTime', 1); } else { $count++; sg('ow_setting.countTime', $count); } } // END openweather module//START openweather module $updateTime = gg('ow_setting.updateTime'); if($updateTime > 0) { $count = gg('ow_setting.countTime'); if($count >= $updateTime) { include_once(DIR_MODULES . 'app_openweather/app_openweather.class.php'); $app_openweather = new app_openweather(); $app_openweather->get_weather(gg('ow_city.id')); sg('ow_setting.countTime', 1); } else { $count++; sg('ow_setting.countTime', $count); } } // END openweather module
Class objects:
$h=(int)date('G',time()); $m=date('i',time()); if (isWeekDay()) { } if (($h>=8) && getGlobal('clockChimeEnabled')) { if ($m=="00") { say(timeNow(),1); } } setGlobal('timeNow',date('H:i')); $homeStatus=date('H:i'); if (getGlobal('NobodyHomeMode.active')) { $homeStatus.=' Дома никого'; } else { $homeStatus.=' Дома кто-то есть'; } $homeStatus.=' '.getGlobal('Security.stateDetails'); $homeStatus.=' '.getGlobal('System.stateDetails'); $homeStatus.=' '.getGlobal('Communication.stateDetails'); setGlobal('HomeStatus',$homeStatus); if (timeBetween(getGlobal('SunRiseTime'),getGlobal('SunSetTime')) && getGlobal('isDark')=="1") { setGlobal("isDark",0); callMethod('DarknessMode.deactivate'); } elseif (!timeBetween(getGlobal('SunRiseTime'),getGlobal('SunSetTime')) && getGlobal('isDark')!="1") { setGlobal("isDark",1); callMethod('DarknessMode.activate'); } if (timeIs(getGlobal('SunRiseTime'))) { say('Всходит солнце'); } if (timeIs(getGlobal('SunSetTime'))) { say('Солнце заходит',2); } if (timeIs("23:30") && (gg("EconomMode.active")!="1") && (gg("NobodyHomeMode.active")=="1")) { say("Похоже никого нет сегодня, можно сэкономить немного."); callMethod('EconomMode.activate'); } if (timeIs('20:00')) { callMethod('NightMode.activate'); } elseif (timeIs('08:00')) { callMethod('NightMode.deactivate'); } if (timeIs("03:00")) { runScript("systemMaintenance"); } if (gg('ThisComputer.AlarmStatus') && timeIs(gg('ThisComputer.AlarmTime'))) { runScript('MorningAlarm'); }
Class methods:
Class objects:
if ($params['serial']=='' && $params['devname']!='') { $params['serial']=$params['devname']; } $device=SQLSelectOne("SELECT * FROM usbdevices WHERE SERIAL LIKE '".$params['serial']."'"); if (!$device['ID']) { // new device connected //say("Подключено новое устройство",1); $device=array(); $device['SERIAL']=$params['serial']; $device['TITLE']='устройство '.$params['devname']; $device['FIRST_FOUND']=date('Y-m-d H:i:s'); $device['LAST_FOUND']=date('Y-m-d H:i:s'); $device['LOG'].=$device['FIRST_FOUND'].' подключено (впервые)'."\n"; $device['ID']=SQLInsert('usbdevices',$device); } else { // device already in our database //say("Подключено ".$device['TITLE'],1); if ($device['USER_ID']) { $user=SQLSelectOne("SELECT * FROM users WHERE ID='".$device['USER_ID']."'"); if ($user['ID']) { //$user['NAME']; // теперь мы знаем имя пользователя, связанного с этим устройством } } $device['LAST_FOUND']=date('Y-m-d H:i:s'); $device['LOG']=$device['LAST_FOUND'].' подключено'."\n".$device['LOG']; SQLUpdate('usbdevices',$device); if ($device['SCRIPT_ID']!='') { runScript($device['SCRIPT_ID'],$params); } elseif ($device['SCRIPT']!='') { eval($device['SCRIPT']); } }
Class properties:
Class objects:
, Россия
© 2024 - Site Built By SergeJey | Реквизиты: Курицын С. С. ИНН 762001394609 | Контакты | Public agreement
SmartLiving