I always had a fascination in Smart Home Automation. It was cool and fun. I noticed that I didn't like opening and closing my curtains everyday. So to resolve this, I got a remote controlled curtain. However it wasn't able to be voice controlled. So I wanted to make a Smart Home Alexa skill to resolve this. It was going to control my curtains automatically, but also control all of the other smart devices in my house or work environment. This would improve my everyday life since I no longer had to do all the normal daily things manually. I just let the Echo do it for me, and so there's no need to waste time do these basic things. I also realized that since I had multiple products like Smartthings and Wink in my house, why not combine them all in 1 skill? This would make my life simpler for setup and control. That is the inspiration I got to make skill, a life hack to a simpler, easier, and futuristic lifestyle.

What it does

The intent of this project was to control my curtain, as well as other smart devices, through voice commands. My skill is a Smart Home Skill, and it allows users to control their smart home devices through voice. Not only that, it also allows users to control multiple brands of devices like Smartthings, Wink, and Nest. So if I had 1 device connected to Smartthings and 1 device from Wink, I would be able to control both of them from the same Alexa skill. In a technical perspective, the Amazon Alexa would connect to a Smart Hub via Wifi which would connect to smart devices like lights via RF.

How I built it

I built my skill via Node.js. I utilized AWS lambda, AWS IoT Gateway, and DynamoDB for the entire project. The main components of the voice control function were primarily from Node.js in AWS Lambda. The rest were mostly for account linking. I did a lot of research on the Smartthings, Wink, and Nest APIs, all of which were implemented in my Lambda function. The APIs would allow Alexa to communicate with these Smart Home services, as implied from its definition: an application programming interface.

For hardware, on my curtain motor control, I build a circuit that communicated via ZigBee to the Smart Hub. This hardware was able to activate the motor to open or close. It is essentially a Smart Home device that I created and the Amazon Echo was able to control it successfully with my Amazon Alexa skill.

Challenges I ran into

The major challenge with account linking I ran into was with Smartthings. Because I was using their new Beta version of APIs, their authorization server had not yet been fully developed. And so I had to make my own authorization server. But so much constant trial and error, I was unable to do this. As a backup plan, I made the account linking process manual. So the user was required to input their access token manually, which would be saved from the AWS service. This worked successfully, but it was a bit cumbersome. So in the future, I plan on making this way simpler to setup.

The incremental and iterative development process I followed was coding, testing, and debugging. Often times, my code was in incorrect format, and so I went through a series of trial and error, refining and testing code, to fix the problems. One difficulty I faced was retrieving data from the Smart Hub. I got an error every time I tried to get information from the Smart Hub. After trial and error, I resolved this issue when I found out that the returned response from the API was actually an object with an array in it. So in order to format the code to retrieve data correctly, I had to make a request that calls the object and the array in it. I also had an issue when I did a https request to retrieve a device’s Id, global variables that were set a value inside of the https request, wouldn’t actually be saved in the global variables. So when I tried to call the global variable outside of the https request, it didn’t actually contain the updated value. I went through trial and error to resolve this and found that if I wanted the variable to be used again by another function, I had to place that function inside of the https request. My whole development was independent.

Accomplishments that I'm proud of

First and foremost, I am very proud that I was able to actually control my devices! This was very hard for me to understand. I initially had no idea how to make a Smart Home skill, let alone with programming with APIs. This was my 1st time doing this. But after many weeks of research, programming, and testing, I was finally able to accomplish what I thought would be impossible. Likewise, I was also ecstatic that I managed to make my skill and actual Smart Home Skill; not just a custom skill. Making a Smart Home Skill was like a whole another world for me from the regular custom skill. Everything was more technical and standardized. So I had to follow every smart home programming rule provided by the Amazon Alexa developer requirements. I read through numerous articles, and finally figured this out. And lastly, as a lazy person, I'm so glad now that I no longer need to open my curtains manually. I know let the Amazon Echo do all the work for me. Overall, I'm no expert in the field of Smart Home development, but I certainly have gained a lot from this entire experience, and that's a major accomplishment that I'm most proud of.

What I learned

The overall take back from this learning process was how to make my own Smart Home Skill. Before this, I only knew how to make custom skills. I worked with basic games and simple interactions between the Echo and the user. But throughout this project, I figured out how a smart home interface worked, and how all the functions of a Smart Home Skill worked. And with that, I then learned about how to program with APIs because that was the only way the Amazon Echo could communicate with the Smart Home Services. These API were implemented in my AWS lambda function, which was coded in a new learned language, Node.js.

For account linking, I learned how to utilize multiple AWS services such as AWS IoT Gateway and DynamoDB. Because of the 1st issue with Smartthings account linking, I needed to use these services to save the access token for the user. Additionally, for the web pages in my account linking (shown in video), I learned how to program in HTML and CSS for the first time. I stylized the interface with a clean, white page look to make it look futuristic and cool.

Lastly, I also learned the flow of oAuth2.0. I spent numerous days attempting to create my own authorization server. However, I struggled and am probably not at the level of knowledge that I need to be to make this. And so to return my account linking page back to the Alexa redirect URL successfully, I was forced to use "Login with Amazon" as the authorization server.

What's next for Universal Smart Home

First off, I need to fix some of the bugs that I have with my Wink and Nest account linking in my skill. So those are currently in heavy development. But for the future, I plan on incorporating even more Smart Home Services into my 1 skill; try to make my skill a standard skill for all Smart Home Services. This will make everything easier and more centralized for customers who want to integrate their smart home products with Alexa. I also plan on adding more devices that my skill can control. As of now, my skill only supports the capability of a "Power Switch" (on/off) to control devices. There are many devices that have more that on/off abilities, and so I need to make sure my skill supports control of that. Lastly, I plan on making the user interaction easier. This way when customers try to control their devices through Alexa, they can use native voice control. Some inputs from users aren't recognized by the Echo, and so I need to make my skill more flexible and understand more of the user language. Overall, there is so much room for my skill to grow upon, and I will always continue to develop and improve my skill.

Share this project: