Alexa, Put the Kettle On!




Make a smart kettle for under £60 using Alexa and Arduino.

Alexa, Put the Kettle On!

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
× 1
SparkFun Logic Level Converter - Bi-Directional
SparkFun Logic Level Converter – Bi-Directional
× 1
Tefal Temperature Control Kettle
× 1

Software apps and online services

Arduino IDE
Arduino IDE
Alexa Skills Kit
Amazon Alexa Alexa Skills Kit
AWS Lambda
Amazon Web Services AWS Lambda
Shiftr

Story

Introduction

Why make two trips to the kitchen, or hang around waiting for the kettle to boil when you can just ask Alexa to put the kettle on?

This project uses as few components as possible and is really easy to follow but it does involve tinkering with mains powered devices and water. So be careful and always make sure the kettle is unplugged when working on it! You will need to know how to solder to complete this hack.




Try it for yourself

I’ve published a demo version of the Skill HERE. If you add this to your Alexa account then visit the Shiftr Namespace HERE you will be able to say “Alexa, put the kettle on” and see a blip move around the node map to the device brewTime-TEST. You can also see the state of the request in the top left corner. The device brewTime-01 is the kettle in my house, you can’t control this but you can see it’s state.

Prerequisites

  • An Amazon developer account, create one here if needed
  • An Alexa-enabled device associated with the above account
  • An AWS account, create one here if needed

How the services communicate

The software

Let’s get your MKR1000 talking to Alexa before we start hacking the kettle. This involves creating an Alexa Smarthome Skill, an AWS Lambda function to handle the requests from Alexa and using Shiftr.io to communicate with the MKR1000.

Setup a Namespace on shiftr

This service allows your MRK1000 to talk to AWS via a simple protocol called MQTT.

  • Click New Namespace, give it a name and click Create
  • Click on the Namespace Setting Page link and click Add Token
  • Leave everything as default and click Create Token

Make a note of your key and secret, you’ll need these later.

Setup LWA

First, you need to create an LWA security profile. Here’s how:

  • Click on Developer Console in the top right corner if you are not redirected
  • Click on Apps & Services, in the menu then click Login with Amazon in the submenu. (link)
  • Click on Create a New Security Profile
  • Fill in all three fields to create your security profile and click Save. The name and description are up to you and the privacy URL can just be http://example.com/privacy
  • On the cog icon, click on Security Profile

Make a note of Client ID and Client Secret, we will need these later.

*** Leave this tab open, we will need to come back here later!

Create the skill

This is super easy! The steps here will provide you with the bare minimum required for a working Smart Home skill.

  • Click on Developer Console in the top right corner if you are not redirected
  • Go to Alexa > Alexa Skills Kit (Get Started) > Add a New Skill (link)
  • In the Skill Information tab:
  • Skill Type = Smart Home Skill API
  • Language = Choose your region e.g. US or UK – this is important and has to match your Alexa device and Lambda function region.
  • Name = Test Smart Home Skill (or whatever you want)
  • Payload Version = v3
  • Click Save

This creates the skill. Note the skill ID near the top, underneath your skill name.

Create a Lambda function

This couldn’t be easier! I’ve included a zip file with everything you need to upload to AWS. Now let’s setup the Lambda function:

  • Go to Services > Compute > Lambda
  • In the top right corner of the page next to Support will be a geographical region. e.g. “Ireland” or “N. Virginia”. Click this dropdown and choose Ireland for an Alexa Skill in the UK, or N. Virginia for US. I’m not sure what other regons are needed for Alexa in other countries.
  • Click on Create Function
  • Step 1: Click on “Author from scratch” and enter the following into the fields…
  • Name = SampleLambdaFunction (or whatever you want)
  • Runtime = Node.js 6.10
  • Role = Create a Custom Role which will launch a new tab. Click Allow. This will create a new role named lambda_basic_execution and automatically insert this role into the Lambda basic information dialog.
  • If after you click Allow the Role changes to Choose an existing role, then select the Existing role named lambda_basic_execution from the box below.
  • Click Create Function
  • Step 2: In the Add Triggers List, click Alexa Smart Home, then scroll down to the box titled Configure Triggers. If you can’t find the Alexa Smart Home trigger it’s becasue your Lamda function is in the wrong region. Try creating a new function in a differnt region.
  • Application Id = skill ID of your test skill that you noted above
  • Enable trigger = checked
  • Click Add
  • Step 3: Click on the name of your function in the layout box at the top of your page e.g. SampleLambdaFunction, it has an orange icon.
  • Scroll down to Function Code and enter the following information…
  • Code entry type = Upload a .ZIP file
  • Click on Upload and choose the upload.zip from the repo HERE
  • Handler = index.handler
  • Under the Environmental Variables section, enter the following keys/values:
  • key=MQTT_KEY value=Your shiftr key from earlier
  • key=MQTT_SECRET value=Your shiftr secret from earlier
  • key=DEVICE_ID value=brewTime-01 (the device ID can be changed as long as you change the device ID in the Arduino sketch as well)
  • Click Save at the top of the page.

In the top right corner, note the Lambda ARN.

Configure the Skill

Now that you have all the components, let’s put everything together.

  • Click on Developer Console in the top right corner if you are not redirected.
  • Go to Alexa > Alexa Skills Kit. (link) Then click the test skill you created earlier
  • In the Configuration section:
  • Endpoint > Default = enter your Lambda ARN noted from the previous step
  • Authorization URL = https://www.amazon.com/ap/oa
  • Client ID = your client ID from LWA noted in a previous step
  • Scope = profile (click Add Scope first) *this is case sensitive*
  • Access Token URI: https://api.amazon.com/auth/o2/token
  • Client Secret: your client secret from LWA noted in a previous step
  • Client Authentication Scheme: HTTP Basic (Recommended)
  • Click Save

Provide Redirect URL’s to LWA:

  • The Configuration page for your Skill lists several Redirect URLs (shown in green above). Open the LWA security profile you created earlier (the tab that you left open) and click on the Web Settings tab. Click Edit and provide each of the Redirect URL values from your Skill in the Allowed Return URLs field. Click Save.

Upload the sketch to your MKR1000

  • Don’t connect your MRK1000 just yet
  • Launch the IDE and open the MKR1000 sketch from the repo. HERE
  • Click on the tab called arduino_secrets.h
  • Enter the SSID and password for your WiFi into SECRET_SSID and SECRET_PASS
  • Enter the shiftr key and secret you wrote down earlier into MQTT_KEYand MQTT_SECRET
  • If you chose a different device ID when creating the Lambda function, then change MQTT_DEVICE_ID here to match.
  • Click on the Tools menu, where it says Board: xxxxxxxxxxx and click Board Manager…
  • In the text box enter MKR
  • Click the entry called Arduino SAMD boards… and click Install. Once the install is complete click Close
  • Click on the Tools menu, where it says Board: xxxxxxxxxxx and click Arduino/Genuino MKR1000
  • Click on Sketch > Include Library > Manage Libraries… on the menu
  • Search for WiFi101, click on WiFi101 by Arduino, click Install
  • Search for MQTT, click on MQTT by Joel Gaehwiler, click Install, click Close
  • Connect your MKR1000 with a USB cable.
  • On the Tools menu again, where it says Port: xxxxx select the correct port, e.g. COM10 (Arduino/Genuino MKR1000) This may already be selected.
  • On the menu click Tools > Serial Monitor to open the serial monitor window.
  • Then click Sketch > Upload, once the upload has completed you should see the following appear in the serial monitor window…
Checking wifi...done
Connecting to MQTT broker...done
Status: OFF Power: OFF Heat: OFF 

Test it!

Now comes the fun part:

  • You should see a variable appear in the list on the left called BrewTime/Actual and a blip moving around the nodes every 10 seconds.
  • Login with same Amazon developer account
  • Make sure you have an Alexa device associated with the account. If not, in another tab visit https://echosim.io/ and setup a virtual Alexa on your Amazon account.
  • Once you have an Alexa device setup Go to Skills > Your Skills (in the top right corner) then click on Dev Skills.
  • Click on the skill and then click Enable
  • Log in with the same Amazon credentials when presented with a LWA login page
  • Allow LWA access, and you should see a message that says you can close this window. Close that window and you should be presented with a popup asking to discovery devices. Click Discover Devices.
  • Go to Smart Home > Devices and you should see Brew Time Kettle
  • Now with your Alexa device, try “Alexa, put the kettle on”, Alexa should respond “OK” and the LED should light up on the MKR1000.
READ  Python Meets the Arduino

The Hardware

Schematics

Kettle PCB

Where to connect the wires to the kettle

Maker:S,Date:2017-8-29,Ver:6,Lens:Kan03,Act:Lar02,E-Y

Wiring Diagram

How to connect up the MKR1000 and Logic Level Converter to the kettle.

Schematic

The Schematic.
Alexa, Put the Kettle On! schematics

Code

BrewTime repository

Contains the AWS Lambda function and the Arduino MKR1000 sketch.

Arduino MKR1000 powered Alexa Smart Home Skill to put the kettle on. — Read More

 

Source : Alexa, Put the Kettle On!




This Post / Project can also be found using search terms:

  • adding alexa to existing esp32 project
  • use alexa in arduino project

Leave a Comment

*
= 5 + 0

(Spamcheck Enabled)

Read previous post:
Chicken Coop Automation
Chicken Coop Automation

Automating a chicken coop with sensors and actors, using an Arduino MKR1000 and the Blynk internet dashboard. Things used in...

Close
Scroll to top