Making Amazon Echo Alexa Sing to openHAB2

Update

Preface

The documentation on openHAB2 is somewhat lacking and scattered. But I was able to complete my journey so I thought I’d add another article to the noise.

There are a number of approaches to integrating the Echo with openHAB. I have tried some of them successfully and others less so. This tutorial focuses on what appears to be the official approach at the time of writing.

For those of you who like a road map, we will be building a custom Alexa Skill. When triggered, the skill will execute an AWS Lambda function that we will be creating. The Lambda function will call out to the myopenhab.org cloud service which will pass the appropriate action to your personal openHAB server. If any of that went over your head, you’re in the right place. Let’s do this.

Sidenote to the tin foil hats: yes, you can bypass the myopenhab.org piece and have the lambda function call your openHAB server directly, however, there is a significant amount of extra work to make that happen and I’d recommend getting comfortable with the easy route before jumping into that.

Tag Your Items

To expose items to Alexa, you need to tag them with Lighting, Switchable, CurrentTemperature, or TargetTemperature. The readme is a good reference.

In your browser, navigate to https://myopenhab.org. Sign up for an account. You’ll need to know your uuid and secret. These values can be found in files that live in your userdata folder. I’m using docker so that is located at /openhab/userdata/, but on other platforms you’ll likely find it at /usr/share/openhab/userdata. Inside this folder, you should find a file named uuid. Additionally, you’ll find a folder named openhabcloud with a file inside named secret. These two files contain the values you’ll need to register at myopenhab.org

Fill in the application ID from earlier. It’s the one that looks like amzn1.ask.skill.xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and click Submit

Save the ARN from the top right corner. Note that this is different than the Role ARN we used earlier.

The security conscious will want to return to the AWS Security Console and either disable or delete the access key. This key was only needed by the setup script and can safely be revoked.

Alexa Skill (Part 2)

With our dependencies met, we can now finish the skill. Open the skill list and click the edit link next to the Alexa Skill we started earlier.

Click on the Configuration section.

Check the appropriate box for either North America or Europe

In the white box that appears, paste the ARN we copied from the Lambda page

This is a great resource for the next section, but not required reading

In the account linking section, enter https://www.amazon.com/ap/oa?redirect_uri=https://pitangui.amazon.com/api/skill/link/XXXXXXXXXXXXXX for the authorization url. Change the X’s to your redirect URI found later in the Account Linking section

Enter the Client ID from the security profile we created earlier

Add a scope named profile

Set Authorization Grant Type to Auth Code Grant

Set Access Token URI to https://api.amazon.com/auth/o2/token

Specify the Client Secret from the security profile we created earlier

Finally, save the redirect URL for later

Click Next

On the Test page, make sure the toggle is selected to show the skill in the Alexa app and click Next

There are a couple more sections that are not required to be completed since we will not be publishing the skill

first of all, thx for the detailled description – I am curious where it will lead me to 🙂

But I have a question about these bulletpoints:
-Login to the Amazon Lambda Console and select the newly created function
-Under the Triggers tab, select Add Trigger
-…

When I (re)login to Lambda, I can’t find that Triggers tab… I am always redirected to some kind of “AWS Lambda Overview Page” and also don’t find anything within the ARN role… can you please give me a hint?

This is a really great tutorial. You might mention that this is obsolete now that the skill is officially available. I went through all these steps and it didn’t work, only to realize that I could simply enable the skill in the skill store.