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).
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.
#!/usr/bin/python import RPi.GPIO as GPIO import time import subprocess GPIO.setmode(GPIO.BOARD) # 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 time.sleep(.5)
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.