Raspberry Pi + HDMI CEC + Node.js

I’m a huge fan of Google’s Chromecast. I’m an even bigger fan of the little-known HDMI CEC protocol originally introduced with HDMI 1.0, which is a spec that allows devices to control CEC-enabled devices through HDMI. This is the technology used by Google that allows Chromecast to turn a TV on from a standby state and automatically switch to the appropriate input when you cast a video stream to the device from a remote client. While this has been a great feature which I frequently use with my Samsung HDTV (Samsung refers to HDMI CEC as “AnyNet+”), it’s unfortunate that there was no option to turn off the TV from a remote client.

After doing some additional research I quickly learned that HDMI CEC is rather capable with what it allows a client device to do and that it does so much more than just turning on or off a device – OSD Display, Device Menu Control, Routing Control, System Information, Timers, Status, to name a few.  I was ecstatic!

After digging even deeper I learned that my Raspberry Pi Model B fully supports HDMI CEC, and the fine folks at Pulse-Eight have developed a fairly mature C++ based library to control rudimentary CEC functions. While this was a great option, it required me to maintain an SSH connection into my Raspberry Pi which was less than ideal (I’m so lazy that I can’t reach for the remote control, what makes you think I’ll SSH in to issue a command line to my Raspberry Pi to turn off my TV?).


The palm-sized Raspberry Pi Model B computer!

I decided to wrap the lib-cec C++ library in a quick and dirty Node.JS Express Framework app so that I could remotely send commands from my phone over a web server. The core piece of my app is contained here, which enables the “on”, “off” and “status” functions of the CEC protocol, and pipes the output to the web client for the user to see:

The app routes are invoked when the user accesses the URL path for “on”, “off”, or “status”. I modified my Firewall’s Iptables to port forward the app so I can even check on my TV from outside my network, and it works like a charm! I can now control my TV from my iPhone, which means…


Full code can be seen in  my GitHub project page found here. Feel free to help me clean it up 🙂

One thought on “Raspberry Pi + HDMI CEC + Node.js

Leave a Reply

Your email address will not be published. Required fields are marked *