3

My master plan is to be able to send CEC commands from my pi running raspbmc to do things such as turn on/off the tv as well as other devices connected to the TV. Then I will be adding voice recognition to send these commands...that's for another day. I have read up on CEC but from what I've gathered it seems like you can't send CEC commands directly through the command line without the CEC usb adapter? I have installed the cec-client and libCEC library on my pi but when I run cec-client -l it shows no devices.

My question is, how can I send CEC commands via the command line to my tv from the pi without the adapter? Am I missing some basic element about CEC?

4 Answers 4

4

You can use single-command mode like this: echo "standby 0" | cec-client -s (for power off TV) echo "on 0" | cec-client -s (for power on TV)

1
  • Forgot this question out there. Yes, that is the command I needed to. I added some other commands to my .bashrc if anyone else finds them useful is another post below
    – Austin
    Dec 1, 2013 at 12:48
1

It's possible that the installation of the cec-client and libCEC library didn't work. Unfortunately I don't know what might have gone wrong, but I've installed both on my system. I see the following output when I list devices:

me@raspberrypi ~/libcec-release $ cec-client -l
Found devices: 1

device:              1
com port:            RPI
vendor id:           2708
product id:          1001
firmware version:    1
type:                Raspberry Pi

I compiled libCEC on the Raspberry Pi, which you can see here:

me@raspberrypi ~/libcec-release $ cec-client -i libCEC version: 2.1.1, host: armv6l-unknown-linux-gnueabihf, features: 'P8 USB' 'P8 USB detect' 'RPi', compiled on: Wed Apr 24 21:12:36 UTC 2013 by me@raspberrypi on Linux 3.2.27+ (armv6l)

Now if I start 'cec-client' from the command line, I will see it output information when I press the "Play", "Stop", "Pause", etc. buttons on the television remote control. So from that perspective, the system is working.

I'm not sure if you can send commands from the RPi to the television, but if you figure out how to do it I would love to know! :)

P.S. I unplugged the HDMI cable from the television and ran 'cec-client -l' again. It reported the same information, so the television doesn't seem to matter.

0

As @Michael first posted the correct way to control the power for the TV, this is my bashrc of commands to control my TV via command line.

# CEC Stuff
alias tvon="echo 'on 0' | cec-client -s"    
alias tvoff="echo 'standby 0' | cec-client -s"

# Change TV input to HDMI2 or HDMI3
alias tv3="echo 'tx 4f 82 30 00' | cec-client -s"    
alias tv2="echo 'tx 4f 82 20 00' | cec-client -s"
0

Like other answers point out, you can pipe commands to the cec-client binary, for example

echo "on 0"      | cec-client -s # turn on the television
echo "standby 0" | cec-client -s # turn it off (standby)

Check all available CEC commands with

tv# echo h | cec-client -s -d 1
opening a connection to the CEC adapter...

================================================================================
Available commands:

[tx] {bytes}              transfer bytes over the CEC line.
[txn] {bytes}             transfer bytes but don't wait for transmission ACK.
[on] {address}            power on the device with the given logical address.
[standby] {address}       put the device with the given address in standby mode.
[la] {logical address}    change the logical address of the CEC adapter.
[p] {device} {port}       change the HDMI port number of the CEC adapter.
[pa] {physical address}   change the physical address of the CEC adapter.
[as]                      make the CEC adapter the active source.
[is]                      mark the CEC adapter as inactive source.
[osd] {addr} {string}     set OSD message on the specified device.
[ver] {addr}              get the CEC version of the specified device.
[ven] {addr}              get the vendor ID of the specified device.
[lang] {addr}             get the menu language of the specified device.
[pow] {addr}              get the power status of the specified device.
[name] {addr}             get the OSD name of the specified device.
[poll] {addr}             poll the specified device.
[lad]                     lists active devices on the bus
[ad] {addr}               checks whether the specified device is active.
[at] {type}               checks whether the specified device type is active.
[sp] {addr}               makes the specified physical address active.
[spl] {addr}              makes the specified logical address active.
[volup]                   send a volume up command to the amp if present
[voldown]                 send a volume down command to the amp if present
[mute]                    send a mute/unmute command to the amp if present
[self]                    show the list of addresses controlled by libCEC
[scan]                    scan the CEC bus and display device info
[mon] {1|0}               enable or disable CEC bus monitoring.
[log] {1 - 31}            change the log level. see cectypes.h for values.
[ping]                    send a ping command to the CEC adapter.
[bl]                      to let the adapter enter the bootloader, to upgrade
                          the flash rom.
[r]                       reconnect to the CEC adapter.
[h] or [help]             show this help.
[q] or [quit]             to quit the CEC test client and switch off all
                          connected CEC devices.
================================================================================

Extracted from

https://ownyourbits.com/2017/02/02/control-your-raspberry-pi-with-your-tv-remote/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.