Using the hue API and the shortcuts app, you can create some advanced automations you can’t normally run with the normal shortcuts or home app.
For example, fade a light on or off over 15 minutes, or make all your lights cycle through all the colors of the rainbow.
You need to do two steps to get started:
1. Set your hue bridge to a static IP address on your local network2. Create an API username using Philips’s instructions here
Once you’ve done that, you can start making issuing commands to the hue bridge using the “get contents of URL” action.
The API documentation here and CLIP debugger linked in item 2 above is great. I’m not a programmer but I was able to make a few neat shortcuts using this.
First example: Make all the lights in your house cycle through the colors of the rainbow.
Create action with “get contents of url” and set the url to this, where the IP address is your bridge address, and username is the username you generated in step 2
http://192.168.1.2/api/USERNAME/groups/0/action/
Press “show more” and set “Method: Put” and “Request Body: JSON”.
Add the following fields:
Boolean: on: true
Number: bri: 254
Number: sat: 254
Hue: number: 0
Text: effect: colorloop
Run the shortcut, and you’re done.
Second example: fade a light off over 15 minutes.
First, go to the CLIP debugger from the getting started link in item 2 above. Find the list of all your lights by entering /api/USERNAME/ in the URL field, and clicking GET.
Next, create a “get contents of URL” action in shortcuts with the URL
http://192.168.1.2/api/USERNAME/lights/1/state
Where 1 is replaced with the number of your target light.
Set this action to “Method: Put” and “Request Body: JSON”
Add the following fields:
Boolean: on: false
Transitiontime: 9000
Where the transitiontime number is 15 minutes in 10ths of a second.
Hopefully this is enough to get started. Read the documentation to learn about addressing lights and groups, or how to send other types of commands (increment brightness, set color temperature, etc.)
Here’s some things I’ve done:
- Automation to fade my lights on in the bedroom slowly before my alarm comes on- a command to slowly fade the lights out in the bedroom at slightly different rates so they don’t all go off at once
- set a lamp to a different color depending on what the temperature is going to be that day
A few of my expamples are here.