A simple PHP command-line tool to control Philips Hue lights using the Philips Hue API.
- Turn lights on or off
- Set light color using hex values
- Adjust brightness (absolute or relative changes)
- Set color temperature
- List all connected lights and their statuses
- PHP 7.4 or higher
- Composer for dependency management
- A Philips Hue Bridge with at least one connected light
- A valid configuration file (
config.json) with bridge IP and API key
-
Clone the repository or download the source code:
git clone https://github.com/mfutselaar/huecontrol cd huecontrol -
Install dependencies using Composer:
composer install
-
Create a
config.jsonfile in the project root with the following structure:{ "bridge_ip": "your_bridge_ip", "key": null }Replace
your_bridge_ipwith the IP address of your Philips Hue Bridge. Thekeywill be automatically generated on first run.
Run the script from the command line using:
php src/index.php <light_name> [color] [options]<light_name>: (Required) The name of the light to control. Use--listto see available light names.[color]: (Optional) A hex color value (e.g.,#FF00FF) to set the light's color.
--help, -h: Display help information.--on: Turn the specified light on.--off: Turn the specified light off.--lights, --list, -l: List all connected lights and their statuses.--temperature <int>, -t <int>: Set the color temperature (within the light's supported range).--brightness <float>, -b <float>: Set brightness (e.g.,50for absolute,+10or-20for relative changes).
When you omit --on or --off, the light will be toggled in whatever the current opposite state is.
-
List all lights:
php src/index.php --list
-
Turn a light named "Living Room" on:
php src/index.php "Living Room" --on -
Set a light to a specific color:
php src/index.php "Bedroom Light" #FF0000
-
Adjust brightness by +10:
php src/index.php "Kitchen Light" --brightness +10 -
Set color temperature to 3000K:
php src/index.php "Office Light" --temperature 3000
On the first run, if no API key is present in config.json, the script will attempt to register with the Philips Hue Bridge:
- Run the script with any command (e.g.,
php src/index.php --list). - If prompted, press the link button on your Philips Hue Bridge.
- Re-run the command to complete registration. The API key will be saved to
config.json.
The config.json file must include:
bridge_ip: The IP address of your Philips Hue Bridge.key: The API key (initiallynull, auto-generated on first run).
Example:
{
"bridge_ip": "192.168.1.100",
"key": "your_api_key"
}Create a symlink in $HOME/.local/bin or anywhere else in your $PATH to src/index.php and chmod +x the symlink.
eg. ln -s ~/Projects/huecontrol/src/index.php ~/.local/bin/huecontrol && chmod +x ~/.local/bin/huecontrol. You can
from then on control your Hue system from anywhere by typing huecontrol livingroom
- Ensure the Philips Hue Bridge is powered on and accessible on the network.
- Color temperature and brightness values are validated against the light's supported range.
- "Bridge unavailable" error: Verify the
bridge_ipinconfig.jsonand ensure the bridge is powered on. - "Link button not pressed" error: Press the link button on the bridge and re-run the command.
- Invalid color or temperature: Ensure hex colors are prefixed with
#and temperature/brightness values are within valid ranges.