Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending CEC commands via command line over HDMI

My master plan is to be able to send CEC commands from my raspberry pi 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?

UPDATE

In addition to the posts below here is a link that asked in the PI portion of stackoverflow which has some more CEC commands that I have put within my .bashrc to turn the tv on/off and change the input

https://raspberrypi.stackexchange.com/questions/5345/raspmbc-send-cec-commands-without-cec-adapter

like image 318
Austin Avatar asked Mar 09 '13 20:03

Austin


2 Answers

You can pipe commands to the cec-client binary

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

For completeness, these are some other things that you can do

List connected devices

tv# cec-client -l
libCEC version: 3.1.0, git revision: libcec-3.1.0+5-6d68d21, compiled on Fri  8 Apr 15:44:58 UTC 2016 by nacho@tv on Linux 4.1.19-v7+ (armv7l), features: P8_USB, DRM, P8_detect, randr, RPi
Found devices: 1

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

Check all available CEC commands

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/

like image 119
nachoparker Avatar answered Sep 21 '22 10:09

nachoparker


Recent versions of libcec will recognize the Raspberry Pi hardware as a CEC adapter.
To send control commands through the command line, basically:

echo "on 0" | cec-client -s

will power on device 0 (ie your TV)
Check out cec-client interactive shell for more complex commands

like image 31
Benjamin Avatar answered Sep 23 '22 10:09

Benjamin