This is part 2 of our last article about solving real life problems using artificial intelligence.
SOMETHING IS MISSING…
It works. It is easy. It is usefull. It even solves the initial problem. But something is missing. How do I know that the heating started? What is the temperature in this room? I can control the house but I still don’t have the response from it.
ALEXA, CAN YOU HELP?
Since there is already Alexa involved, maybe she (hmmm… can we really say “she”?) can do it? When she can start some process, maybe she can also react and inform me about what happened? Let’s learn something new!
LET’S MAKE ALEXA SKILL!
If we want Alexa to do something, we need a Skill – something that will be understood, interpreted and will trigger some action.
TOOLBOX
Before developing your first skill, you should start with the Alexa for Developers course from Amazon. It will introduce you to all the needed basics.
Alexa skill is a simple lambda function that is called depending on some special keywords that it receives. They are called Utterances.

If you ask Alexa about something – that is an utterance. Utterances trigger Intents. An Intent is an action that is invoked and it calls an associated lambda function. Intents can be triggered by many different utterances so the developer needs to cover all possible questions or sentences that user may use. When defined improperly, it can trigger a wrong skill, wrong intent or be not understood at all. This is probably the most important part of the development and this will be the user interface of your skill. These simple utterances can contain Slots. A Slot is something you can predefine and use to call different actions in invoked lambda function. In my case such slot could be the name of the room. So if I ask Alexa about the living room it will recognize the slot (living room) and get proper data for this particular room and not any other one. All the intents and utterances create a model. This model will be “the brain” of the skill, deciding what should be done when Alexa receives some input. After the model is properly built, you can test it asking something and checking if a proper intent was called and the slot was correctly recognized. It only recognizes an intent but the lambda is not called yet so you don’t need any code at this moment.

When you create a skill, you need to choose a language – currently supported are Node.js and Python. The Amazon’s course uses Node.js but I will use Python. Why Python? More on that later. The lambda code will look very similar – the main libraries and functions are named almost the same so it is only up to the developer which one to choose. For the development you can use the Alexa Skill Kit (ASK) online environment which is very usefull and has an integrated Alexa simulator.

You can of course also use some external tools (Visual Studio Code for example) but… there are some problems you will encounter.
The development IDE has also a simple icon builder which can be used later on once the skill can be prepared for certification and the skill icon will be required. It is also all prepared to bring you as fast as possible to building your own skill.

PROBLEMS
If you are a developer outside the US – you have problem. US developers can debug Alexa skills locally and use real device to connect and debug their lambda functions. Each device connects to the nearest Amazon server that serves Alexa skills. There are only few of them and only the US server supports local debugging. There is however a workaround described in the Alexa documentation: Setting Up Local Debugging in Other Regions. I didn’t use this solution because I figured out a different one. So I can’t say if it really works and how helpfull it is.
When the lambda function breaks in the skill’s environment, you don’t have any information about what happened. Only the enigmatic “There was a problem with the requested skill’s response” message. The code editor event doesn’t show the obvious errors. So if your lambda is something more than a simple function, it would be good to have the debug. It is not impossible but difficult without it. When you decide using a local environment for development, you can install all the libraries and Alexa ASK CLI on your machine. But, according to the documentation, the lambdas will work but will not say anything. For this you will need to call the original lambda. So one point for simulator. You need of course to prepare the local environment and this takes time – another point for online tools that come preconfigured. Then, if you decided to code locally you need to copy all the changes back to the skill manually. When you decide for Python however, you can use some online preconfigured Jupyter Notebook provided by cloud providers. For example Google Colaboratory feature from Google Drive (I don’t know such environment for Node.js that willl be also compatible with Alexa’s Node.js. It has almost the same configuration like Alexa skill and you can run the code with only minor changes. Yes, you still can not debug but you can run the code line by line, print variable values and do everything needed. When you copy the code back to the skill’s lambda function, there is a bigger chance that it will work properly. And no need to install and configure anything locally. This is why I have chosen Python. And this is why I didn’t want to configure an US account for local debugging. Why should I waste my time when I could use online preconfigured tools. Local environment knocked out!
If you want to use the real Alexa device and not the simulator (which is pretty good in my opinion) there is also a workaround. The skill needs to be certified before it can be available in the skill shop. And the device will not use the skill before it can install it (here this is called enabling skill). But if you fill the certification form, prepare required informations, icons and comply with other guidelines, you can enable the Beta Test for your skill. And guess, who can be your beta tester? Then just enable the skill for your device and it works like a charm! Even for any Region outside the US. The only drawback is that all the lambda errors are displayed on the main page of Alexa app. But, hey, who uses it? You! Does it really matter?
THE ULTIMATE SKILL THAT RULES THE WORLD
When you already thought through the whole Voice UI (VUI) of your skill, you should have all the possible utterances and the interaction paths with slots that can be used ready. Then you can code the intents yourself or use some predefined from Amazon. For example all the starting and closing intents are already there. When you start a new skill project, you need to choose which template you will use. This prepares the skill that comes with example intents and the code for lambda functions in place. Just delete the unneeded code (yes, this can be annoying), add or modify what is essential for your skill and you’re good to go. This is Amazon’s directive: Why reinvent the wheel? Building all of your skill from scratch is difficult and time-consuming, so let Amazon do it and use your development time to build your digital product. You can use Natural Language Understanding (NLU) or Automatic Speech Recognition (ASR) and focus on the actions.
And remember that the interactions are most important here. User will not have any other interface – only his voice. My skill looked good during the development. It was even working perfectly on the Alexa simulator. But when it came to real device (the beta version release 1) it broke. Without the code infornt of my eyes, not remembering proper room names (if it was the kid’s room or children’s room… or maybe kid room?) Alexa just couldn’t answer my questions. It has to be more intuitive and produce no errors. Everything has to be fool proof. So let’s try beta version release 2…

Hey, this is not my skill, wrong skill started. Alexa, try again. Let’s ask with full sentence…Why is she asking me this? Next release… And another one…
Finally it works! It talks and asks and even helps when I speak too slowly or use wrong utterances. What was looking good in the first release was not good enough to just operate voice only. A lesson for the future.

I finally solved my initial problem. So… Alexa, what is the temperature in the living room?
AMB’S TECH INSIGHTS – AN ARTICLE BY IREK
Ireneusz (Irek) started his carrier as a Software Developer mainly programming in Java.
Since 2014 Irek developed his skills in Quality Assurance (QA) of frontend and backend software using automated tools wherever it was possible also for DevOps challenges. Jenkins and Selenium are his mother tongues.
Irek has a „never settle“ attitude, which led him to get into new technologies and making his Microsoft Azure Cloud Certificate this year, where he will continue his hands on experience also in the AI fields.