Today I will show You how to turn off your TV and XBMC using just command line.
You could ask why someone may wish to use command line for this task that can be easily performed with remotes.
Well, this will be quite useful if You wish to turn XBMC off from another computer using an SSH connection.
I have RaspBMC installed on one Raspberry (model B) and on another one (model A) I'm trying to make some automation. Just by sending a Whatsapp message I'm able to suhtdown RaspBMC and turn off my TV.
This is just a part of the automation involving my home theatre that (maybe one day...) will include much more.
Before going on, just one note: these commands should work on most of the unix-based XBMC installations but to turn off Your TV it must be connected using HDMI and all the system (TV, cable and XBMC hardware) should be CEC compliant.
Let's see which steps I did... First of all the easiest part: turn off XBMC. The command is quite simple and can also be found in the XBMC website.
sudo initctl stop xbmc
This stops XBMC, but does nothing more than this. The interesting thing is that You can start XBMC again just by typing
sudo initctl start xbmc
Anyway this is not what I needed. TV stays on and RPi is still active.
Next thing I tried is the "classic"
Now RPi stops, but TV stays still on. Another issue is that sending this as an SSH command (so not on an interactive session) nothing happens.
sudo /sbin/shutdown -hP now
Now it's just missing a way to turn off the TV. Again internet is a really good friend and I found a nice command to accomplish the task:
echo "standby 0" | /opt/xbmc-bcm/xbmc-bin/bin/cec-client -s
As stated before, all the system must be CEC compliant, so the libraries have to be installed in the system. RaspBMC (but also OpenElec) should have these library already installed, so no problem here.
For an easier shutdown i just created a small script in my RaspBMC with the two commands (CEC command must be the first one), so I can now shutdown the system with just one SSH request when needed.