As @lenik's answer says, your TV needs to support CEC. I installed a compiled version of libcec which included the command line utility cec-client
from SourceForge using the following commands:
wget http://sourceforge.net/projects/selfprogramming/files/libCEC.deb/libcec_2.1.0-1_armhf.deb/download -O libcec_2.1.0-1_armhf.deb
sudo dpkg -i libcec_2.1.0-1_armhf.deb
UPDATE: 2017-02-27
The link above to SourceForge no longer exists. According to this article you can install cec-client
using the following command:
sudo apt-get install cec-utils
The rest of this answer should still be valid.
Here's a thread on raspberrypi.org that discusses using the cec-client
to issue commands.
The thread says that the following command successfully turned on a Samsung TV:
echo "on 0" | cec-client -s
The following commands change the source from TV Tuner to Raspi HDMI:
echo "as" | cec-client -s
or
echo "tx 1f 82 30 00" | cec-client -s
The following commands were unsuccessful in turning the TV off:
echo "tx 10 36" | cec-client -s
or
echo "standby 0" | cec-client -s
standby 0
DEBUG: [ 56474] << putting 'TV' (0) in standby mode
TRAFFIC: [ 56476] << 10:36
DEBUG: [ 56477] sending data: len = 1, payload = 10:36
DEBUG: [ 56538] received data: header:00020001 p0:00003610 p1:00000000 p2:00000000 p3:00000000 reason:1
DEBUG: [ 56539] command transmitted
DEBUG: [ 56660] received data: header:00040002 p0:04360001 p1:00000000 p2:00000000 p3:00000000 reason:2
TRAFFIC: [ 56661] >> 01:00:36:04
NOTICE: [ 56661] >> TV (0) -> Recorder 1 (1): feature abort ( 0)
DEBUG: [ 56661] marking opcode 'standby' as unsupported feature for device 'TV'
echo "standby 0" | cec-client -s
works fine for my Panasonic TV, although the process stalls after, and I had tokill -9
it. – Sparhawk Jul 07 '14 at 00:16cec-client
– HeatfanJohn Feb 27 '17 at 20:59