If you have any smart IoT devices in your home or office and tried controlling them with Alexa, you might wonder how it actually works. In this guide, you will learn about building a custom Alexa skill that will let you control a wi-fi enabled light bulb with Alexa. You will be able to turn the light on/off and change the light colors. You can see a demo of the completed project as well as an overview of its components in the video below:
The solution consists of the following components:
The diagram below illustrates all the components and how they relate to one another:
It is important to note that this solution does not require you to use AWS Lambda; it can be implemented entirely in Backendless. Even with the the free plan in Backendless, you can build and run a custom Alexa skill.
The process of developing this solution makes more sense to do in the reverse order, that is:
The reason for that order is the plain inter-component dependency.
This is the code containing the logic for communicating with the light bulb. The code is published into Backendless, which automatically turns it into an API service. The service APIs provide the functionality for controlling the light bulb, such as turning it on or off and changing the light color. For detailed instructions on how to develop, test and deploy the service, see the following blog post:
Developing and API Service with JavaScript and additional NPM modules.
A custom skill consists of two parts: the code that handles requests sent by Alexa and the skill registration with Amazon. In this step, you will focus on the implementation of the skill. A skill implementation in Backendless must be an API service. It can be done with any server-side language supported by our platform, which includes JavaScript, Java or Codeless. In this guide, we will use Codeless and we plan to update it with code listing for Java/JavaScript.
{ "session": { "new": true, "sessionId": "SessionId.0bfc18c3-d11c-4cb5-beea-cd03a5cdea52", "application": { "applicationId": "amzn1.ask.skill.YOUR-SKILL-ID-HERE" }, "attributes": { }, "user": { "userId": "amzn1.ask.account.SOMEID" } }, "request": { "type": "IntentRequest", "requestId": "EdwRequestId.a3f8c85b-f8cf-472d-af68-013fd934b438", "intent": { "name": "LightControl", "slots": { "state": { "name": "state", "value": "on" } } }, "locale": "en-US", "timestamp": "2018-01-02T23:47:27Z" }, "context": { "AudioPlayer": { "playerActivity": "IDLE" }, "System": { "application": { "applicationId": "amzn1.ask.skill.YOUR-SKILL-ID-HERE" }, "user": { "userId": "amzn1.ask.account.SOMEID" }, "device": { "supportedInterfaces": { } } } }, "version": "1.0" }
If the invocation is successful, you should see the following:
The final part in creating this solution is registering the skill you “coded” in the previous section with Amazon. This will make the skill available on your Alexa-enabled devices.
{ "interactionModel": { "languageModel": { "invocationName": "magic light", "intents": [ { "name": "AMAZON.CancelIntent", "samples": [ ] }, { "name": "AMAZON.HelpIntent", "samples": [ ] }, { "name": "AMAZON.StopIntent", "samples": [ ] }, { "name": "LightControl", "slots": [ { "name": "state", "type": "states" } ], "samples": [ "turn the light {state}", "turn it {state}", "turn {state} the light", "lights {state}" ] }, { "name": "ColorControl", "slots": [ { "name": "color", "type": "colors" } ], "samples": [ "set the color of the light to {color}", "set the color to {color}", "change the color to {color}", "make it {color}", "change light to {color}", "to turn {color}" ] } ], "types": [ { "name": "colors", "values": [ { "name": { "value": "red" } }, { "name": { "value": "blue" } }, { "name": { "value": "green" } }, { "name": { "value": "purple" } }, { "name": { "value": "yellow" } }, { "name": { "value": "orange" } } ] }, { "name": "states", "values": [ { "name": { "value": "on" } }, { "name": { "value": "off" } } ] } ] } } }
Enjoy!