Develop Your Own Raspberry Pi Alexa Skill and Control Pi Remotely

Voice control is an increasingly important component in smart homes. For this purpose, Amazon provides skills that run on Amazon Echo Dot, Fire TV sticks, smartphones and other devices. In this way, Raspberry Pi Alexa skills can also be created in a simple manner.

The skills can be published optionally and even money can be made with them. In this tutorial, we will create an Alexa skill which will execute commands on our local Raspberry Pi. We will go through all the points of that process step by step.

Various other providers such as Google (“OK Google”), Apple (Siri) and Microsoft (Cortana) also have language assistants and offer opportunities to write your own skills. If you are interested, we can show those in future tutorials.

This tutorial includes building simple LED controls, but many other scenarios can be built through small adjustments.

Required Hardware Parts

The software runs completely on the Pi. We also need the hardware which will be operated by voice control. For this we will use the following:

An Amazon device with Alexa is also required. These are:


Preparation and Raspberry Pi Programming

Before we create the actual Alexa skill, we have to set up and configure a few things. First of all, we need an Amazon developer account. We first create an account on or log in with the existing Amazon account.

Then we take care of the setup on the Raspberry Pi.

Connecting the Raspberry Pi Hardware and Installing the Software

Before you start the Pi, connect a simple LED with the long end to GPIO 17 and the short end to Ground. Here you can see the pin assignment:

Raspberry Pi GPIO Pin Assignment

Raspberry Pi GPIO Pin Assignment

Ideally, you can also connect a small resistor (220Ω) between Ground and the LED.

Since this example is very simple, I would like to give you some better project ideas:


Now connect e.g. via SSH with the Raspberry Pi. First of all we install the required software. We use the Python packages Flask or Flask-Ask, which make it very easy to write Amazon Alexa skills:

python3 -m pip install Flask-Ask
pip3 install --upgrade setuptools
pip3 install 'cryptography<2.2'

As you can see, we used a version less than 2.2 of the package cryptography. With newer versions. there are often errors in connection with Flask.

Now let’s create the python file that contains our code:

sudo python3

This file has the following content:

Save the file with Ctrl + O and close the editor with Ctrl + X. Then we run the file:


Accessibility Outside of the Local Network

We now have a Raspberry Pi server running, but this can only be accessed via the local network. It must be publicly accessible so that Amazon can call up our Raspberry Pi later.

We could either use a dDNS service and enable the ports in the router, or we could use ngrok. This has the advantage that we can save the configuration.

Open a new terminal (do not close the old one) and enter the following:


Afterwards we can start:

./ngrok http 5000

NgrokWe then need the second URL (https) for Amazon.

Attention: As a non-registered user, the connection will be reset after 8 hours and you will get a new URL. You can change this by registering and providing your token:

./ngrok authtoken <TOKEN>

It is also possible to choose the subdomain yourself. You can find more information about ngrok in the documentation.

./ngrok http -subdomain=myveryownamazonalexaskill 5000


By the way: We can also start both commands (Python script and ngrok) via autostart.


Setting up the Raspberry Pi Alexa Skill in the Amazon Developer Account

We press the “Create Skill” button in the Amazon Developer Console. Here we assign a name (e.g. “Raspberry Pi”), choose the language and the “Custom” model. The hosting method is “Provision your own”.  Then we click on “Create Skill” in the top right corner.

Create Raspberry Pi Alexa Skill - New Skill

Then we press the plus sign next to “Slot Types” (Interaction Models) and create a new type called “STATUS”:

Create Raspberry Pi Alexa Skill - Slot Type

For this we create two “values”. These are given the names “on” and “off” and we also define all possible synonyms (these are the same synonyms that are also specified in the Python script):

Amazon Alexa Skill Slot Values

As the last configuration step, we create an “intent” (click on the plus sign) with the name “LightIntent” (the same name which was also specified in the script):

Create Raspberry Pi Alexa Skill - Add Intent

In the lower part, we first add the “intent slot”. Here we choose the type “STATUS” and also call it “status” (lower case):

Raspberry Pi Alexa Skill Intent Slot

In the upper part, you can now enter all possible voice commands, such as “turn off the light”. By double-clicking on a word, you can replace it with the slot:

Raspberry Pi Alexa Skill Light Intent

Think about different combinations that you want to use later. Usually, the call is e.g. as following:

Alexa, tell Raspberry Pi, [turn on light / turn off light / …]

The second part is therefore important and should be defined in this part. Save the model and press “Build Model”.

Here again the generated JSON file. You can also just paste them in


Last but not least, we have to specify the server URL to which the commands are sent. To do this, click on “Endpoint” on the left, select HTTPs and paste the URL of ngrok into “Default Region”. Also, choose the following option: “My development endpoint is a sub-domain of a domain that has a wildcard certificate from a certificate authority“.

Amazon Alexa Skill Endpoint

Don’t forget to save it.


Test the New Raspberry Pi Alexa Skill – Locally and on Amazon Echo Devices

We now want to test the Raspberry Pi Alexa Skill. There are various options for this, which we will go into. Ideally, both are carried out in succession:

1. Amazon Developer Console – Test

In the Developer Console, there is the possibility to send commands via voice recording or text under the tab “Test”. To do this, you have to allow your browser to use your microphone. You can see that command on the right side.

2. Live Testing on Amazon Echo (Dot), Fire TV Stick, etc.

We want our developed skill to run permanently on Amazon devices. To do this, first, we have to add all devices to our account. How this works is, among other things, described here. You can see all Alexa devices either in the smartphone app (Android, iOS) or in the Amazon dashboard.

You can also easily add new devices in the apps. As soon as the device is linked to the account, the skill can already be used.


What projects do you have in mind? Further ideas and suggestions as comments are welcome.

17 Responses

  1. When I test this the py script just keeps returning “I’m sorry this command is not possible.”
    Checked everything many times.
    What am I missing?

  2. Great tutorial! However, I cannot seem to get it to work. I have followed the entire tutorial and I am using the exact JSON code provided. WHen I try a command such as “ask raspberry pi light on”, “tell raspberry pi light on” or even “open raspberry pi”, I get the response “There was a problem communicating with the requested skill”
    It does not seem to be accessing the ngrok link that I have set up on the pi, since I don’t see any change in the ngrok terminal, or the terminal (which should log something if the link was accessed). What could I be doing wrong?

    • Can you manually try to reach your ngrok server (from inside and outside of your network)? This is where I would begin to search for the issue.

      • Thank you for the reply. Yes, I can manually access the ngrok server by entering in the URL into a browser (both in and out of the local network). The browser in both cases reports “Method Not Allowed” and ngrok prints the two lines:
        GET /favicon.ico 404 NOT FOUND

  3. Hi.. it works like a charm. But how i can turn on off all GPIO just saying a word like turn TV ON or turn IRRIGATION ON?

    Need to change the python of alexa skill or start a lot of skills?

  4. I’m getting this error when running – python3…
    Traceback (most recent call last):
    File “”, line 5, in
    from flask_ask import Ask, request, session, question, statement
    ImportError: No module named ‘flask_ask’
    I installed python3 -m pip install Flask-Ask
    Also tried changing the from flask_ask import Ask, request, session, question, statement to ..
    from flask-ask import Ask, request, session, question, statement

  5. Says I need 3.5 or higher of Python to install anything but I have 3.7. Even running “Python –version” shows I have 3.7 so not sure how to resolve this.

  6. Great tutorial!
    I’m able to test it successfully through the simulator in the console. But failing to do so through a physical echo dot device. I keep getting “Sorry, I’m having trouble accessing your Raspberry Pi skill right now “. Could you please help me out with this?

  7. when i type sudo python3, i get python3: cant open file ‘’: [Errno2] no such file or directory

  8. I Followed this guide but unfortunately i am receiving this error. Just like a lot of people in the comment section it doesn’t work.
    I hope someone can fix it 🙂
    [2021-03-11 11:55:31,215] ERROR in app: Exception on / [POST]
    Traceback (most recent call last):
    File “/home/user/.local/lib/python3.8/site-packages/flask/”, line 2446, in wsgi_app
    response = self.full_dispatch_request()
    File “/home/user/.local/lib/python3.8/site-packages/flask/”, line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
    File “/home/user/.local/lib/python3.8/site-packages/flask/”, line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
    File “/home/user/.local/lib/python3.8/site-packages/flask/”, line 39, in reraise
    raise value
    File “/home/user/.local/lib/python3.8/site-packages/flask/”, line 1949, in full_dispatch_request
    rv = self.dispatch_request()
    File “/home/user/.local/lib/python3.8/site-packages/flask/”, line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
    File “/usr/local/lib/python3.8/dist-packages/flask_ask/”, line 560, in _flask_view_func
    result = self._map_intent_to_view_func(self.request.intent)()
    File “/usr/local/lib/python3.8/dist-packages/flask_ask/”, line 574, in _map_intent_to_view_func
    view_func = self._intent_view_funcs[]
    KeyError: ‘TVSourceIntent’ – – [11/Mar/2021 11:55:31] “POST / HTTP/1.1” 500 –
    “context”: {
    “Extensions”: {
    “available”: {
    “aplext:backstack:10″: {}

  9. Your tutorial is excellent. I was able to learn enough by completing it to write my own Alexa skill with Python. My next step is to do the same thing in C++. Thanks for taking the time and effort to put this together.

  10. Hello , great tutorial thanks for posting.
    A quick question I have is why go for Ngrok rather than the recomended (in alexa developemnt docs) AWS ? Just wondering..


Leave a Comment

Your email address will not be published.