Yes, how you name your Philips Hue lights is highly important when you are connecting them to a Smart Assistant (with voice commands). Get things wrong and you end up with your Amazon Echo constantly spouting off “I’m sorry the Master Bedroom doesn’t support that.” You could also get plagued with your devices randomly becoming unresponsive with Alexa. Oh fun. Nothing to piss you off more than your lights just not working. I know first world problems right?
If you are just using the Hue app with no voice assistant you can get away with naming them whatever you want because it doesn’t really matter. When the voice commands are added the names of the rooms or groups you have them in as well as the names of the individual lights matter greatly. Not only will your smart assistant constantly just not fucking work with your lights, you may also get tired saying a particular phrase for a light or it may turn out you never actually called that light that name to begin with. Spend some time thinking about light names, seriously.
In my previous home I had a shit ton of Hue lights. When you have that many lights they end up becoming numbered. “Master Bedroom One,” “Living Room 3,” etc. Then when you have the rooms/groups of “Master Bedroom” or “Office” the lights with numbers in their names wont ever conflict with each other and their groups/rooms. Now that I am solo and in an apartment I only have a small handful of lights so I don’t need to number them anymore. Now I was getting conflicts with my names.
With my most recent struggles I have noticed, and eventually found the cure with the problem and the names I had chosen. I thought I picked them simply and perfectly because I honestly do not have that many lights in my apartment. As is turns out the biggest thing that was causing constant strife with my Echos and lights was the names I had chosen for the Echos themselves, along with the same conflicting name for the rooms they are in. For example, I have an Echo Dot in my master bedroom which I had named simply “Master Bedroom” because I was only thinking of my Echos at the time and not in conjunction with the light names; “Master Bedroom,” “Office,” and “Kitchen.” Well I had also made some rooms with the Hue app with the same names of “Master Bedroom,” “Office” and “Kitchen.” Same names as the Echo names, damn it. The lights worked initially when I set them up but after a few houros or day or so they all stopped and my Alexa started rebelling.
The Simple Fix
So there is a simple fix, which took me hours to figure out in the middle of the night I hate to admit. I ended up renaming the Echos first. “Master Bedroom Echo,” “Office Echo,” and “Kitchen Echo” to separate them from the name of the groups/rooms for the lights. I also figured out that I was getting multiple devices with the same names in my Alexa app because of the scheme I had originally chosen. So I removed all groups and rooms from the Hue app. I don’t use the Hue app much as it is, primarily just the Echos with the lights or Apple Homekit. So my Hue app has just one group now called “All Hue Lights” so they are easy to get to in the Hue app if I ever need to use it. Then in the Amazon Alexa app I did a device discovery and it pulled the one group and all the lights and Echos. Then in the Echo app I created the groups of “Master Bedroom,” “Office” and “Kitchen.” No more conflicts now, the lights all work and no more unresponsive remarks from Alexa or the apps.
Finally! I am surprised it didn’t even take as long as it usually does for me to figure shit out. Took a few weeks. As usual, I did not come up with the solution on my own but found it out on the web and slapped it all together. I wanted a custom Alexa Node-Red skill, to be able to take a command given to Alexa and have it read back data from one of my sensors. Things like temperature sensors, water level, etc. I wanted to be able to ask Alexa what the values are. What I got: exactly what I wanted. It all works. There is two parts to this: the Node-Red flow and the Alexa skill.
First off, to get any of this working you must have your Node-Red server accessible from the outside world. That means port-forwarding, DNS, domains, SSL, all that. It’s fun getting it all working. Not. Just like my previous post, I happened to have it already setup. Once your Node-Red install is available from the web you are good to go. Now you don’t need the entire NR setup opened up either. I just allowed a few NR served pages to be available. Not the entire NR itself.
It starts with a regular HTTP node to a switch node. That switch node splits up Alexa’s requests to NR; LaunchRequest, IntentRequest, SessionEndedRequest. LaunchRequest gets invoked when the skill starts. You could have Alexa say “Hello what do you want?” for example. IntentRequest is the goods. Then theres SessionEndedRequest, I’m assuming this gets called at the end. Haven’t toyed with it. Then you pass those requests off to do other stuff, like the DoCommand where it grabs your intent. Then a function node to extract the commands, which gets passed off to another switch node to split up the possible commands you can give Alexa. Give her as many commands as you want, then there is a “device doesn’t exist” at the bottom. This is used if she didn’t hear you right or the device doesn’t exist. All that data gets passed to a template to format what Alexa will say and sticks the data in JSON. Bam! That wasn’t so hard right?
Here’s the whole flow (all standard nodes used):
1
[{"id":"84f88c01.3a741","type":"http in","z":"74af25a6.5c836c","name":"/alexa","url":"/alexa","method":"post","swaggerDoc":"","x":90,"y":1200,"wires":[["390e7e54.f5d7f2"]]},{"id":"390e7e54.f5d7f2","type":"switch","z":"74af25a6.5c836c","name":"Request Type","property":"payload.request.type","propertyType":"msg","rules":[{"t":"eq","v":"LaunchRequest","vt":"str"},{"t":"eq","v":"IntentRequest","vt":"str"},{"t":"eq","v":"SessionEndedRequest","vt":"str"}],"checkall":"true","outputs":3,"x":260,"y":1200,"wires":[[],["79e0966.d586568"],[]]},{"id":"79e0966.d586568","type":"switch","z":"74af25a6.5c836c","name":"Intents","property":"payload.request.intent.name","propertyType":"msg","rules":[{"t":"eq","v":"DoCommand","vt":"str"}],"checkall":"true","outputs":1,"x":450,"y":1200,"wires":[["6a5f2c6c.2f5fe4"]]},{"id":"6a5f2c6c.2f5fe4","type":"function","z":"74af25a6.5c836c","name":"Extract commands","func":"msg.payload = msg.payload.request.intent.slots.command.value;\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":1200,"wires":[["74def98d.31a598","9265c084.10d21"]]},{"id":"74def98d.31a598","type":"debug","z":"74af25a6.5c836c","name":"spoken text","active":true,"console":"false","complete":"payload","x":670,"y":1240,"wires":[]},{"id":"9265c084.10d21","type":"switch","z":"74af25a6.5c836c","name":"request","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"computer temperature","vt":"str"},{"t":"eq","v":"garage temperature","vt":"str"},{"t":"eq","v":"inside temperature","vt":"str"},{"t":"eq","v":"i outside temperature","vt":"str"},{"t":"nnull"}],"checkall":"true","outputs":5,"x":880,"y":1200,"wires":[["1db561b.015c99e"],["dc21a191.9eeca"],["a3cf81a0.7f198"],["f9b89dbe.3fe29"],["46a05746.410fe8"]]},{"id":"1db561b.015c99e","type":"function","z":"74af25a6.5c836c","name":"Server Temperature","func":"msg.current = {\n server: context.global.servertemperature\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1070,"y":1140,"wires":[["80a3b45b.18ac88"]]},{"id":"dc21a191.9eeca","type":"function","z":"74af25a6.5c836c","name":"Garage Temperature","func":"msg.current = {\n garage: context.global.garagetemperature\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1080,"y":1180,"wires":[["973f5f3f.4274a"]]},{"id":"a3cf81a0.7f198","type":"function","z":"74af25a6.5c836c","name":"Inside Temperature","func":"msg.current = {\n inside: context.global.insidetemperature\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1070,"y":1220,"wires":[["315e3b6.ff8bdc4"]]},{"id":"f9b89dbe.3fe29","type":"function","z":"74af25a6.5c836c","name":"Outside Temperature","func":"msg.current = {\n outside: context.global.outsidetemperature\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":1080,"y":1260,"wires":[["2888b889.6999c8"]]},{"id":"46a05746.410fe8","type":"function","z":"74af25a6.5c836c","name":"Unrecognized","func":"\nreturn msg;","outputs":1,"noerr":0,"x":1060,"y":1300,"wires":[["ade58298.2cf17"]]},{"id":"80a3b45b.18ac88","type":"template","z":"74af25a6.5c836c","name":"Format Alexa's Response","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"version\": \"1.0\",\n \"response\": {\n \"outputSpeech\": {\n \"type\": \"PlainText\",\n \"text\": \"The server closet is currently {{current.server}} degrees\"\n },\n \"shouldEndSession\": true\n }\n}","x":1350,"y":1140,"wires":[["e636973f.8e1428"]]},{"id":"973f5f3f.4274a","type":"template","z":"74af25a6.5c836c","name":"Format Alexa's Response","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"version\": \"1.0\",\n \"response\": {\n \"outputSpeech\": {\n \"type\": \"PlainText\",\n \"text\": \"The garage is currently {{current.garage}} degrees\"\n },\n \"shouldEndSession\": true\n }\n}","x":1350,"y":1180,"wires":[["e636973f.8e1428"]]},{"id":"315e3b6.ff8bdc4","type":"template","z":"74af25a6.5c836c","name":"Format Alexa's Response","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"version\": \"1.0\",\n \"response\": {\n \"outputSpeech\": {\n \"type\": \"PlainText\",\n \"text\": \"The inside of the house is currently {{current.inside}} degrees\"\n },\n \"shouldEndSession\": true\n }\n}","x":1350,"y":1220,"wires":[["e636973f.8e1428"]]},{"id":"2888b889.6999c8","type":"template","z":"74af25a6.5c836c","name":"Format Alexa's Response","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"version\": \"1.0\",\n \"response\": {\n \"outputSpeech\": {\n \"type\": \"PlainText\",\n \"text\": \"It is currently {{current.outside}} degrees outside\"\n },\n \"shouldEndSession\": true\n }\n}","x":1350,"y":1260,"wires":[["e636973f.8e1428"]]},{"id":"ade58298.2cf17","type":"template","z":"74af25a6.5c836c","name":"Format response","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"version\": \"1.0\",\n \"response\": {\n \"outputSpeech\": {\n \"type\": \"PlainText\",\n \"text\": \"I'm sorry, there is no device named {{payload}}\"\n },\n \"shouldEndSession\": true\n }\n}","x":1330,"y":1300,"wires":[["e636973f.8e1428"]]},{"id":"e636973f.8e1428","type":"json","z":"74af25a6.5c836c","name":"","x":1570,"y":1220,"wires":[["348a8cc4.cc99a4"]]},{"id":"348a8cc4.cc99a4","type":"http response","z":"74af25a6.5c836c","name":"","x":1710,"y":1220,"wires":[]}]
That’s the Node-Red half. You are not done yet. On to the Alexa skills half. This part is easy don’t worry. Login to your Amazon Dashboard and click Alexa. Choose “Get Started” with the Alexa Skills Kit, click add a new skill. Under Skill Information give it a name and choose the invocation word, what you will say to Alexa to start your skill. I chose “Node Red”, so I have to say “Alexa, ask Node Red….”. These can be changed at any time it seems. You won’t be publishing this skill, it stays beta for only you to use. For the Global Fields section, no you will not be using an audio player. Well, maybe you will but I didn’t, and it will probably change things for you.
Note about the flow: The NR flow works (for me) just fine however I noticed it throws an error in the debug tab whenever a command is called. If it is an unrecognized command response it doesn’t throw the error though. It complains about headers already being sent. I will update the flow if I find a fix for it.
Interaction Model
Intent Schema
This is the part of the Alexa skill where you tell it what to do. It is pretty straight forward. Just copy this to your “Intent Schema”. There are no custom slot types and no values to enter.
1
2
3
4
5
6
7
8
9
10
11
12
13
{
"intents":[
{
"slots":[
{
"name":"command",
"type":"LITERAL"
}
],
"intent":"DoCommand"
}
]
}
Sample Utterances
This is where you list the invocation phrases that will activate Alexa. Normally (and in other online tutorials for Alexa skills) this is where you add a ton of different phrases. But we are not. Node-Red is going to handle that side for us. This box just gets one line of text.
1
DoCommand{script parameters|command}
Configuration
Global Fields/Endpoint
For a service endpoint you are going to pick “HTTPS”. In a lot of other tutorials you will usually choose AWS Lambda but we are doing all of our own heavy lifting with NR. We don’t need no stinking Lambda. Choose your closest location and enter the URL that your Node-Red is accessible from (via the web remember). Say no to account linking and you can also leave Permissions alone.
SSL Certificate
Certificate for Endpoint
Choose the option that bests describes you. Most likely it will be the first option. For me I am using a subdomain that is already SSL’d with Let’s Encrypt so I choose the second option.
Test
Basically just leave the toggle flipped to enable the skill for you to use. you don’t need to do anything else on this page.
Publishing Information
Nothing to do here, you won’t be publishing this skill. Why? Because it requires too much setup on the users behalf. I don’t think Amazon would approve a half functioning skill that requires advanced user setup to get working. You could always try. Good luck.
Privacy & Compliance
Three no’s and one box to check, I mean as long as it all applies to you right 😉
Done
That should be it. With Node-Red available to the web and the flow implemented the new Alexa skill you just made you should be good to go. I hope you found this useful, I sure wish I had found a blog post like this. Now go test it out with your Amazon Echo/Dot!
At the time of this writing a beta product appeared in the Amazon Dashboard for a the “Skill Builder”, looks to be a new UI for building Alexa skills. If this gets implemented for everyone in the future things may be different than they are described in this blog post.
Revisited
Originally posted April 26, 2017 @ 17:56
I decided to come back to this post. I was adding and modifying some things on my flow and I was using this post as a reference and decided it was not cutting the mustard, it felt unfinished. So here we are.
The above section contains the main flow you will need and it steps you through the Amazon Developer side of things that needs to be setup. Once that is all finished you should have a working flow with Alexa responding accordingly. What I feel I left out was how to configure the flow itself. Many of you may already have figured it out or can see whats going on and thats cool. Heres for the ones that need the help (myself included).
The flow
HTTP node
The first node in the flow is the HTTP request. This is the page you will use to point your reverse proxy to. This is the page that Node-Red will server, that Amazon/Alexa will look for. This page needs to be accessible from outside your network.
Request Type
This contains the types of requests we can send to Alexa. We are only worried about
IntentRequest right now. Play with the other later.
Intents & Extract Commands
There is no need to modify these nodes. They contain the code needed to send requests.
Request
Add your verbal question here. Add it how Alexa hears it. This may take a little trial and error depending on how you talk and how she hears you. Sometimes you can simply put exactly what you are going to say in there, like “garage temperature” works fine for me but if I ask Alexa what the outside temperature is she doesn’t know and I get the unrecognized question response. But this is ok, pay attention to the output of the unrecognized responses. It will spit out what Alexa heard and how she heard it. So when I ask what the outside temperature is she hears “i outside temperature” for some unknown reason. So if I modify my request to be the same, and it works.
Function node
This function is very simple. It just grabs the global variable name you put in it. So when I ask for the “garage temperature” it looks for the global I have specified, in this case
contex.global.garagetemperature. Add whatever global you want. Just make sure it is initialized first (has some data to report).
Formatting Alexas response
This template node contains the information for Alexas verbal reply. Once the basic structure is there all you do is edit the “text” to the response you want to receive, in plain english. She will respond with “exactly” what you type in there.
JSON & HTTP Response
Move along, noting to see here. The data gets formatted as JSON and the HTTP node completes the whole flow.
Done.
There you go. I feel better now. I at least explained WTF is going on here rather than dumping the flow on you and walking away. Sorry about that. Now you can run off and play with Alexa and Node-Red to your hearts content. The only thing I have noticed with the whole flow is that after Alexa responds Node-Red throws an error in the debug log. It all works 100% and works well but it always sends this error, and I haven’t figured it out. But I also haven’t been looking for it. Just a little FYI.
Amazon Polly and Node-Red. This was far easier to get going than any Alexa skill I tried to do. I just came across this the other day on Scargill’s Tech blog.
“Amazon Polly is a service that turns text into lifelike speech. … With Amazon Polly, you only pay for the number of characters you convert to speech, and you can save and replay Amazon Polly’s generated speech.”
Basically you feed Polly SSML text and it returns it in spoken form as an MP3 (or other format). Sweet, I can give my server/Node-Red a voice! Not sure my wife will like this but it will actually server a valid purpose. I was admitted to the hospital (again) for a short three-day stay recently and while I was admitted (and loaded up on drugs) my server closet reached my maximum set temperature… and issued the text alert 187 times. Now I can have the server annunciate that the closet needs to be opened. I could add my wife’s number to the SMS list but that will fail, lol. Simply saving the MP3 on the server and having it be played back works just great.
I am sure you can tap into the API many other ways, and use Polly many other ways, but the simplest way was my path. I just logged into the Amazon Polly Developer console and slapped some text in the input box. It spit out an MP3 and I saved it. The catch here is that the free tier of the Polly program only lasts 12 months, then you get charged. Its super cheap though, $4 per 1 million characters. The free tier is 4 million per month (for 12 months). From what I have read Polly will search the cloud to see if the file already exists. If it does it pulls it down, if it doesn’t it creates it (and counts agains the character limit) and pulls it down. Is this for “the cloud” or your account? Dunno. Still pretty cheap.
I have circumvented the whole thing (for now). I don’t really plan on (or have the need to) generating Polly files on the fly. What works for me is as I said, just slapping a ton of phrases I think I’ll need into Polly and saving the files for later. I’m cool with that.
But, there is a node for NR that will generate Polly files for you on the fly, and/or pull down the ones already generated. I mentioned I found Polly on Scargill’s blog, he also used NR to play with Polly. He had to do it the hard way. Three days ago the node was made. Definitely check out his blog even if you just use the node. Its all good info.
The node looks pretty simply to use (I have not used it). You need to add your Amazon Polly API credentials to the node. The input gets TTS’d and the file saved. If the text has already been converted no Polly call is made and just the file served. So it looks like it stores all the Polly MP3s for you locally. Sweet.
I purchased an Amazon Echo Dot a couple weeks back. In the past I had stated that I would never put one in my house, and generally had a distain for voice activated things. I had done a little bit of reading on the Dot and I have been getting further into home automated things. I finally had a light bulb moment where I now understand all the coding. I am now dangerous. Haha.
Logically the next step was integrating Alexa with my custom build devices. All of my devices work off an ESP or Raspberry Pi (or will). I found Fauxmo Wemo emulation which is fantastic. That covers about 60% of my use, a simple off and on. But for things like my temperature sensors, hyrgrometers and water lever sensors I need to be able to pull data and have Alexa read it back. Like “Alexa, ask server for the temperature.” Or “Alexa, ask the garden for an update.” All of my devices communicate via MQTT. I started with Node-Red without Alexa so this is the direction I went. I still think it was the best route to go. All I need is an Alexa skill to read back different inbound MQTT topics (for different devices). I can’t believe there isn’t a skill already out there to read back MQTT data or homebrew temperature sensors. Or is there and I haven’t found it yet? The majority of the available Alexa skills fucking suck. There are very few actually useful skills to use. The majority of the skills I have seen are garbage. One off skills you would use once or twice then forget about. More Alexa joke skills than there needs to be.
So I started looking into making my own skill. This is what I have found to get started with creating a skill.
You need an Amazon AWS Developer account
You need access Lambda
You must subscribe to basic free tier of service
You must subscribe to Amazon EC2, which is only free for one year.
So is this a catch with using custom skills and Alexa? Will my skills then start costing me money after 12 months. If I cancel after 12 months do I lose all my skills? I’m thinking yes, I will bet you Amazon is planning on cashing in on this later? Or is it already that late in the Echo game that I am just being unfoundedly paranoid?
I have not yet created a skill. Javascript is not my forte and I haven’t sat down to dig in to this yet.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here:
Cookie Policy