This project provides a step-by-step walkthrough to help you build a hands-free Alexa Voice Service (AVS) skill to connect to your [Neurio] (https://www.neur.io) power device.
A simple AWS Lambda function that demonstrates how to write a skill for the Amazon Echo using the Alexa SDK and Neur.io API with Oauth 2 authentication.
This application uses OAuth2 to connect and authentication with external hosted API by Neurio. This API is then used to query some simple information about your home energy usage.
To run this example skill you need to do two things. The first is to deploy the example code in lambda, and the second is to configure the Alexa skill to use Lambda.
- Login to My Neurio
- Go to Settings>Apps
- Click Register New App
- Enter in "Alexa Neurio" or similar for App Name.
- Enter in Homepage url and fake callback url (will be updated later)
- Click Register new app.
- Copy down Client ID and Client Secret (to be used in Alexa Skill Setup)
- Enter in Callback URL after step 10 of Alexa Skill Setup
- Click update app.
- Go to the AWS Console and click on the Lambda link. Note: ensure you are in us-east or you won't be able to use Alexa with Lambda.
- Click on the Create a Lambda Function or Get Started Now button.
- Skip the blueprint
- Name the Lambda Function "Alexa-Neurio-Skill".
- Select the runtime as Node.js
- Go to the the src directory, select all files and then create a zip file, make sure the zip file does not contain the src directory itself, otherwise Lambda function will not work.
- Select Code entry type as "Upload a .ZIP file" and then upload the .zip file to the Lambda
- Keep the Handler as index.handler (this refers to the main js file in the zip).
- Create a basic execution role and click create.
- Leave the Advanced settings as the defaults.
- Click "Next" and review the settings then click "Create Function"
- Click the "Triggers" tab and click on "Add Trigger"
- Select Alexa Skills kit and Enable it now. Click Submit.
- Copy the ARN from the top right to be used later in the Alexa Skill Setup
- Go to the Alexa Console and click Add a New Skill.
- Set skill type to "Custom Interaction Model"
- Set "Neurio Energy Monitor" as the skill name and "neurio" as the invocation name, this is what is used to activate your skill. For example you would say: "Alexa, ask Neurio to ..."
- Copy the Intent Schema from the included IntentSchema.json.
- Copy the Sample Utterances from the included SampleUtterances.txt. Click Next.
- [optional] go back to the skill Information tab and copy the appId. Paste the appId into the index.js file for the variable APP_ID, then update the lambda source zip file with this change and upload to lambda again, this step makes sure the lambda function only serves request from authorized source.
- Select the Lambda ARN for the skill Endpoint and paste the ARN copied from above.
- Select Account Linking "Yes"
- Enter "Authorization URL" https://api.neur.io/v1/oauth2/authorize?response_type=code&state=alexa&redirect_uri=[url from Redirect on this page].
- Authorization Grant Type should be set to "Auth Code Grant"
- Access Token URI should be set to https://api.neur.io/v1/oauth2/token
- Enter in your Client Id obtained from Neurio Setup.
- Enter your Client Secret from Neurio setup.
- You are now able to start testing your sample skill! You should be able to go to the Echo webpage and see your skill enabled.
- In order to test it, try to say some of the Sample Utterances.
User: "Alexa, ask neurio what the current power usage is"
Alexa: "You're current power consumption is 1000 watts."