<?php /** * Example: Create test group. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php create-group.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Creating test group', "\n"; $groupId = $client->sendCommand(new \Phue\Command\CreateGroup('Test Group', [$client->getLights()[4], $client->getLights()[5]])); echo 'Group Id: ', $groupId, "\n";
<?php /** * Example: All lights to a scene. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php all-lights-scene.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Setting all lights to a scene.', "\n"; $x = new \Phue\Command\SetGroupState(0); $y = $x->scene('phue-test'); $client->sendCommand($y);
<?php /** * Example: Create test sensor. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php create-sensor.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Creating test sensor', "\n"; $sensorId = $client->sendCommand((new \Phue\Command\CreateSensor('Test sensor'))->modelId('TestSensor')->softwareVersion(1)->type('CLIPGenericFlag')->uniqueId('123.456.789')->manufacturerName('PhueClient')->stateAttribute('flag', true)->configAttribute('on', true)->configAttribute('reachable', true)->configAttribute('battery', 100)->configAttribute('url', 'http://example.org')); echo 'Sensor Id: ', $sensorId, "\n";
<?php /** * Example: Schedule all lights to change. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php schedule-all-lights-change.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Scheduling lights to dim, then become bright, 3 times, 1 second periods.', "\n"; $client->sendCommand(new \Phue\Command\CreateSchedule('Dim all lights', (new \Phue\TimePattern\Timer(1))->repeat(3), (new \Phue\Command\SetGroupState(0))->brightness(1))); $client->sendCommand(new \Phue\Command\CreateSchedule('Brighten all lights', (new \Phue\TimePattern\Timer(1))->repeat(3), (new \Phue\Command\SetGroupState(0))->brightness(255))); echo 'Done.', "\n";
<?php /** * Example: Update test sensor. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php update-sensor.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Updating test rule', "\n"; $sensor = $client->getSensors()[4]; $client->sendCommand((new \Phue\Command\UpdateSensor($sensor))->name('Test sensor new name')); $client->sendCommand((new \Phue\Command\UpdateSensorState($sensor))->stateAttribute('flag', false)); $client->sendCommand((new \Phue\Command\UpdateSensorConfig($sensor))->configAttribute('battery', 99));
<?php /** * Example: Candle effect. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php candle-effect.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Starting candle effect.', "\n"; while (true) { // Randomly choose values $brightness = rand(20, 60); $colorTemp = rand(440, 450); $transitionTime = rand(0, 3) / 10; // Send command $client->sendCommand((new \Phue\Command\SetLightState(4))->brightness($brightness)->colorTemp($colorTemp)->transitionTime($transitionTime)); // Sleep for transition time plus extra for request time usleep($transitionTime * 1000000 + 25000); }
<?php /** * Example: Update test rule. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php update-rule.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Updating test rule', "\n"; $sensor = $client->getSensors()[2]; $rule = $client->getRules()[5]; $client->sendCommand((new \Phue\Command\UpdateRule($rule))->name('New name')->addCondition((new \Phue\Condition())->setSensorId($sensor)->setAttribute('lastupdated')->changed())->addAction((new \Phue\Command\SetGroupState(0))->brightness(200)));
<?php /** * Example: Schedule a specific groups state. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php schedule-group-state.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Scheduling group 1 state.', "\n"; $x = new \Phue\Command\CreateSchedule(); $y = new \Phue\Command\SetGroupState(1); $z = $x->name('Group 1 dimmer')->description('Dims the lights for group 1')->time('+10 seconds')->command($y->brightness(255))->status(\Phue\Schedule::STATUS_ENABLED)->autodelete(true); $client->sendCommand($z); echo 'Done.', "\n";
<?php /** * Example: Create test scene, set state, and assign to group. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php create-scene-state.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Creating test scene', "\n"; $sceneId = 'phue-test'; $lightIds = [4, 5]; // Create/modify scene $client->sendCommand(new \Phue\Command\CreateScene($sceneId, 'Test Scene', $lightIds)); echo 'Buffering light states', "\n"; // Iterate through each light and buffer state foreach ($lightIds as $lightId) { $client->sendCommand((new \Phue\Command\SetSceneLightState($sceneId, $lightId))->brightness(255)->hue(50000)->transitionTime(0)); } echo 'Done.', "\n";
<?php /** * Example: Create test sensor. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php create-sensor.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Creating test sensor', "\n"; $x = new \Phue\Command\CreateSensor('Test sensor'); $y = $x->modelId('TestSensor')->softwareVersion(1)->type('CLIPGenericFlag')->uniqueId('123.456.789')->manufacturerName('PhueClient')->stateAttribute('flag', true)->configAttribute('on', true)->configAttribute('reachable', true)->configAttribute('battery', 100)->configAttribute('url', 'http://example.org'); $sensorId = $client->sendCommand($y); echo 'Sensor Id: ', $sensorId, "\n";
<?php /** * Example: Create test scene, set state, and assign to group. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php create-scene-state.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Creating test scene', "\n"; $sceneId = 'phue-test'; $lightIds = array(4, 5); // Create/modify scene $client->sendCommand(new \Phue\Command\CreateScene($sceneId, 'Test Scene', $lightIds)); echo 'Buffering light states', "\n"; // Iterate through each light and buffer state foreach ($lightIds as $lightId) { $x = new \Phue\Command\SetSceneLightState($sceneId, $lightId); $y = $x->brightness(255)->hue(50000)->transitionTime(0); $client->sendCommand($y); } echo 'Done.', "\n";
<?php /** * Example: Create test rule. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php create-rule.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Creating test rule', "\n"; $sensors = $client->getSensors(); $sensor = $sensors[2]; $rule = new \Phue\Command\CreateRule('Button 1 press'); $cond1 = new \Phue\Condition(); $cond2 = new \Phue\Condition(); $g_state = new \Phue\Command\SetGroupState(0); $cmd = $rule->addCondition($cond1->setSensorId($sensor)->setAttribute('buttonevent')->equals()->setValue(\Phue\SensorModel\ZgpswitchModel::BUTTON_2))->addCondition($cond2->setSensorId($sensor)->setAttribute('lastupdated')->changed())->addAction($g_state->brightness(2)); $ruleId = $client->sendCommand($cmd); echo 'Rule Id: ', $ruleId, "\n";
<?php /** * Example: Create test rule. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php create-rule.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Creating test rule', "\n"; $sensor = $client->getSensors()[2]; $ruleId = $client->sendCommand((new \Phue\Command\CreateRule('Button 1 press'))->addCondition((new \Phue\Condition())->setSensorId($sensor)->setAttribute('buttonevent')->equals()->setValue(\Phue\SensorModel\ZgpswitchModel::BUTTON_2))->addCondition((new \Phue\Condition())->setSensorId($sensor)->setAttribute('lastupdated')->changed())->addAction((new \Phue\Command\SetGroupState(0))->brightness(2))); echo 'Rule Id: ', $ruleId, "\n";
<?php /** * Example: Schedule a specific groups state. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php schedule-group-state.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Scheduling group 1 state.', "\n"; $client->sendCommand((new \Phue\Command\CreateSchedule())->name('Group 1 dimmer')->description('Dims the lights for group 1')->time('+10 seconds')->command((new \Phue\Command\SetGroupState(1))->brightness(255))->status(\Phue\Schedule::STATUS_ENABLED)->autodelete(true)); echo 'Done.', "\n";
<?php /** * Example: All lights to colorloop effect. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php all-lights-colorloop.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Setting all lights to colorloop effect.', "\n"; $client->sendCommand((new \Phue\Command\SetGroupState(0))->effect('colorloop'));
<?php /** * Example: Create test group. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php create-group.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Creating test group', "\n"; $lights = $client->getLights(); $groupId = $client->sendCommand(new \Phue\Command\CreateGroup('Test Group', array($lights[4], $lights[5]))); echo 'Group Id: ', $groupId, "\n";
<?php /** * Example: All lights to a scene. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php all-lights-scene.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Setting all lights to a scene.', "\n"; $client->sendCommand((new \Phue\Command\SetGroupState(0))->scene('phue-test'));
<?php /** * Example: Schedule all lights to change. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php schedule-all-lights-change.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Scheduling lights to dim, then become bright, 3 times, 1 second periods.', "\n"; $x1 = new \Phue\TimePattern\Timer(1); $y1 = new \Phue\Command\SetGroupState(0); $z1 = new \Phue\Command\CreateSchedule('Dim all lights', $x1->repeat(3), $y1->brightness(1)); $client->sendCommand($z1); $x2 = new \Phue\TimePattern\Timer(1); $y2 = new \Phue\Command\SetGroupState(0); $z2 = new \Phue\Command\CreateSchedule('Brighten all lights', $x2->repeat(3), $y2->brightness(255)); $client->sendCommand($z2); echo 'Done.', "\n";