Ejemplo n.º 1
0
<?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";
Ejemplo n.º 2
0
<?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";
Ejemplo n.º 3
0
<?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";
}
Ejemplo n.º 4
0
<?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";
Ejemplo n.º 5
0
<?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'));
Ejemplo n.º 6
0
<?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);
Ejemplo n.º 7
0
<?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";
Ejemplo n.º 8
0
<?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";
Ejemplo n.º 9
0
<?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";
Ejemplo n.º 10
0
<?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";
}
Ejemplo n.º 11
0
<?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";
Ejemplo n.º 12
0
<?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";
Ejemplo n.º 13
0
<?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";
Ejemplo n.º 14
0
<?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);
}
Ejemplo n.º 15
0
<?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));
Ejemplo n.º 16
0
<?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";
    }
}
Ejemplo n.º 17
0
<?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";
}
Ejemplo n.º 18
0
<?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";
Ejemplo n.º 19
0
<?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";
}
Ejemplo n.º 20
0
<?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";
Ejemplo n.º 21
0
<?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();
Ejemplo n.º 22
0
<?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";
Ejemplo n.º 23
0
<?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'));
Ejemplo n.º 24
0
<?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";
Ejemplo n.º 25
0
<?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";
}
Ejemplo n.º 26
0
<?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)));
Ejemplo n.º 27
0
<?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";
}
Ejemplo n.º 28
0
<?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";
Ejemplo n.º 29
0
<?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";
}
Ejemplo n.º 30
0
<?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";