Combine your two favorite gadgets!
We’re keeping on playing with Alexa. This time I want to create one skill that uses a compatible device (for example one Raspberry Pi 3). Here you can see the documentation and examples that the people of Alexa provides us. Basically we need to create a new Product/Alexa gadget in the console. It gives us one amazonId and alexaGadgetSecret.
You may also like: Smart Home Tutorial: ESP8266, Alexa, and Amazon Echo
Then we need to install the SDK in our Raspberry Pi (it install several python libraries). Then we can create our gadget script running on our Raspberry Pi, using the AmazonId and alexaGadgetSecret. We can listen to several Alexa events. For example: When we say the wakeword, with a timer, an alarm and also we can create our custom events.
I’m going to create one skill that allows me to say something like: “Alexa, use device demo and set color to green” or “Alexa, use device demo and set color to red” and I’ll put this color in the led matrix that I’ve got (one Raspberry Pi Sense Hat)
This is the python script:
Here the ini file of our gadget:
Whit this ini file I’m saying that my gadget will trigger a function when wakeword has been said and with my custom event “Custom.gonzalo123”.
That’s the skill:
One important thing here is the GadgetInterceptor. This interceptor finds the endpointId from the request and appends it to the session. This endpoint exists because we’ve created our Product/Alexa gadget and also the python script is running on the device. If the endpoint isn’t present maybe our skill must say to the user something like “No gadgets found. Please try again after connecting your gadget.”.
Finally, the handlers to trigger the custom event:
Here one video with the working example:
Source code in my GitHub.