When I heard about this contest, I thought many things. But an idea came to mind, we have many things in our home that we cannot control via Alexa/mobile phone like traditional fans, lights, TV, ovens, juicers, lightning strips and etc. So I planned to develop a generic smart power strip with temperature capability to control anything generically. And it's a portable power strip, you can move it to any room when you require. For example, you want to monitor the baby room temperature and control its fans, lights and heater. Or you want to monitor your parents room, then shift this gadget to their room, or if you want to wish a surprise to your loved one (I mean wife ;)), then move this smart power strip to your room and attach fancy lights strips and control all your traditional electronics with Alexa Smart Home skills. This Alexa-enabled power strip is also good for paralyzed persons (with voice) to control their basic appliances according to their mood - now, no more dependency on others! This power strip will also work like a thermostat.
Smart Home skill is great thing for developers. For this, we don't care about voice commands, we just need to focus on the device and its communication with Lambda. Alexa will handle all voice commands, send directives and requests to Lambda and then Lambda will generate the response after communication with the device cloud. You can more read about Alexa Smart Home skills: https://developer.amazon.com/alexa/smart-home
I am going to divide this project into the below 3 phases:
- Preparation of Smart Power Strip
- Connecting it to Cayenne Mydevices Cloud
- Preparation of Smart Home Skill, Lambda to bridge Smart Home Skill with Cayenne MyDevices Cloud
First of all, collect all the above mentioned hardware components. And below is our very simple hardware assembling diagram which will demonstrate how the sensor and relay are connected with MKR1000.
Everything is simple except we have a single ground and I am not going to use any vero board. Take 3 female-to-female cables and join two cables head with the third cable, now we have 2 grounds. Connect one with TMP36 and the other with the relay.
- Relay In1= Pin#1
- Relay In2= Pin#2
- Relay In3= Pin#3
- Relay In4= Pin#4
- Relay VCC=5V
- TMP36 Data Pin= Pin#A1 (analog)
Connect its VCC to MKR1000 VCC (not with 5V because we are using TMP36 formula for 3.3V)
Note:* After completing the above step move to Cayenne Cloud Step for MKR1000 setup.
After completing the Cayenne Step we need to pack our stuff in a plastic box for protection or movement.
Cayenne MyDevices is a very nice IoT Cloud Platform which offers many features such as drag-n-drop of widgets by visual interface, triggers and etc. Please read this article for detailed Cayenne My Cloud Device Setup: click here.
After successful linkage, create 4 button widgets and 1 value widget for temperature. Assign the channel 1, 2, 3, 4 to button widgets as we assigned the relay pins to Arduino MKR1000.
After setting up the device and widgets at Cayenne, please update your below code with username, password and Client-ID and upload it to MKR1000. Test the product. If everything is working fine then again move back to the top for packing your hardware components in a box. If there is any problem, review everything carefully again or you can post the query in comments section. I will try my best to solve your problem.
Preparation of Smart Home Skill & AWS Lambda to bridge Smart Home Skill with Cayenne MyDevices Cloud:Some important terminologies and short codes which will be used throughout the whole process.
- LWA: login with Amazon
- AWS: Amazon Web Service
- Lambda: a service by Amazon to run any language code in a cloud without management of resources
- alexa.amazon.com: for managing Alexa device skills
- developer.amazon.com: developer portal for managing Alexa skill development, login and etc.
- https://console.aws.amazon.com/console/home: Amazon Cloud Service Portal Like Lambda, Storage, Compute and etc.
Before we create the Smart Home skill we need to create LWA settings for the skill.
Open developer.amazon.com login and then click on Developer Console. Click on APP & Services, then on Login with Amazon and then click on Create a New Security Profile. Fill in the details. After that, you will receive Client ID and Client Secret; save these for future use.
Now click on Alexa and then click on Alexa Skills Kit.
Click on Add new Skill.
Select Smart Home Skill API. Enter your Skill Name.
When you click on the Save button, it will save the skill and generate the Application ID. Save it for AWS Lambda usage. Before we move to another step in Skill Development, we need to create a AWS Lambda for the skill so now it's time to move to https://console.aws.amazon.com/console/home.
Type Lambda in the search bar and select Lambda.
Click on Create Function.
Select Author from Scratch. Enter Function Name, and select Existing Role lambda_basic_execution. And click on Create Function.
After creating the function, you got ARN, save this for use in Skill Configuration. From the sidebar, drag Alexa Smart Home under your function.
After dragging, enter your Smart Home Skill Application ID and check on Trigger.
Now click on Function Name and you will see the Editor copy. And put the Lambda code below into Lambda Editor, but before saving please change your Cayenne Device ID & Sensor ID to work properly with them.
Now we need to move back to developer.amazon.com to complete other parts of the Alexa skill. Configuration is easy except the configuration tab. So we will focus on Alexa Configuration tab.
In Default, enter your AWS Lambda ARN & select the region. after that in Account Linking insert the ClientID and Client Secret that you can take from LWA. And in Authorization URL enter: https://www.amazon.com/ap/oa/, and Access Token URI: https://api.amazon.com/auth/o2/token. Under privacy policy, enter your privacy policy page URL.
After getting the all tabs green, you are able to test your application. Click on Manage Test and then you will begin testing the URL to install the skill.
Generic Electronic Appliance Demo:
Surprise Room Demo:
Future Work:
Due to time constraint, I was unable to include all features, but you can implement features like:
- Turn on all the sockets by one command
- Turn off the all sockets by one command
- Automate your sockets with a temperature range like thermostat
Comments