<?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";
<?php /** * Example: Delete test group. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php delete-group.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Deleting group 1:', "\n"; $client->getGroups()[1]->delete(); echo "Done.", "\n";
<?php /** * Example: List timezones. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php list-timezones.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Listing timezones:', "\n"; foreach ($client->getTimezones() as $timezone) { echo $timezone, "\n"; }
<?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"; $client->sendCommand((new \Phue\Command\SetGroupState(0))->scene('phue-test'));
<?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: Delete a schedule. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php delete-schedule.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Deleting schedule 1:', "\n"; $schedules = $client->getSchedules(); $schedules[1]->delete(); 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: List rules. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php list-rules.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Listing rules:', "\n"; foreach ($client->getRules() as $rule) { echo "\t", "#{$rule->getId()} - {$rule->getName()}", "\n", "\t\t", "Last Triggered Time: {$rule->getLastTriggeredTime()}", "\n", "\t\t", "Creation time: {$rule->getCreationTime()}", "\n", "\t\t", "Times triggered: {$rule->getTriggeredCount()}", "\n", "\t\t", "Owner: {$rule->getOwner()}", "\n", "\t\t", "Status: ", $rule->isEnabled() ? 'Yes' : 'No', "\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: 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 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: List sensors. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php list-sensors.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Listing sensors:', "\n"; foreach ($client->getSensors() as $sensor) { echo "\t", "#{$sensor->getId()} - {$sensor->getName()}", "\n", "\t\t", "Type: {$sensor->getType()}", "\n", "\t\t", "Model Id: {$sensor->getModelId()}", "\n", "\t\t", "Manufacturer Name: {$sensor->getManufacturerName()}", "\n", "\t\t", "Software Version: {$sensor->getSoftwareVersion()}", "\n", "\t\t", "Unique Id: {$sensor->getUniqueId()}", "\n", "\t\t", "Model name: {$sensor->getModel()->getName()}", "\n"; foreach ($sensor->getState() as $key => $value) { echo "\t\t", "State - {$key}: ", json_encode($value), "\n"; } foreach ($sensor->getConfig() as $key => $value) { echo "\t\t", "Config - {$key}: ", json_encode($value), "\n"; } }
<?php /** * Example: List groups registered on bridge. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php list-groups.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Listing groups:', "\n"; foreach ($client->getGroups() as $group) { echo "\t", "#{$group->getId()} - {$group->getName()}", "\n", "\t\t Type: ", $group->getType(), "\n", "\t\t Lights: ", implode(', ', $group->getLightIds()), "\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: List scenes registered on bridge. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php list-scenes.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Listing scenes:', "\n"; foreach ($client->getScenes() as $scene) { echo "\t", "#{$scene->getId()} - {$scene->getName()}", "\n", "\t\t", "Light Ids: ", implode(', ', $scene->getLightIds()), "\n", "\t\t", "Is active: ", $scene->isActive() ? 'Yes' : 'No', "\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"; $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: Set bridge config. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php set-bridge-config.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); $bridge = $client->getBridge(); // Turn bridge link button on. $bridge->setLinkButtonOn(true)->setTimezone('America/Los_Angeles')->enableDhcp(true)->setProxyAddress()->setProxyPort();
<?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: 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: List users. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php list-users.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Listing users:', "\n"; foreach ($client->getUsers() as $user) { echo "\t", "{$user->getUsername()} - {$user->getDeviceType()}", "\n", "\t\t", "Create date: {$user->getCreateDate()}", "\n", "\t\t", "Last use date: {$user->getLastUseDate()}", "\n"; }
<?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: List lights registered on bridge. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php list-lights.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Listing lights:', "\n"; foreach ($client->getLights() as $light) { echo "\t", "#{$light->getId()} - {$light->getName()} - {$light->getModel()}", "\n", "\t\t", "Unique Id: {$light->getUniqueId()}", "\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: List schedules. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php list-schedules.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Listing schedules:', "\n"; foreach ($client->getSchedules() as $schedule) { echo "\t", "#{$schedule->getId()} - {$schedule->getName()}", "\n", "\t\t", "Time scheduled: {$schedule->getTime()}", "\n", "\t\t", "Method: {$schedule->getCommand()['method']}", "\n", "\t\t", "Address: {$schedule->getCommand()['address']}", "\n", "\t\t", "Body: ", json_encode($schedule->getCommand()['body']), "\n", "\t\t", "Status: ", $schedule->getStatus(), "\n", "\t\t", "Autodelete: ", $schedule->isAutoDeleted() ? 'Yes' : 'No', "\n"; }
<?php /** * Example: Delete a schedule. * * Usage: HUE_HOST=127.0.0.1 HUE_USERNAME=1234567890 php delete-schedule.php */ require_once 'common.php'; $client = new \Phue\Client($hueHost, $hueUsername); echo 'Deleting schedule 1:', "\n"; $client->getSchedules()[1]->delete(); echo 'Done.', "\n";