Turning your TV on or off using the Pi

For this example, we are relying on a technology called Consumer Electronics Control (CEC), which is a feature of the HDMI standard to send control messages to your home electronics equipment.

To help us send these messages, we'll need a software package called libCEC. While previously we had to build the libCEC package ourselves, we can now download a version for Raspbian Jessie using the installer:

pi@raspberrypi ~ $ sudo apt-get install libcec3 cec-utils

We will be using a utility called cec-client to send CEC messages to the TV. Issue the following command to switch off your TV:

pi@raspberrypi ~ $ echo "standby 0" | cec-client -d 1 -s

Use the following command to turn your TV on again:

pi@raspberrypi ~ ...

Get Raspberry Pi for Secret Agents - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.