Control RPi with TV Remote

One of the things that made the biggest impression on me when I borrowed rpi from Tomek was that I could control this tiny computer with my tv remote. Now it may sound a bit silly :), but that was over a year ago. Now, with our Lightberry and possibility to have ambilight effect even for external source, I was wondering how to turn off or on the leds. The only thing I had was rasbian with hyperion and drivers for the grabber installed. TV remote does not work out of the box with such setup :). We all know that XBMC can be controlled with TV remote via CEC, so I thought there had to be a way to make use of my remote to turn hyperion-v4l2 on and off. Of course, there is :) This is how you do that….

In theory everything is written on cec website, but it took me a while to understand what packages I need to install via app-get or what parameters I need to pass to compile it correctly. After gathering information from many forums it gets very easy at the end…

In order to install cec for pulse-eight adapter on Rpi you need to compile it on rpi with certain parameters and, before that, you need to have few other packages and development headers installed.

Here is step-by-step instruction that works perfectly on Raspbian:

Ok so we have it installed – lets run it and let’s press some buttons on the tv remote.
Here is how you start it:

Now, let’s press “play” button on the remote… This is what happens at cec-client:

Now, Let’s press “2” on remote…

Ok, cool. So we can see what buttons we use, but how to execute a script depending on what button was pressed?

Here is how I did it although my gut feeling is that there has to be more elegant way of achieving the same result :) any suggestions are very welcomed.

First you run cec-client with -sf (file) switch… It will make cec-client to log user actions into the (file). Then I wrote simple script that scans through the log file ( ${1} ) and searches for user interaction:

Now instead of “echo” command just put some scripts there and you can do everything with your TV remote :)

ENJOY!

Here is your raspberry pi ampilight system!
  • Mischa Anwald

    Very cool idea!!!

    Two questions:

    1) I’m using Hyperion on Raspian with WS2801 LED-Strips and this tutorial: http://bite-in.com/?p=9 for a standalone-solution with multiple HDMI-sources.
    Will your tutorial also work with this setup or is it only usable when using the rPi not only as the Ambilight-controller but also as the mediaplayer? Because right now the HDMI-port of my rPi is not connected to anything.
    2) How would a script for turning the LEDs on or off will look like? Unfortunately I’ve got no further experiences with Linux and scripting. My LEDs are connected to my rPi through a WS2801-bridge kit from hackerspaceshop.com sitting on the GPIO-pins.

    Thanks a lot for your help and best regards

    Mischa

    • Jacek

      Mischa, you must have hdmi cable connected to rpi and your tv must be switched to raspberry pi hdmi port in order to transmit cec commands.

  • AdamR

    #archeologist suggestion
    Other option is to create script (in this case switching hyperion on-and-off) and then changing keymap XML to use following command when choosen key is pressed (works for kodi)

    XBMC.System.Exec(“your_magic_goes_here.sh”)

    Hint: Keymap Editor addon (kodi) helps to get this stuff done – creates new XML config file and allows to get IDs of remote’s keys.