Eubolist's Blog

about IT, Linux, the web and much more

Set up LIRC to control your Ubuntu/MythTV Box with a Microsoft Media Center Edition (MCE) infrared remote control

with one comment

I wanted to control my MythTV-Box like I used to control my old receiver with a good old fashioned IR remote rather than with keyboard and mouse. That’s why I went to eBay and bought myself a cheap MCE remote, you can have them shipped from China for less than 20 bucks:

I didn’t know whether the device was Linux compatible, so I just plugged it in and took it from there:

~$ lsusb

Bus 003 Device 002: ID 045e:006d Microsoft Corp. eHome Remote Control Keyboard keys

Looks good. Let’s install the latest version of lirc:

~$ sudo aptitude update && sudo aptitude install lirc

Then let’s check whether lirc picks up correct signals from our remote:

~$ irw

Then press the OK or any other button and the output should look somewhat like this:

000000037ff07bdd 00 OK mceusb

If it does: Congratulations, you’ve got a lirc compatible infrared remote! Exit irw by pressing [Ctrl + C].

LIRC normally runs at system start as a daemon (=runs in background). It reads a file called “.lircrc” in your home directory, in this file you can specify a command for each button. You can even specify custom keybindings for different programs, let’s have a look at my .lircrc file:

~$ cat .lircrc

include /home/eubolist/.mythtv/lircrc                             –> Here we specify which configuration
include /home/eubolist/.lircfiles/vlc                                       files to include in addition to this one
include /home/eubolist/.lircfiles/rhythmbox

begin
prog = irexec                –> irexec means that lirc will
button = Home                   pick up your command no matter which program is running
config = python /home/eubolist/ir-scripts/mythfrontend.real.py 
end

begin
prog = irexec
button = TV
config = python /home/eubolist/ir-scripts/miro.py
end

begin
prog = irexec
button = Videos
config = python /home/eubolist/ir-scripts/vlc.py
end

begin
prog = irexec
button = Music
config = python /home/eubolist/ir-scripts/rhythmbox.py
end

begin
prog = irexec
button = Power
config = python /home/eubolist/ir-scripts/onoff.py
end

Now you may ask yourself why I have some Python scripts specified as actions when I press certain buttons. The reason is simple, let’s have a look at vlc.py:

##!/usr/bin/python
import commands
import os
import sys
import subprocess

output = commands.getoutput(‘ps -A’)

## Check whether vlc is running:              –> As I usually don’t need multiple instances of the same
if ‘vlc’ in output:                                    program running I want to check whether it’s already open

## If yes: either shut the process down
#       os.system(‘/usr/bin/killall vlc’)

## or do nothing:
sys.exit(0)

## If not: Open vlc and end this script:

else: pid = subprocess.Popen(‘/usr/bin/vlc’).pid       –> If you just use os.system() again here the
sys.exit(0)                                        script will just stay open and keep irexec busy, if you press the button again it woud get queued and run again once you exit vlc

Now have fun toying around with Ubuntu and your ir remote control. If you have any questions, thoughts or criticism you are welcome to write a comment.

Advertisements

One Response

Subscribe to comments with RSS.

  1. […] #split {}#single {}#splitalign {margin-left: auto; margin-right: auto;}#singlealign {margin-left: auto; margin-right: auto;}#splittitlebox {text-align: center;}#singletitlebox {text-align: center;}.linkboxtext {line-height: 1.4em;}.linkboxcontainer {padding: 7px 7px 7px 7px;background-color:#eeeeee;border-color:#000000;border-width:0px; border-style:solid;}.linkboxdisplay {padding: 7px 7px 7px 7px;}.linkboxdisplay td {text-align: center;}.linkboxdisplay a:link {text-decoration: none;}.linkboxdisplay a:hover {text-decoration: underline;} function opensingledropdown() { document.getElementById('singletablelinks').style.display = ''; document.getElementById('singlemouse').style.display = 'none'; } function closesingledropdown() { document.getElementById('singletablelinks').style.display = 'none'; document.getElementById('singlemouse').style.display = ''; } Re IPhone Universal Rc – Infrared Remote Control Accessory For IPhone, IPad And IPod Touchhealth for all databaseiPhone Universal Remote ControlHacked Air Conditioner Infrared Remote Control – Hacked Gadgets – DIY Tech BlogUK SmartPhones FansSet up LIRC to control your Ubuntu/MythTV Box with a Microsoft Media Center Edition (MCE) infrared r… […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: