PHP code example of adam-innes / alpha-hue

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);

# Delete group 1.
$hue->deleteGroup(1);

$red = $hue->getXYPointFromHex('#ff0000');
$groupAttributes = array(
  'on'  => true,
  'bri' => 254, // max brightness is 254
  'xy'  => $red
);
$hue->setGroupState(1, $groupAttributes);

# Get list of rules stored in the bridge.
$rules = $hue->getRules();

# Get rule with a rule ID of 1.
$rule = $hue->getRule(1);

# Delete a rule with ID 1.
$hue->deleteRule(1);

# Get an array of all sensor information.
$sensors = $hue->getSensors();

# Get schedules.
$schedules = $hue->getSchedules();

$hue->config['name']; // Bridge Name.
$hue->config['apiversion']; // Bridge API Version.
$hue->config['ipaddress']; // Bridge IP Address

$ php composer.phar install