DISCLAIMER: This project deals with 110V and also voids the appliance warranty. So proceed at your own risk.
Updates:
Oct, 10th 2017: I have changed to new Alexa API v3.
Oct, 16th 2017: Better step-by-step description (copied from my other project https://www.hackster.io/saka/alexa-voice-control-for-almost-any-amplifier-tv-cd-dvd-87fff1)
Why hack a smart kettleBeing a tea drinker, I wanted to automate switching on/off my electric kettle. Initially, I thought of the simplest solution of adding a smart plug. That, however, had a very unfriendly characteristic of having to remember to leave the switch on; so being unreliable myself and my wife being the best tester of my ideas, we immediately rejected this one. I turned to the market and tried to just buy one. With so many smart appliances around, I thought this would be a simple tasks - not so much. There is a smart kettle with Alexa functionality available in UK, but not being sold in US (and would require a transformer). I found one advertised as controlled by smartphone app, made by a company called Aimox. I just thought I could check what commands are being sent and somehow integrate with Alexa. That proved futile, it is using a very old technology and not REST API (all UDP discovery). So ended up hacking one myself.
I selected Hamilton Beach 40996. Primarily because:
- It is relatively cheap ($33 on Amazon) so if I would end up breaking it not a big loss.
- Programmable, so the on/off keys are not mechanical but push-button type.
- The electronics are in a relatively large base, where I was hoping there is enough space to fit additional components (there is) => the only visible alteration externally is an LED that I added, otherwise all components are built in.
For this project I'm using the newest version of the Alexa Home Skill API (v3). I actually originally started with developing custom Alexa skills and got it to work. But due to the requirements of invocation, etc., it was quite a mouthful to say "Alexa tell smart kettle to put water on". Another DOA not passing my wife's test. Using the Alexa home skills it is a hack in itself, as meant for lights. But works very well, just saying "Alexa, kettle on".
So how my solution works:
- Through Alexa I am able to invoke a Particle cloud function ("KettleOnOff").
- The Particle is interfacing with the kettle through 2 octocouplers: one is simulating a on/off pushbutton press, the other detecting if the kettle is on or off (it looks at the relay coil 12V); the kettle state detection is necessary as the the button is toggle, so the function should be activated only if the state is different then desired.
- The Particle function can be also linked to IFTTT; I have for instance created a trigger every morning, so when waking up the water is hot.
- I added an LED, which is visible externally and used to communicated states (a heartbeat from Particle every 15s saying it's alive), on/off state and a few seconds blink when the function is activated.
- The Hamilton Beach kettle by default has a warm up function, sustaining the desired temperature for 1 hour; for me this is too much but cannot be reprogrammed; I added some code to the particle that shortens that time to 20 minutes.
- There is a 5V signal somewhere on the Hamilton Beach electronics; but I wasn't sure about quality and whether it can withstand the additional Particle consumption (and could not locate the service manual/schematics); as such I found a small cell phone charger with micro USB and put that inside the base, powering the Particle.
You need a developer account with Amazon, if you don't have one you can sign for free.Go to https://developer.amazon.com/alexa In the developer console go to Alexa Skills Kit
Then create a new skill:
You need to select
- Smart Home Skill API in the Skill Type
- Name can be anything you like
- Payload version v3 (new APIs that Amazon released recently)
Once you save it, a unique Application ID is created, you'll need that later on for the Lambda function
Press Next, Next and go to the configuration window.
In order to configure this window, you need few parameters that you'll get from executing a Curl command (you can download the program if you don't have it; you execute in a terminal window):
curl https://api.particle.io/v1/clients -d name=your_name -d type=web -d access_token=particle_token -d redirect_uri=""https://layla.amazon.com/api/skill/link/code_in_alexa"
where:
- name => your choice, just keep it simple (I used Krell, which is the make of my amplifier)
- access_token => here you need to go to the Particle IDE and under Settings copy the Access Token
- redirect_uri => you get this in the Alexa Skills configuration window (see picture)
The response to the Curl command would look something like:{"ok":true,"client":{"name":"your_name","type":"web","secret":" secret_code ","redirect_uri":"https://layla.amazon.com/api/skill/link/ code_in_alexa ","id":" your_name-number "}} These are the Oauth parameters that you need to finish the Alexa skills configuration. Here what you set:
- Authorization URL: https://api.particle.io/oauth/authorize
- Client Id: your_name-number result from the Curl command
- Scope: profile
- Access Token: URI https://api.particle.io/oauth/token
- Client Secret: secret_code result from the Curl command
Leave all the rest defaults. You done with the Alexa Skills setup! Off to Lambda configuration.
LAMBDA CONFIGURATIONFor this part you need an AWS account. You can create one at https://aws.amazon.com/ Before we can configure Lambda we need to set the right permission. In the AWS Console, go first to IAM, Roles, and create a new role. You need to attach the AWSLambdaBasicExecutionRole, should be enough. Then choose a name for it, I used Alexa_particle.In the Console go to Lambda and make sure you select N. Virginia as region; currently the speech API are only supported there. Then create a new function
Select "Author from Scratch" and fill the info:- Name: your choice- Existing role: the role you created in IAMOnce you created the function go to triggers and select Alexa Smart Home, for the Application Id you need to copy it from the application you created in the Alexa API section.Next go to configuration and copy the code from this project (krell.js)
Few edits you need to do:
- set the variable "particleId" to your device ID, you can find it in the Particle IDE under devices
If you have done all the steps correctly, when you go to your Alexa app, under Skills/ Your Skills it should show the Alexa application you created (e.g. Krell_Serial). In the app go to Smart Home/ Devices and do a discover. Should see the controller as Stereo (if you haven't changed the friendly name in the Lambda code. Once you connect the HW to the serial port of the device you want to control, it should react to the Alexa commands (e.g. "Alexa, kettle on").
DEBUGGINGIf something does not work, you can configure the test events in the Lambda function. The easiest way is to go to the reference documentation https://developer.amazon.com/docs/smarthome/smart-home-skill-api-message-reference.html and copy the response from the interfaces you want to test, for instance for switching on looks like this:
You need to change the token and deviceId to your particle, how to find those was described earlier in the article.
Comments
Please log in or sign up to comment.