Is it possible to detect when I turn on/off the TV? Unfortunately my TV does not support CEC, but I want to somehow stop the XBMC process when the TV is switched off (or uses a different source).

3 Answers 3


You could use the GPIO pins to attach some kind of sensor. I'm checking to see if my stereo is on, using just a simple LDR. I placed the LDR inside the SPDIF output of my stereo. If my stereo is on, the is light coming from the SPDIF, and the the LDR will pull the GPIO pin low. Works like a charm.

I found out that the LDR I used in combination with the build-in pull-up resistor inside the Pi's chip will result in a LOW if the stereo is on, and a HIGH if off.

So all I needed to do is connect one pin of the LDR to ground, and the other to one of the GPIO pins. No other components needed.

This is (part of) the script I use to control audio playback, only when the stereo is turned on.

import RPi.GPIO as GPIO
import time
import subprocess

# LDR (LOW if stereo on)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)

playing = -1
while True:
    ldrState = GPIO.input(7)

    if ldrState == False and playing != 1 :
        subprocess.call("mpc play", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        playing = 1

    if ldrState == True and playing != 0 :
        subprocess.call("mpc stop", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        playing = 0

  • Thanks for the idea, maybe I'll try this in the future, but for now it's enough for me to start/stop XBMC via SSH.
    – ofalvai
    Commented Jul 4, 2013 at 11:11

If your TV has a USB port, you could use a gpio pin to sense the voltage on the TV's USB power pins.

Remember to use a level shifter or opto-coupler because USB power will be 5 volts.


Sorry you cannot, unless you create some kind of hardware device, that watches if your TV is switched on or not by checking the current in the power cable or by looking at the screen through the web-cam, and write appropriate scripts to process the data and shutdown xbmc at the appropriate moment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.