Get full voice control over your Hue lights: recall and save scenes, set timers and alarms, change colors, and trigger dynamic effects!
Story
Control Hue Lights with Alexa
Well, you already can turn them on and off and dim them with Alexa. But this Alexa program gives you much more control: change colors, recall scenes, save scenes, set timers, turn on dynamic effects (color loops and alerts) and, of course, turn them on and off and dim them.
This skill has three components:
- An Amazon Alexa Lambda function â thanks to Matt Kruseâ on AWS that just receives requests fromâŠ.
- An Alexa âskillâ that you set up in the Amazon Developerâs portal and passes commands ontoâŠ
- A server on your local network that does have access your Hue Bridge.
Please note that Alexa-Hue requires a server running all the time (or all the time you want to control your lights with Alexa.)
First, download this .zip file and unzip it in a folder thatâs easy to get to.
Creating the Lambda Function
For information on how to set up the Lambda function, look at the tutorial here.
Set up your developer account by following step #1. Then go through the instructions under step #2.
When you get to Step #2 5., youâll be copying and pasting in the text from lambda_passthrough.js that you downloaded from the repo. (Remember, itâs in that easy to get to folder.) Add your code as Node.js. Just copy and paste lambda_passthrough.js in the code editor.
Continue through Step #2 12.
When you Step #3, follow the instructions under 1. and 2. to set up a new skill. Then follow my instructions below (though the pictures in Step #3 of the tutorial are relevant and might still be helpful.)
Creating the Skill
To create your new skill, go to the Amazon developer portal, and click on the âAdd New Skillâ button, up there in the top right.
- For âSkill Typeâ just leave the default âCustom Interaction âModelâ
- For âNameâ pick anything you want.
- For âInvocation Nameâ pick anything you want. This is the name youâll use to open the skill (e.g., âAlexa, tell house lighting toâŠ.â)
- For âVersion NumberââŠanything. How about 0.0.1?
- For âEndpointâ select âLambda ARNâ and point it to your Lambda function by filling in the field with the proper resource name. Just go to your Lambda Function in the AWS Console. The ARN will look something like this: arn:aws:lambda:us-east-1:123456789805:function:my_function
- On the next page fill in the interaction model, custom slot values, and utterance samples by copying and pasting the info from intent_schema.txt, sample_utterances.txt and custom_slots.txt onto the appropriate form fields.
- Create custom slots first. In the âcustom slot typeâ section, youâll see a button âAdd Slot Type.â Click on that. Add the slot name in the âEnter Typeâ box. The name will be one of the all caps names from the custom_slots.txt, e.g., LIGHTS or ATTRIBUTE. Then paste in the values (they appear just below that all caps name in the custom_slots.txt), one value per line, in the âEnter Valuesâ box. Then click âOK.â In the end youâre going to create 7 different custom slots.
- Copy/paste the contents of intent_schema.txt into the âIntent Schemaâ box.
- Copy/paste the contents of utterance_samples.txt into the âSample Utterancesâ box.
Now, for the custom slot values âLIGHTSâ and âSCENESâ substitute in the appropriate values for your lights and scenes.
IMPORTANT NOTE: When filling in the LIGHTS custom slot, single bulbs should be indicated by âlightâ (e.g, âkitchen lightâ) and groups with âlightsâ (e.g., âliving room lights.) This means that you donât want the actual name of your lights to be something like âKitchen lightsâ or âBedroom light,â because then youâll have to say things like âTurn on the kitchen lights lights!â The name of the group/lights should just be âKitchenâ or âbedroom,â and in the LIGHTS custom slot youâll enter âKitchen lightsâ or âBedroom light.â
Installing the Server
Okay, now weâre done with the âcloudâ side of things. We need to set things up on your local network.
There are two ways to set the server up. If youâre running the server on Windows or OSX, the easiest way to get up and running is with a Docker containter. (Thanks to jpeffer for the work on Windows and OSX! The container includes the correct version of Ruby and everything required to get the server talking to your skill.
If you have a Raspberry Pi 3, you can still use Docker, though there are a few additional steps required to get Docker running on a Pi 3. Thanks to eschizoidfor the Raspberry Pi build of Alexa Hue, and for the startup script.)
You can also set up everything manually, skipping the Docker installation. (This is the only installation method available on Raspberry Pi 2 or earlier, and it still might be easier than using Docker on a Pi 3.) Iâve written some instructions for doing that here.
Docker Setup (for OSX, Windows, and Pi 3)
For Windows and OSX, install the correct version of Docker Toolbox for your OS.
â The default installation settings most likely adequate.
â Select âYesâ if prompted to install additional drivers.
If youâre installing Docker on a Rapsberry Pi 3, look at the instructions here. Assuming youâve got a copy of Raspbian Jessie running on your Pi, scroll down to the instructions in the Installing Docker section. Thatâs all you need to worry about.
Once youâve got Docker properly installed:
On Windows or OSX, open the Docker Quickstart Terminal (again, select âYesâ if prompted). On a Pi 3, open a terminal window in the folder where you unzipped the repo contents. Now, run a command of the following form:
bash start.sh <timezone> <win|mac|pi>
Supply the timezone and platform paratmeters that you want to use. (Thereâs a list of time zone codes at the end of this readme.) So, if youâre running your server on OSX, and your timezone is PDT, your command will look like:
bash start.sh âAmerica/Los_Angelesâ mac
If all goes well, you should end up looking at a screen with information like this on it:
Forwarding http://2a52d01e.ngrok.io -> docker-alexa-hue:4567
Forwarding https://2a52d01e.ngrok.io -> docker-alexa-hue:4567
(If all doesnât go well, and you get an error like: âUnable to connect to Docker Daemonâ, try sudo bash start.sh <timezone> <win|mac|pi>
Head back to the lambda function on aws and replace the application_id and url with the application_id of your skill (found in the developer portal) and the ip address of your server (e.g., the ip address of your ngrok tunnel.) So, line 9 (or so) of the Lambda function might look something like this:
âamzn1.echo-sdk-ams.app.3be28e92-xxxx-xxxx-xxxx-xxxxxxxxxxxxâ:âhttp://2a52d01e.ngrok.io/lightsâ
(Donât forget to at â /lights â to the end of the URL)
Almost done!!!!
Before you can use the skill, youâll need to give it access to your Hue bridge. Press the link button on your bridge and launch the skill (within, I think, 30 seconds or so.)
If you donât do this step, Alexa will remind you.
At this point the skill should be available to you. You can say things like:
âAlexa, tell [whatever invocation name you chose] to turn the kitchen lights blue.â
âAlexa, ask [whatever invocation name you chose] for blue kitchen lights.â
âAlexa, ask [whatever invocation name you chose] for a dark red bedside light.â
âAlexa, ask [whatever invocation name you chose] to set romantic scene.â
âAlexa, ask [whatever invocation name you chose] for romantic scene.â
âAlexa, ask [whatever invocation name you chose] for a green bedside light.â
âAlexa, tell [whatever invocation name you chose] to turn the bedroom lights dark red.â
âAlexa, tellâŠset the floor light to saturation ten and brightness fiveâ
âAlexa, tellâŠschedule dinner scene at 8:30 pmâ
âAlexa, tellâŠchange the table light to the color relaxâ
âAlexa, tellâŠturn off the bedroom lights in 5 minutesâ
âAlexa, tellâŠturn on the lights at eight forty five p.m.â
âAlexa, tellâŠset dinner scene in one hourâ
âAlexa, tellâŠstart color loop on the bedside lightâ
âAlexa, tellâŠstop color loop on the bedside lightâ
âAlexa, tellâŠstart long alert on the kitchen lights in forty five secondsâ
Preprogrammed colors include pink, orange, green, red, turqoise, blue, purple, and violet. All these colors accept the modifiers âdarkâ and âlightâ (e.g., âdark blueâ, âlight pink.â). You can also specify the following mired colors: candle, relax, reading, neutral, concentrate, and energize.
Groups and Scenes
Alexa Hue gets information about groups and scenes from your Hue Bridge. You can get information about what groups, scenes, and lights you have on the bridge just by asking. The relevant information will be sent to a card in your Alexa app:
âAlexa, askâŠ.what groups do I have?â
âAlexa, askâŠ.what lights do I have?â
âAlexa, launchâŠ.what are my scenes?â
There are a few things to keep in mind. First, the Alexa app stores groups locally, in the app, not on the bridge. So any scenes you created in the Alexa app will have to be recreated on the bridge. Second, youâll only be able to recall groups and scenes that are stored on the bridge with pronounceable names. Even when an application stores the scenes on the bridge, it may append alphanumeric strings to your scene and groups names â âliving roomâ becomes âliving room on 45hdjsldfk4â, for example â so you wouldnât be able to recall that just by asking.
There are two solutions.
The first is to find an app that a) stores the scene on the bridge and b) doesnât mess with the name. I recommend âAll 4 Hueâ available for Android., but I assume many others will work as well. (Note: the official hue app is not one of the them.)
Create a scene in an app that meets requirements a) and b) and then add the scene name as a value in the SCENES custom slot. (You can tell if the application stored the scene correctly on the bridge by asking the skill for your scenes, and making sure that the scene shows up with the name you expect.)
The second solution is to save scenes from within the skill. Just set up the lights the way youâd like. Then you can say, for example:
âAlexa, tellâŠ.to save scene as dinnerâ
Or, to save the scene for just a group:
âAlexa, tellâŠ.to save scene as romantic on the kitchen lights.â
This method is probably not as reliable as the first, but it works. It will work a lot better if you add the name of the scene you are creating to the SCENES custom slot values before you save the scene.
Why do I have to keep adding the names of the scenes/groups in the developerâs portal? I have not included lots and lots of sample utterances or custom slot values. Because of this, the voice recognition for arbitrary words will not be very good. However, the recognition for the supplied values will be very, very good. (Itâs a trade off.) Since you you using this to control just your lights, thereâs no need for the program to recognize just anything you say. Remember, even if you add scenes with an app, recognition will be much better if you add the scene (and group, and light) names as values in the relevant custom slot.
Alexa keeps saying she canât find a group (light, or scene) named âMarks Roomâ even though I know there it exists?This is likely a voice recognitions problem. Look in the settings tab of the Alexa app, under history. There you can see exactly what Alexa heard for everthing you say. Perhaps she heard âMarcs roomâ? This shouldnât happen if youâve added the name of the light/group/scene as a value in the relevant custom slot, but who knows? Alexa is not constrained to recognize only those values
Alexa keeps asking me to specify a light or lights, but I did. Again, this is likely a recognition problem. Check that she heard what you correctly. For example, she might be hearing ârecipe likeâ instead of ârecipe light.â Iâve taken care of a couple common mistakes in the app (you can say âturn on the bedroom likeâ and it will still work), but there might be others. In the history section of the app you can give feedback and tell Alexa that she misheard. If you do this a few times, she usually corrects the error.
Some Common TZ Codes
For the Docker installation, you need to replace the value of the âTZ=â parameter with the time zone name that matches your location. For example TZ=America/Los_Angeles
More complete information here
America/New_York
America/Chicago
America/Denver
America/Los_Angeles
America/Phoenix
America/Indiana/Indianapolis
America/Indiana/Tell_City
America/Indiana/Petersburg
America/Indiana/Knox
America/Indiana/Winamac
America/Indiana/Vevay
America/Kentucky/Louisville
America/Kentucky/Monticello
America/Detroit
America/Menominee
America/Anchorage
Pacific/Honolulu
Source more detail:Â Alexa Hue