Using System LEDs for Recording Status

From MythTV Official Wiki
Jump to: navigation, search

How To Use Your Case's Power LED and HDD LED to see if your Myth is recording

I don't personally care to have the Power LED or the HDD LED reflect system power or disc activity -- I figured it would be nice if these two LEDs showed me if my dual tuner MythTV box was recording (and specifically which tuner(s) were recording).

To do this I used

  • Python 2.3.3 (came with Redhat Fedora Core 2, but, any 2.2 or later Python should work) [1]
  • py Serial 2.1 [2]
  • A female db9 serial connector, preferably with wires connected to the pins
  • Some extra wire

On my system I ended up using COM1, my script reflects this.

The first thing you have to do is connect your serial port to the LEDs. To do this, cut the little back connector from the HDD LED wires and Power LED wires which normally you would connect to your motherboard. Strip the ends of the wires. Each wire pair will be some color and white. If you want this to be reversible don't cut the black thing off, just figure out a better way to connect the wires.

Next, focusing on the female DB9. If you face the connector toward you there are 9 holes, the pinout is

   5 4 3 2 1
    9 8 7 6

The pins we want to work with are 4 (DTR), 5 (Ground), and 7 (RTS).

You will now use your extra wire to connect 5 (Ground) to the two white cables coming from the case LEDs.

Next, connect 4 (DTR) to one of the colored cables. Optionally you could use a resistor in this connection, something like a 1000 ohm resistor from what I hear. I didn't do it and it didn't seem necessary, but, this maybe a good idea. These resistors are probably really cheap at Radio Shack.

Finally, connect 7 (RTS) to the other colored cable. Again, maybe a resistor.

I would recommend soldering and/or electrical taping all of the connections. Personally I have just twisted the wires together and electirical taped them, but, do what you like.

Note: I just ran the wires from the DB9 plugged into the serial port at back of the case through one of the PCI slot openings. You may have a better way to do it, I couldn't think of one.

Plug the DB9 into a serial port (preferably COM1).

Now for the Python script to monitor if you are recording (OR watching LiveTV, there is no real difference)...

My script was created as "/root/" and I made sure it had execute permissions.


import commands
import serial,time

#Open COM1
s = serial.Serial(0)
#Turn of all lights

   recording = commands.getoutput('/sbin/fuser /dev/video0 | grep -cv grep')
   if(recording == "1"):
   recording = commands.getoutput('/sbin/fuser /dev/video1 | grep -cv grep')
   if(recording == "1"):
   #Sleep for a minute

As this script only checks for recording status of the two tuners once a minute, I believe it should add very low overhead. If you want the check to occur more or less often just adjust the time.sleep(60) statement to meet your needs.

Assuming you wired the cable to the LEDs correctly, you are plugged into COM1, and do have two tuners on /dev/video0 and /dev/video1 this script should run fine for you. The last bit to do is to make it being execution on system startup. To do this (using Redhat) I added a line to my "/etc/rc.d/rc.local"

/root/ &

Enjoy! Kevin C. Dorff [3]

Special thanks to Travis Kelley for posting the `fuser ...` stuff to the MythTV mailing list so I knew how to see if /dev/video0 or /dev/video1 was recording.

    • This nice script has the one slight problem, it is unable to differentiate between a 'live tv' display and a 'recording' display.

You should be able to do this. Try this instead: ls -l /proc/`fuser /dev/video0 | awk '{print $2}'`/fd/ 2>&1 | grep nuv$

This tells you if the process that is using /dev/video0, also has a file handle open to a file that ends in nuv. Give this a try and integrate into your script.

Scott Carlson

As someone pointed out on the mailing list -- another extremely low-tech way to do this, at least on a combined frontend/backend box, is to hook up a hard disk activity LED ;) -- Justin Mason