Alexa, turn on my TV!
How I controlled my TV with an Echo Dot
A few months ago, I decided to build an app for Amazon’s smart home device, the Echo. I’ve been interested in getting my hands dirty with developing smart home apps, and thought I’d try controlling my TV with my voice. This article provides a high level overview and technical details of how I built an app with an Echo Dot and a Raspberry Pi. The code for everything required to build this app is located here.
When I first got the Dot, the most common use case I had was controlling my Phillips Hue lights and playing Spotify playlists. The “aha” moment for the connected home came to me when I realized that LG had built a developer platform for their TV, and someone had already built a node API for it. This meant that building an app to control my TV was possible. This amazed me because there were already pieces of hardware in my home that were connected to my network with existing developer platforms that were easy to build on top of. I decided to build an app that helped me switch my TV input to my PlayStation, since my roommate often plays Xbox on a different input.
It is worth noting that there are existing solutions that can be purchased to solve similar tasks, like Anymote or Harmony hub. I wanted to both save money and learn how the Alexa platform works, so I opted to build a custom solution for my place. The end solution may not be the most efficient, but it works pretty well.
At the core, my TV and Echo communicate with each other via Firebase. Whenever a user issues a command, my AWS Lambda instance updates a parameter in Firebase. Firebase has an API that allows any client to be notified whenever a value is changed in a performant manner. The Raspberry Pi listens for these changes and notifies the TV.
How do you send requests to your TV if it is off? Modern TVs have an interesting feature on the HDMI ports called the Consumer Electronics Control (CEC), which allows devices plugged into HDMI ports to send control signals to the TV. A common use case of this is automatically powering on the TV when an Xbox turns on to avoid having the user manually turning the TV on. This feature was useful to my project as I was able to power the TV remotely by first turning on my Chromecast. How did I turn on my Chromecast? Luckily, there is a node API for just about anything you can imagine. Essentially by switching on the Chromecast via the node API, I can quickly and automatically switch the input to the previous known state.
Moving forward, there are a few features I would still want to build. It would be fun to implement a “shuffle” feature for TV channels, similar to how you would expect it to work for music. For example, imagine saying “Alexa, find me something to watch on TV” and have the TV flip channels, maybe in a random order, and stop on command. Overall, this was a fun project to work on, and truly sold me on the notion of smart homes.