Raspbmc: Turn XBMC On or Off (inc. HDMI Out) from SSH

Why would you want to do this?

I use my RPi for XBMC and as a web server (yet to reinstall after switching to Raspbmc). I do not always want XBMC running, as I am not always home and also not always watching films! So in the interests of saving system resources I wanted to stop XBMC and shut off the HDMI to stop any TV interference. There are two commands to do this, but they are quite long and not easy to remember! I needed something to shorten this process. Preferably xbmc start/stop.

This is how I implemented it.

When you have SSH’ed into your Raspbmc box, we are going to add a custom command to the .bashrc file. This controlled the shell environment, and allows you to create custom commands to call from the command line.

Step 1: Edit ~/.bashrc file.

~$ sudo nano ~/.bashrc

when you are here, use ctrl+v to page down to the bottom of the file. (of course, you can use vi).

Add the following code to the bottom of the file:

xbmc (){
if [ $* = "start" ] ; then
/opt/vc/bin/tvservice -p
sudo initctl start xbmc
fi
if [ $* = "stop" ] ; then
sudo initctl stop xbmc
/opt/vc/bin/tvservice -o
fi
}

press ctrl+o; ctrl+x to save and exit the file.

If you want to control HTML only, remove the BLUE lines from the above code and change the function name to hdmi. 

Step 2:

Restart bash without restarting the session.

~$ source ~./bashrc

Step 3:

Type the following command to test it works:

~$ xbmc stop

You should now see XBMC shutdown and the TV / Monitor report no source input. However, notice you are still logged into the session and the Pi is still on.

To start xbmc and the hdmi out use xbmc start, to stop the service use xbmc stop.

You can also hack a function to turn on the HDMI port if you want, just omit the XBMC stuff, call it hdmi () and use on/off!

Leave a comment if you have tried this and it worked, or AMA. I couldn’t find this anywhere else on the net to I thought I would post it.

12 thoughts on “Raspbmc: Turn XBMC On or Off (inc. HDMI Out) from SSH”

  1. Enbable/disable hdmi function
    hdmi (){
    if [ $* = "on" ] ; then
    /opt/vc/bin/tvservice -p
    sudo initctl start
    fi
    if [ $* = "off" ] ; then
    sudo initctl stop
    /opt/vc/bin/tvservice -o
    fi
    }

    ¿Is that right?

    This is my output:
    root@raspbmc:/home/pi# hdmi off
    initctl: missing job name
    Try `initctl –help’ for more information.
    Powering off HDMI
    root@raspbmc:/home/pi# hdmi on
    Powering on HDMI with preferred settings
    initctl: missing job name
    Try `initctl –help’ for more information.

    Thanks, this post is very useful, Im new on unix systems.

    1. I see what your trying to do here. If you want to turn XBMC on or off as well as the post describes then you need to include “start xbmc” after sudo initctl (so “sudo initctl start xvmc”).

      If you just want to control the HDMI which your command name suggests, remove the sudo initctl line all together. You should be good to go!

  2. Thanks for sharing this! I was stuck in a loop caused by a scraper that couldn’t identify an artist, and using this I was able to restart the xbmc without pulling the power.

  3. Thanks for your post. xbmc start and xbmc stop work for me like a charm, but if I run hdmi off and afterwards hdmi on (without stopping and restarting xbmc),
    the screen went on, but nothing is displayed. Seems like XBMC isn’t told about the hdmi switching on again.

  4. In raspbmc and raspbian the command “/opt/vc/tvservice -o does turn hdmi off as expected, and “/opt/vc/tvservice -p” will turn hdmi back on, but the screen will remain blank. In raspbian, entering “sudo chvt 6″ then “sudo chvt 7″ from the command line will cause the screen to return to normal. This doesn’t work in raspbmc. I’ve tried “fbset -depth 8; fbset -depth 16″ without success as well. I wonder what happens in the xbmc startup sequence that resolves this?

    1. I believe there would be no straightforward way of doing this, without attaching an IR sender to the Pi, encoding it with your TV’s signal code, and sending the power off that way!

  5. what about starting and stopping a slideshow that’s running from an SMB share automatically?

    So, XBMC is running and the slideshow stops working for whatever reason. Need to reboot the RPi and automatically connect to the SMB share and play a slideshow of pictures in the SMB share.

    I’d also like to set a time on the HDMI output to turn off/on at specific times of the day.

    Thanks in advance!

Leave a Reply