1. Go to this page and download the library: Download adam-innes/alpha-hue library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adam-innes / alpha-hue example snippets
here are instructions on how to obtain Hostname and Username below.
$bridge_hostname = '192.168.1.1';
$bridge_username = 'xxxxxxxxxxx';
$hue = new \AlphaHue\AlphaHue($bridge_hostname, $bridge_username);
// Get all light IDs.
$light_ids = $hue->getLightIds();
// Turning lights on by ID.
foreach ($light_ids as $light_id) {
$hue->togglePower($light_id, 'on');
}
// Turning lights off by ID.
foreach ($light_ids as $light_id) {
$hue->togglePower($light_id, 'off');
}
$powered_on = $hue->getLightOnStatus($light_id); // True if on, false if off.
$hue->deleteLight($light_id);
# Set the light to Red.
$hue->setLightToHex($light_id, '#ff0000');
# Set the light to Blue.
$rgb = array(
'r' => 0,
'g' => 0,
'b' => 255
);
$hue->setLightToRGB($light_id, $rgb);
# Get the state of light 1
$state = $hue->getLightState(1);
# Sets the light state to a Red, max brightness.
$red = $hue->getXYPointFromHex('#ff0000');
$lightAttributes = array(
'on' => true,
'bri' => 254, // max brightness is 254
'xy' => $red
);
$hue->setLightState(1, $lightAttributes);
$group_ids = $hue->getGroups();
# Create a group titled 'New Group'
$response = $hue->createGroup('New Group');
# Change group 1 name and set lights 1 and 2 to be the group members.
$attributes = array(
'name' => 'New Group Name',
'lights' => array(1, 2),
);
$hue->setGroupAttributes(1, $attributes);