Jordan's Space

Technology, music, fishkeeping, me.

ComputersHome AutomationLinux

Computer Monitor Roku: Remote Sound Control, Tripp-Lite UPS Power Switching.

This was a fun little project to turn my computer monitor into a TV with remote volume and power control, and play around with some cord cutting options in my bedroom. I was able to achieve the infrared control using an Iguana IR USB IR dongle, and ir-keytable / rc_keymaps.cfg, as well as the Roku remote.

LIRC isn’t even needed for the remote control driver layer anymore. I still use it, for things like irexec below, but, sitting on top of the the native linux RC Keymap feature, which lets you create keymaps directly directly to keys – basically making your remote act like an input device, like a keyboard. This has all sorts of cool implications, but for my purposes, I just want to map it to some standard buttons.

The first step is using “ir-keytable -t” and reading some keystrokes from the remote. Essentially, you just press some buttons and hopefully, if all works, you’ll get some hex numbers. You can then assign those to remote buttons in a custom keymaps file:

# cat /etc/rc_keymaps/roku
# table roku, type: NEC
0x4f5002 KEY_POWER

This also needs to be added to the /etc/rc_maps.cfg file, you can use a simple catch-all in most cases:

#driver table file
* * roku

If “ir-keytable -t” didn’t work, you may need to add some remote protocols to the list. At a high level – the event driver supports interpreting the IR protocols from various brands like NEC, Sony, JVC, RC-5, etc. NEC, Sony, and RC-5 are pretty common, so simply adding these to the list via something like “ir-keytable -p nec” and then re-trying the key-grabs is often all you need. This, and any other commands can be run automatically before LIRC starts by creating a systemd file:

$ cat /etc/systemd/system/lircd.service.d/override.conf
ExecStartPre=/usr/bin/ir-keytable -a /etc/rc_maps.cfg -p nec -D 700

Speaking of LIRC, you do need to have lirc compiled with the devinput driver in this particular setup case. If you were using it some other way, like with a native lirc driver, then you would start with configuring that instead of the ir-keytable stuff, but, this new style setup is definitely nicer and doesn’t require as much extra driver fun.

The volume control is easy enough from there – I simply use the line input on my sound card, and use irexec to control the volume levels via amixer. The amixer commands below are probably more complicated than usual in my case – this is due to my soundcard’s fancy mixing capabilities, I essentially have to control it as 2 mono devices. Most people can use much simpler amixer commands than mine:

prog = irexec
config = echo -e "set 'Monitor Mixer',0 1db+\nset 'Monitor Mixer',5 1db+" |amixer set -D mia -sq
repeat = 1

prog = irexec
config = echo -e "set 'Monitor Mixer',0 1db-\nset 'Monitor Mixer',5 1db-" |amixer set -D mia -sq
repeat = 1

The power control is where it gets fun. I wrote about my Tripplite Online UPS before and one of the cool things that they can do is load switching. They even have built in features to “ramp up” or “ramp down” loads based on remaining battery charge and things like that. For my purposes, I just wanted to manually switch it on and off.

The easiest way to do this for my purposes, is via the optional SNMPWebcard. It uses a horribly dated java interface, though it supports telnet and FTP firmware updates, which is convenient. First I usually update them to the latest firmware by following tripplite’s instruction. Once that’s done, it should support the latest tripplite MIB’s – which you can drop under ~/.snmp/mibs or the like. I then wrote a simple bash script to trigger the outlets via SNMP. My tripplite’s have 2 switchable banks, and this is switching bank 2 which is indicated by the last digit of all the OIDs “.2” you can likewise use “.1” to switch the first bank of my UPS. I also do some basic state tracking, which allows the script to act like a toggle if run with no arguments.

I’ve reached out to the NUT project as well, in hopes that this could some day be implemented as a “upscmd” or the like, as well. That would truly be ideal, but tracking state may still be needed for my purposes, as it seems the UPS cannot immediately respond to commands after processing a previous one, thus the 20 second delay I’ve added.

The last piece is the irexec for the toggle script,

button = KEY_POWER
prog = irexec
config = /home/xero/media/misc/scripts/

And that’s it! Now I can control volume and my monitor’s power via the roku remote! I should add, I did have to basically fake out the roku remote in order for it to configure itself as an IR device – basically told it I had some particular TV and once it was set to that – learned those codes.