Dot controlling a Photon microcontroller
So there I was creating my 5th Photon controlled LED lighting project for my RV. This was getting really fun. I had several Photons controlling lights and fans, and an Alexa skill and iOS apps to control them. To add another device, all I needed to do was:
- Decide on a name for the new device
- Copy/Paste and modify a bunch of existing C++ code from my earlier 4 projects to the new Photon.
- Update my Alexa skill to recognize the new name
- Update my iOS control panel apps to add the new name
Being a professional programmer, it bothered me that every time I added another IoT project to my RV I had to repeat these same 4 steps, even if the new project was very similar to one of the others. So I started thinking about how to reorganize my Alexa skill, iOS apps, and Photon sketches to see if I could make this process quicker, easier, and less error prone. It turns out that it can indeed be a lot quicker and easier.
What it does
An Alexa Smart Home Skill has the ability to "discover" devices. So if a device can publish information about the commands that it responds to, then Alexa could automatically support those commands without needing to be reprogrammed. So that's what the Patriot hobbyist smart home skill does.
How I built it
To start with, I took all the duplicated Photon code and put it into a library that can be used by each new project without any cutting and pasting each time. Then I published this library, named "IoTlib", using Particle's new v2 library format so that it can be used by anyone, using any of the available IDEs: Web, Atom, or CLI.
Next I thought about how to enable the Alexa skill and iOS apps to so that they could automatically detect new devices so that I wouldn’t have to keep updating them in order to support new devices. I realized that each device can expose its name, and the actions it supports, using a particle.io variable. So I updated the IoTlib code to do that, and updated the Alexa smart home skill to automatically "discover" those actions. So now when I add a new Photon device, all I have to do is program it using the features provided by the IoTlib, and within a few minutes I can start controlling it with my Alexa. I can also use the Alexa app tell it to "Discover new devices", and the new device will be discovered right away.
Challenges I ran into
The biggest problem that I ran into was figuring out how to make connecting all the needed pieces easy.
Accomplishments that I'm proud of
The feature that I am proudest of is the fact that a hobbyist can leverage the power of Alexa's voice capabilities without having to learn another programming language and environment.
What I learned
What's next for Patriot IoT Hobbyist Smart Home Skill
This project only scratches the surface of the things that are possible with today's IoT technologies. Alexa has taken it a huge step forward. Integrating it with other technologies such as AppleTV, wearables, and computer vision are just a few lines of programming away.