Teaching Alexa how to turn my light on (Building the simplest Alexa skill)
A few days back I was tackling the task of developing a custom skill for Amazon’s voice assistant, a.k.a. ‘Alexa’. I thought of a very…

A few days back I was tackling the task of developing a custom skill for Amazon’s voice assistant, a.k.a. ‘Alexa’. I thought of a very basic execution to learn from, which was to build a setup to output an on/off signal to a device using voice commands. Sounded simple enough for the first step.
Background check: I had my hardware device already integrated with AWS IoT MQTT broker, subscribed to a topic and ready to accept messages. You can do this easily following Amazon’s developer guide. Having this, the straight-forward method to achieve my objective was to make Alexa publish a message to the same MQTT topic so that the device receives the message.
Although I could find many resources on Amazon’s documentation and other forums on building Lambda functions with Alexa, I couldn’t find a direct implementation guide for my objective. Hence here it is.
Note: I’m not going to make this a step-by-step guide for setting up an Alexa skill and an AWS Lambda function. Amazon resources like this does a better job at it. Also you can search for other forums that explains the entire process. I’m just going to share the two major codes that you’ll need in the process, which are the Alexa skill interaction model settings and the Lambda function index.js code.
Interaction model of the Alexa Skill
I wrote a simple intent schema as below. I didn’t go into slots in order to keep complications out. Here the two intents — SwitchOnIntent and SwitchOffIntent defines the two voice commands expected from the user.
A simple set of sample utterances were defined as below.
Lambda Function
The lambda function facilitates communication between the Alexa skill and AWS IoT broker. The Zip file that includes the code plus all dependencies needed for the function can be found in my github repository below. The main code resides in the index.js javascript file.
miranthajayatilake/AWS_LAMBDA_LIGHTCONTROL
AWS_LAMBDA_LIGHTCONTROL - Projects with AWS servicesgithub.com
Upload the Zip file to the lambda function. For the execution role setting I used a custom role with the policy AWSIoTFullAccess for now.
You have to fill in the Alexa skill ID, the thing endpoint and the topic you want Alexa to publish to in the index.js file.
The two main handlers are as below. For instance if the SwitchOnIntent is triggered, the message ‘on’ is published to the given endpoint topic, and if the publishing is successful, Alexa provides the voice feedback saying ‘Switched on’.
Everything done right your device will receive the message from the topic and with a simple logic statement you can make the device control anything using a digital output.
That’s pretty much it. With all other configurations in place now you can test the service. I used the test option in the Alexa skill terminal first and then since I don’t have an Echo myself, used the web simulator at Echosim. It was quite cool to see the result.
Remarks:
This shows a very basic execution of Amazon’s voice assistant to perform a simple task to be used as an initial step to learn VUI. Of course there is so much more you can build on top of this, combining many features and services.
It is surely fascinating to see the way platforms like Amazon services have come to make it really easy for developers to develop sophisticated applications on a high level.
The great potential of VUI applications is pretty evident and it is surely on track to become the most used man-machine interface in the near future.