cec-client (libcec の一部) の助けを借りて、Raspberry Pi は B. HDMI 経由で接続された TV などの CEC をサポートするデバイスを制御できます。テレビのオン/オフ、アクティブなソースの切り替えなどを行うことができます。
これは、オリジナルの Raspberry Pi と最新の Raspberry Pi 4 を含む、すべての Raspberry Pi バージョンまたはモデルで動作するはずです。
考えられるユースケースは、SSH 経由で Raspberry Pi に接続し、それに接続されているテレビを HDMI-CEC 経由でオンまたはオフに切り替えるコマンドを送信することです。または、コマンドを使用してテレビの電源を入れ、CEC アダプターを Raspberry Pi HDMI ソースのアクティブなソースにすることもできます。 他にもさまざまなユースケースが考えられると思います。
CHECK、または Consumer Electronics Control は、HDMI 経由で接続されたデバイスをリモコンで制御できるようにする HDMI 機能です。たとえば、CEC は、リモコンの再生/一時停止ボタンを使用して、HDMI 経由で接続されたデバイスの再生を制御するために使用されます。または、テレビがオフのときに Chromecast でビデオを再生すると、テレビが自動的にオンになり、Chromecast ソースに切り替わります。
最近のほとんどのテレビと AV レシーバーは、HDMI-CEC をサポートする必要があります。ただし、一部のモデルでは、TV 設定で CEC を有効にする必要がある場合があります。 CEC は、デバイスのブランドによって異なる名前を持つことができます。たとえば、Samsung テレビの場合は Anynet +、Philips の場合は EasyLink または Fun-Link、LG の場合は SimpLink などと呼ばれます。
HDMI 経由で Raspberry Pi に接続されている場合、最初のステップは cec-client をインストールすることです。 Raspbian または Raspberry Pi 用のその他の Debian または Ubuntu ベースの Linux ディストリビューションで、その cec-utils
をインストールします。 パッケージ (cec-client
はこのパッケージの一部です):
sudo apt install cec-utils
他の Linux ディストリビューションでは、cec-client
を探す必要があります。 または cec-utils
リポジトリで、またはソースから libcec をビルドします。
その cec-utils
インストールしたら、CEC バスをスキャンして利用可能なデバイスを探しましょう:
echo 'scan' | cec-client -s -d 1
このコマンドで echo 'scan'
スキャン コマンドを cec-client -s
に送信します。 cec-client が単一のコマンドを実行して存在するために使用され、 -d 1
端末が無用な情報で汚染されないように、ログ レベルを 1 (エラーのみ) に設定します。
後で使用するので、テレビ (または HDMI-CEC 経由で Raspberry Pi に接続されているその他のデバイス) のデバイス番号とアドレスを書き留めておきます。
これは、HDMI 経由で Samsung TV (CEC サポートあり) に接続された Raspberry Pi でこのコマンドを実行する例です:
$ echo 'scan' | cec-client -s -d 1
opening a connection to the CEC adapter...
requesting CEC bus information ...
CEC bus information
===================
device #0: TV
address: 0.0.0.0
active source: no
vendor: Samsung
osd string: TV
CEC version: 1.4
power status: on
language: eng
device #1: Recorder 1
address: 1.0.0.0
active source: no
vendor: Pulse Eight
osd string: CECTester
CEC version: 1.4
power status: on
language: eng
currently active source: unknown (-1)
この例ではデバイス番号 0
0.0.0.0
で 住所は私の Samsung TV で、デバイス番号は 1
です 1.0.0.0
で アドレスは私の Raspberry Pi デバイスです。
デバイス番号とアドレスがわかったので、次のコマンドを使用して、HDMI-CEC 経由で Raspberry Pi に接続されているテレビの電源を入れます:
echo 'on <DEVICE #>' | cec-client -s -d 1
または:
echo 'on <DEVICE ADDRESS>' | cec-client -s -d 1
両方のデバイス番号 (0
上記の例では Samsung TV です) とデバイスアドレス (0.0.0.0
は、私の例の Samsung TV デバイスのアドレスです) が機能するはずです。
-d 1
ログ レベルをエラー時のみに維持することをお勧めします。これを使用せずにコマンドを使用できますが、おそらく役に立たない長いログが表示されます。
例:
echo 'on 0' | cec-client -s -d 1
または:
echo 'on 0.0.0.0' | cec-client -s -d 1
あなたもそれを望んでいる as
CEC アダプタをアクティブ ソースにするコマンド (したがって、テレビの電源を入れた後、テレビは Raspberry Pi HDMI ソースに切り替わります):
echo 'as' | cec-client -s -d 1
テレビの電源を切りますか (スタンバイ モードに切り替えますか)?使用:
echo 'standby <DEVICE #>' | cec-client -s -d 1
使い方によっては、テレビの現在の状態(オンかスタンバイか)も確認する必要があります。これは以下で可能です:
echo 'pow <DEVICE #>' | cec-client -s -d 1
cec-client が HDMI-CEC 経由で接続されたデバイスに送信できるすべてのコマンドを表示するには、echo h | cec-client -s -d 1
を使用します。 :
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.