Saturday, April 18, 2009

Howto setup Remote for Ubuntu 8.04 XBMC with MS Remote

It is pretty straight forward to setup basic functionality but finding information is a nightmare.
The biggest problem was to get the shutdown to work with auto started irexec.

1) Remote control XBMC and other applications.
2) Start stop & kill XBMC with remote
3) Shutdown computer
4) Autostart irexec

Basic setup

The first step is to install and configure LIRC.

sudo apt-get install -y lirc
Select windows media center remotes (New version)
IR Transmitter: Select “none”

run irw in terminal and press any button on the remote, the name of device and button should show on screen.

This is pretty much it if you have a standard remote. I have had no problem with MS MCE Remote. You should now be able to control XBMC.

To control other applications you have to create your own button => function mappings.
This is stored in the .lircrc file in ~/.

This is best done by using the lirc generator from the mythbuntu team.

sudo apt-get -y install mythbuntu-lirc-generator
and you will get the lircrc files for the most common applications.

Totem is the standard player in Ubuntu 8.04, it is supported by this setup but first you need to enable the remote plugin from within the player.

Advanced setup
Download files & scripts here.

Setup start stop & shutdown
Most of this is from Some changes was necessary though.

We need irexec to do this and for good measure we setup irxevent as well. The latter is used to send keyboard commands. (ctrl-s etc)

install irxevent
sudo apt-get -y install lirc-x

create file named irexec in ~/.lircrc

# Start XBMC
prog = irexec
button = Home
config = ~/scripts/ &

# Kill XBMC
prog = irexec
button = Red
config = ~/scripts/ &

prog = irexec
button = Power
config = ~/scripts/ &

The '&' is necessary at least in my setup, otherwise the startXBMC will loop in the background and when I exit XBMC it is restarted several times.
I found the solution here

Create an empty file named irxevent in ~/.lircrc
It will contain the mappings for irxevent. I am not using it for the moment. I wanted to send ctrl-alt-Delete, but could not get it to work.

include ~/.lirc/irexec
include ~/.lirc/irxevent
to the ~.lircrc file

echo  "include ~/.lirc/irexec" >>  ~/.lircrc
echo  "include ~/.lirc/irxevent" >>  ~/.lircrc

The next step is to create the script files.
Pick them up at
Worked fine for me, I replaced /home/youruser/ with ~/ when possible. I think the remaining hardcoded usernames can be removed by following the comments further down in the thread (pidof?). I guess killall would also do the trick.

To autostart the irexec (and irxevent) add
to system/preferences/sessions. NB: ~/scripts does not work here.

First test to start manually from terminal

Run it twice and you should see that the script kills the old processes before the new is started.
ps -C irexec
should show one irexec process after two runs.

Now you should be able to start and kill XBMC. Kill should only be used when XMBC cannot be closed down the normal way I think.
Please note that I have mapped Power button to shutdown, when shutdown is finally working it will make it impossible to use the Power button to exit XBMC without shutting down the computer. The mapping can be changed in the irxec file. I think it can also be fixed by using mode in the lirc files to separate the applications.

Now to the shutdown..
I use
sudo /sbin/shutdown -h now
in the shutdown script. We can't have the script asking for password and this is fixed by editing the /etc/sudoers file. It is edited with this command:
sudo visudo.

First make backup
cp /etc/sudoers /etc/

This is where we hit the wall. The correct way(?) to do this is to add the line
youruser ALL=NOPASSWD: /sbin/shutdown
at the end of the sudoers file.

It worksfine if you start irexec manually from the terminal.
But after reboot and autostart shutdown does not work, everything else works fine.

I finally found a solution/ workaround.
%admin ALL=NOPASSWD: /sbin/shutdown

I am aware this is not a good setup, but it will have to do for a while. Can anyone help?

If you find this guide helpful let me know. I would be willing to re-write it with some quality if anyone needs it.


  1. Hello,

    Thanks a lot for your tutorial. Anyway, my big problem is to make lirc/irexec work rather with hibernate than shutdown. My main issue here is that lirc & irexec are not restored properly.

    Any ideas on that?

    thank a lot

  2. I have seen this problem in many threads in Ubuntu and xbmc center, can't find a good answer right now though. I have not tested my self yet.

    The computer does wake on USB already?

    If so you need to create a on resume script and re-initiate the necessary processes in it.

    There is several examples how to restart lirc I found this one:

    # Stops and unloads the current lirc module before suspending, and
    # restarts lirc when resuming

    AddSuspendHook 30 UnloadLirc
    AddResumeHook 30 StartLirc

    UnloadLirc() {
    /etc/init.d/lirc stop
    if [ -f /etc/lirc/hardware.conf ];then
    . /etc/lirc/hardware.conf
    rmmod $MODULES

    StartLirc() {
    /etc/init.d/lirc start

    If that fix the problem we need to find the right place to put the script.

    This is where I would start, I am not sure if it will work though. I had to test a lot of different solution before I got suspend to work,

  3. Thanks a lot for your suggestions. I took a quick look at the link you mentioned, I'll have to read it more carefully.
    To answer to your questions:
    - I don't need wake on USB, because the remote/LCD module has a special power cable plugged on the mainboard - so I don't need anything else for waking the PC up;
    - my main problem is that this remote/LCD (soundgraph imon) needs two instances of lircd hooked to two devices: /dev/lirc0 & /dev/lirc1, so sometimes only one is restored (without adding anything in the suspend/resume scripts). The irexec is not restarted at all.

    And one more question : what is this "AddSuspendHook" you (and the wiki page) mentioned ? I really cannot understand what it is and what areits parameters?

    Thanks a lot for your kind help.

  4. I don't know. I found the script on the page I refer to. I have mostly read up on irexec since I had no problem with lirc. So, far. I haven't tried suspend/ resume yet. For the moment I want to test the new xbmc with a separate xsession before I do anything more on lirc.

  5. There is now a new thread dea1ing with this. Hopefully they will get a clear answer:

  6. hi,

    thanks a lot for the link. I'll keep an eye on it, it still doesn't answer to all my problems.
    Anyway, please keep me posted with any development on your side, if you don't mind.

    Thanks a bunch!

  7. For others looking for a solution that recovers from both a reboot, a standby/resume, as well as random irexec crashes (and works without relying on Gnome functionality), I think I've finally figured it out and posted the answer on my blog. I combed all of the common answers (this being one of the top Google responses), but couldn't find a solution that quite covered everything. Check it out and let me know if anyone has problems with the steps posted.