Custom Alexa Skills & Launch Requests In Home Assistant

The information in this post is outdated. The Alexa skill editor shown here, is no longer used.

Using Alexa to control my stuff is probably the closest thing to using magic as I’ll ever get. You’ve got to get the “incantation” right or it won’t work. Luckily, we can write our own by creating our own Alexa Skills. You’ll learn how to make skills that work 2 different ways.

  • The first is a custom skill to interact with your Home Assistant set up.
    • “Alexa, ask Home Assistant (or whatever you want to name yours) how warm it is in here.”
    • “Alexa, tell Home Assistant to run bedtime.”
  • The second will be a Launch Request. This skill skips the need to call Home Assistant, but can only have one function.
    • “Alexa, go to bed.”
  • Afterwards, you’ll learn to add an icon to your skill.

These skills will work with any Alexa device. With the new devices just announced there are a lot more devices available for accessing Alexa.

The Prep

*Alexa skills will only work with your system if you are using an encrypted system. You’ll need to set that up first before continuing.*

*Scripts and automations created using the Editors, will not be reachable by your Custom Alexa Skills. You’ll need to build them in the YAML file due to naming issues from the editors*

  • The first step you’ll need to take is to go to Amazon Developer Services and create an account.
  • Go to the Alexa section located in the menu bar up top.

Screen Shot 2017-09-27 at 5.08.59 PM

  • Click “Add A New Skill” in the top-right corner of the screen. Here you will name your skill and define your invocation.
  • The name of the skill is unimportant as long as you know what it is.
  • You will use the skill like this:
    • “Alexa, tell Home Assistant to run bedtime.” or
    • “Alexa, ask Home Assistant how warm is it in here?”
  • Replace “Home Assistant” with whatever you want.
  • Scroll down and save. No need to change any of the other settings here.

Screen Shot 2017-09-27 at 5.11.28 PM

  • Alexa skills are based on intents and will start like this.

Screen Shot 2017-09-27 at 5.24.16 PM

{
 "intents": [
 ]
}

From here, you can add in your intents. You can interact with Home Assistant in a couple of ways.

  • First, you’ll learn how to use a template so you can interact with all of your scripts inside Home Assistant.
  • Then, you’ll learn how to make Alexa retrieve information from your set up.

Interact With Your Scripts

  • This first intent will switch theCustom Slot Type “scripts” for the value you define in the next step.
  • Slip this configuration into “intents”: [].
{
  "intent": "RunScriptIntent",
  "slots":
  [
    {
      "name" : "Script",
      "type" : "Scripts"
    }
  ]
}
  • All together, it looks like this.
{
"intents": [
{
  "intent": "RunScriptIntent",
  "slots":
  [
    {
      "name" : "Script",
      "type" : "Scripts"
    }
  ]
}
] }
  • Now you’ll make a Custom Slot Type called “Scripts” to match your intent from above.
  • Add in any of the scripts you want to be able to access this way.
    • Put each script on its own line.
    • If your script has an underscore “_” in it, use a space here. This will be switched out for an underscore inside the Home Assistant configuration.

Screen Shot 2017-09-30 at 12.39.18 PM

  • The last part of the Interaction Model are the Sample Utterances. This is what you say to connect to the intent. Your magic words.
  • This skill will be activated by saying “Alexa, tell Home Assistant to run bedtime.”

Screen Shot 2017-09-30 at 10.58.47 AM

  • Now, you need to define the intent inside Home Assistant.
  • First, you will need to add the alexa: component to your configuration.yaml file
    • This let’s home assistant know Alexa will be communicating with it.
  • Since there are multiple voice assistants that can communicate with Home Assistant, Home Assistant uses a general intent_script: component in the configuration file for the actual scripting.

Screen Shot 2017-09-30 at 10.41.00 AM

  • Intent Scripts can make the system respond however you’d like. You can also make Alexa respond however you’d like.
  • This specific script was made to correspond with the intent you built into your skill.
    • First, it takes the name of your Custom Slot Type value and makes it the correct format to match the script inside Home Assistant.
    • Then, it will run that script.
    • Last, Alexa will respond with whatever you put in “text”.

Screen Shot 2017-09-30 at 12.44.25 PM

  • Remember to save and check your configuration. Then restart Home Assistant.
  • Let’s finish this skill so you can try it. We’ll come back later to add the second intent.
  • Go to the Configuration page for your skill. Here, you’ll connect it to your server.
  • Select HTTPS
  • If you’ve been following along with the rest of my guides, your default will be https://YOURDOMAIN.duckdns.org/api/alexa?api_password=YOURPASSWORD

Screen Shot 2017-09-27 at 5.46.57 PM

  • This next page will ask about your SSL Certificate.
  • Select “My development endpoint has a certificate from a trusted certificate authority.”

Screen Shot 2017-09-27 at 5.47.40 PM

  • After that is all set up, the skill should be enabled for testing.

Screen Shot 2017-09-27 at 5.47.54 PM

  • Give it a spin! Remember to use your invocation after calling Alexa.
    • “Alexa, tell Home Assistant to run bedtime.”

Tell Alexa To Retrieve Information From Your Set Up

  • Now that it’s all up and running, let’s make Alexa a little smarter. Go back to the Interaction Model tab for your Skill.
  • You can add another intent to your current Intent Schema by using a comma between the squiggly brackets.
  • The next intent will have Alexa respond with the temperature inside when you ask her, by accessing the temperature sensor in your BroadLink.
  • Add this to your Intent Schema
, 
{
 "intent": "IndoorIntent"
 }
  • You won’t be using the Custom Slot Types for one, move on to Sample Utterances.
  • How do you want to interact with Alexa to get the temperature. I started with “what is the temperature inside.”

Screen Shot 2017-09-30 at 11.04.59 AM

  • After a few days, I came up with some other options that I want to be able to use. As long as it is connected to the correct intent.
  • You can make as many utterances as you want.

Screen Shot 2017-09-30 at 11.05.30 AM

  • Now I can ask Alexa the same question in a whole bunch of different ways, whichever feels most natural at the time.
  • Head back to your alexaconfig.yaml and add your IndoorIntent.
{{states('sensor.broadlink_sensor_temperature')}}
  • This is JSON format telling Home Assistant to return the temperature from the broadlink sensor.

Screen Shot 2017-09-30 at 1.33.53 PM

  • Now give it a try! “Alexa, ask Home Assistant, what is the temperature inside?”
  • The same template can be used with weather components if you want to be able to ask about the outside temperature as well.

Launch Requests

  • Launch requests work as a shorter invocation, but must be built as its own skill.

Example: “Alexa, go to bed.”

  • I set this up as a more efficient way to call my bedtime script.
  • To build a Launch Request, add a new skill.
  • Pick your invocation.

Screen Shot 2017-09-27 at 9.23.49 PM

  • The Interaction Model is mostly just filler. The actual work will take place in Home Assistant.
  • Leave the Custom Slot Types blank.

Screen Shot 2017-09-27 at 9.20.29 PM

  • Add in an intent, this is also filler.

Screen Shot 2017-09-27 at 9.20.32 PM

  • At the top of the page, you can find your skill ID under the Name.
  • Copy your skill ID

skill ID

  • Open your alexa_intents.yaml file.
  • You’ll configure this intent the same way, except the name will be your skill ID.

Screen Shot 2017-09-30 at 2.05.24 PM

  • Remember to save and check your configuration before restarting Home Assistant.
  • You can finish this skill the same way as the other one
  • Go back to your Alexa skill.
  • Under Configuration, select HTTPS
  • If you’ve been following along with the rest of my guides, your default will be https://YOURDOMAIN.duckdns.org/api/alexa?api_password=YOURPASSWORD

Screen Shot 2017-09-27 at 5.46.57 PM

  • This next page will ask about your SSL Certificate.
  • Select “My development endpoint has a certificate from a trusted certificate authority.”

Screen Shot 2017-09-27 at 5.47.40 PM

  • After that is all set up, the skill should be enabled for testing.

Screen Shot 2017-09-27 at 5.47.54 PM

  • Now it should work! “Alexa, go to bed!”

Add A Logo

  • If you want to add an image to your skill, you can do that on the Publishing Information page

Screen Shot 2017-09-30 at 2.14.30 PM

  • There are two sizes you can upload. 108×108 and 512×512 PNG or JPG files
  • If you have an image you would like to use, you can use a site like this to convert the size of your image properly.
  • If you don’t have an image you’d like to use, you can use the Home Assistant logos from the documentation.

Screen Shot 2017-09-30 at 2.41.21 PM

Tips

  • Keep your invocations simple. That will help with some unnecessary errors.
  • When creating a Launch Request, choose something that Alexa does not respond to already.
  • You can set up a script to access your Scenes the same way that you set up your Scripts intents.

There you have it! These skills really up the helpfulness of having an Alexa device in the house. After you’ve gone through this guide and have a better understating of how it all works, I recommend taking a look at the documentation. There are some more things you can do with Alexa that I didn’t go over here. You can make custom Flash Briefing Skills and give Alexa a little more personality when interacting with skills by using custom confirmations.

What Launch Requests did you create? I’m curious which phrases did and didn’t work while you were testing things out. Let me know in the comments. If these guides have been helpful to you , please share them! If you have any questions, please reach out to me in the comments. Thanks for visiting!

 

One thought on “Custom Alexa Skills & Launch Requests In Home Assistant

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s