Monday, November 3, 2014

Shutdown XBMC (and TV) using command line

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"

sudo halt

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.
After some small research I solved the last problem using the following command to shutdown my RPi:

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.

3 comments:

  1. Nice tutorial! Is it possible to shutdown XBMC via WhatsApp too?

    ReplyDelete
  2. Yes it can be done and actually i'm doing it at home.
    I put the last two commands above in a shell script and execute it when whatsapp receives the right text. If whatsapp and xbmc are in the same raspberry there is no problem. If they are in different rpi then the shell script has to be in the xbmc rpi and the other rpi can execute it by ssh.
    The next post of the blog will be about this topic. Just few days and it will be online!

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete