Making A Home Entertainment Machine with A Remote (Part 1)

In "honor" of Intellectual Property Day, here's how you can more easily play all your media (regardless of origin) without having to get up off the couch. This is Part 1 in the series because there are some nagging things that I've yet to overcome, like the YouTube addon for Kodi needing its own API key but this will do it for 90% of your use cases.

What you'll need

Environment Preparation

Plug in your keyboard and mouse and then install your distro of choice. The details during installation don't matter much aside from one option. If you tell the installer to log in automatically, you can save yourself some trouble later on, but this will be a security risk if you're allowing the box to connect to the internet and you have other people in the house. If you change your mind later, there are instructions on how to change this in the Using Only The Remote section.

Once installation is finished, go install drivers and codecs you'll need. On Ubuntu and others, there's the Additional Drivers application that will find most of your drivers for you. You can install restricted codes by opening a terminal and running the command sudo apt-get install ubuntu-restricted-extras.

Now install Kodi. This is going to be your TV UI to watch your movies and shows, and listen to music. You can do this by running the command sudo apt-get install kodi.

Installing The Receiver

Now it's time to install the IR receiver. If it's external, just plug it in facing wherever you'll be sitting. IR receivers only work within line of sight and distance depends on the remote and the batteries in it. If it's internal, it's time to pop the computer open. If your IR receiver is external, you can skip to the next section.

Since you didn't skip down, your IR receiver must be internal. Turn the computer off, unplug it, and open up the side of the case. Check the documentation for your receiver for exact details, but at least one of the cables will plug into one of the USB headers on your motherboard. Once everything's plugged in, attach the receiver to either the outside of the case or a case window. There's no way the signal's going through metal.

Checking The Remote

Turn the computer back on. Once you're back to a desktop, we're going to be spending a lot of time in the terminal, so open it up.

First thing is to find your receiver, so run the command lsusb. If you don't see your receiver on that list, that either means the system doesn't recognize it or it's not installed properly. Recheck your installation and then do some pointed searches to see what's up between your receiver and your particular distro.

If your receiver is found, the next step is to see if your remote is recognized correctly. Point your remote at the receiver, and start hitting buttons.

If things happen on the screen, then your receiver has some idea of what the buttons on the remote already mean. This is a good thing! Go to Kodi and see if your remote works well there. If it does, jump down to Using Only The Remote!

If things don't happen or things didn't happen the way you'd like, then it's time to program the receiver to translate the codes that the remote is transmitting.

Programming The Receiver

In order to program the receiver, we need a program called ir-keytable. This will read the codes from the receiver and turn them into keys that Kodi can then use. First thing is to install it with sudo apt-get install ir-keytable.

Now we get to the tedious task of reading all of the codes from the remote. Grab a pen and multiple sheets of paper and go back to the computer. Run the command sudo ir-keytable -c -p all -t, aim the remote at the receiver, and then hit a button. A code will appear on the terminal that looks like this: 76293.151321 lirc protocol(nec): scancode = 0x4001

Worry not, you haven't stepped into another dimension. It means the remote uses the nec protocol and the scancode for the button you just pressed on the remote is 0x4001. Don't worry if it says "repeat" on the end. It just means you held the button down long enough for the code to get sent again. If you're getting garbage instead, it's possible that the receiver doesn't support that remote, in which case you'll need to use another remote.

Now go through every button on the remote and write down the button you pressed and the code that appears when you press it. If you get a scancode that looks like 0x6fffffff or 0x7fffffff, that's an error. Make sure the remote is close to the receiver, aimed right at it (not on a weird angle), and try again.

This is all going to go into a specially formatted TOML file that maps all of these scancodes to keys in Linux.

Building and Loading The Translation File

Now that we have all of the scancodes, it's time to build the TOML file! Below is the TOML file I created for my remote, a Toshiba CT-90325, that you can use as a guide. Make sure the name field is unique and each scan code is only in there once! There are better instructions on how to create this file by running the command man rc_keymap. If you need more keys to map to your scancodes, or these don't quite fit, a full list of keys is available at

name = "toshiba_ct_90325"
protocol = "nec"
variant = "nec"
0x4012 = "KEY_POWER2"
0x4080 = "KEY_MENU"
0x4057 = "KEY_SUBTITLE"
0x4001 = "KEY_NUMERIC_1"
0x4002 = "KEY_NUMERIC_2"
0x4003 = "KEY_NUMERIC_3"
0x4004 = "KEY_NUMERIC_4"
0x4005 = "KEY_NUMERIC_5"
0x4006 = "KEY_NUMERIC_6"
0x4007 = "KEY_NUMERIC_7"
0x4008 = "KEY_NUMERIC_8"
0x4009 = "KEY_NUMERIC_9"
0x4000 = "KEY_NUMERIC_0"
0x400f = "KEY_MODE"
0x4082 = "KEY_UP"
0x401d = "KEY_LEFT"
0x4089 = "KEY_OK"
0x4019 = "KEY_RIGHT"
0x4083 = "KEY_DOWN"
0x4084 = "KEY_INFO"
0x401a = "KEY_VOLUMEUP"
0x4030 = "KEY_PLAY"
0x4010 = "KEY_MUTE"
0x401b = "KEY_CHANNELUP"
0x4031 = "KEY_STOP"
0x4035 = "KEY_PAUSE"
0x4034 = "KEY_REWIND"
0x4036 = "KEY_NEXT"
0x4037 = "KEY_PREVIOUS"
0x4058 = "KEY_EXIT"
0x4015 = "KEY_SLEEP"

Save the file with a unique name ending in .toml and go back to the terminal. Load it into the receiver by running the command sudo ir-keytable -w (location of your .toml file)

Go back to Kodi and test out the mappings. If everything is to your liking then you're good, otherwise update your TOML file and reload it.

Using Only The Remote

In order to only have to use the remote, you'll need to set Kodi to launch on startup, disable your screensaver, disable any power options that cause the computer to go into sleep/suspend (unless your receiver can wake the computer back up), disable any locking, and set the computer to automatically log in on boot. All of this is highly dependent on your desktop environment.

For XFCE, disable the screensaver and lock screen on the Screensaver Settings window. You also need to disable password entry on resume, so go to Users and Groups, select the user you'll be logging in as, and click Change... next to Password. Check the box marked "Don't ask for password on login" and click Ok.

Disable sleeping on the System tab of Power Manager by setting "When inactive for" to Never and uncheck "Lock screen when system is going to sleep".

Set Kodi to launch on startup by going to Session and Startup, clicking the Application Autostart tab, and then clicking the + button. A window will appear. Name it whatever you like, the Command will be "kodi" without the quotes, and Trigger will be "on login".

In order to tell XFCE to log in as someone on boot, you have to create a config file for that. Create a new file in /etc/lightdm/lightdm.conf.d with a name ending in .conf. Put in the following, of course replacing YourDesiredAutoLoginUserName with whatever username you'll be automatically logging in as:


After you remove the keyboard and restart, your computer will start yelling on boot that it has an error and refuse to continue. You can turn this off in your BIOS.

And that should be it! Enjoy your new home entertainment PC!

Day 13 of #100DaysToOffload

Tags: Technology Kodi Linux