Answers:
正如@lenik的回答所说,您的电视需要支持CEC。我安装其中包括命令行实用程序libcec的编译版本cec-client
从SourceForge上使用下列命令:
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
更新时间:2017-02-27
到SourceForge的上方链接不再存在。根据本文,您可以cec-client
使用以下命令进行安装:
sudo apt-get install cec-utils
此答案的其余部分仍然应该有效。
这里有一个线程raspberrypi.org,使用讨论cec-client
发出命令。
echo "on 0" | cec-client -s
echo "as" | cec-client -s
要么
echo "tx 1f 82 30 00" | cec-client -s
echo "tx 10 36" | cec-client -s
要么
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'
cec-client
您需要一台通过HDMI 支持CEC(消费者电子控制)协议的电视机。最好查阅您的电视手册或公司网站,以找到有关您特定情况的详细信息,也可以快速搜索“ TV_model + CEC”,这将为您提供一些指导。
基本上,如果您的电视机是几年前生产的,则很有可能会找到如何设置和启用CEC的机会,但是对于较旧的型号,机会就不太好了。
三星CEC实施称为Anynet+
,您也可以尝试搜索。
您可以制作带有IR LED的电视遥控器。有一个关于Adafruit的教程,介绍您想做什么。这是关于同一主题的另一篇博客文章。
注意:您将必须使用GPIO引脚。我不确定您是否正在寻找使用它们的解决方案。
按照HeatfanJohn的上述回答安装cec-client后,我就能够成功打开/关闭Vizio E390i-A1 LED HDTV的电源。我为社区编写了一个脚本:
通过以下方式创建新文件:
mkdir /opt/scripts; vi /opt/scripts/turntv.sh
粘贴以下内容:
#!/bin/bash
#Written by CaptainRewind for the RaspberryPi community
#Modify as needed
#Updated 2014-01-22:
#Now includes full path to cec-client (for cron purposes)
#Also includes "input" command to switch TV Input to RaspberryPi
action=${1}
cecBin="/usr/local/bin/cec-client"
onCommand='echo "on 0" | ${cecBin} -s'
offCommand='echo "standby 0" | ${cecBin} -s'
inputCommand='echo "as" | ${cecBin} -s'
do_on()
{
eval ${onCommand} > /dev/null 2>&1
}
do_off()
{
eval ${offCommand} > /dev/null 2>&1
}
do_input()
{
eval ${inputCommand} > /dev/null 2>&1
}
case ${action} in
on)
do_on
exit 0
;;
off)
do_off
exit 0
;;
input)
do_input
exit 0
;;
*)
echo $"Usage: $0 {on|off|input}"
exit 1
;;
esac
使它可执行:
sudo chmod +x /opt/scripts/turntv.sh
然后,创建别名:
vi /home/pi/.bashrc
添加以下内容:
alias tvon="/opt/scripts/turntv.sh on"
alias tvoff="/opt/scripts/turntv.sh off"
alias input="/opt/scripts/turntv.sh input"
保存,退出,注销/登录(或仅获取.bashrc的源代码)。现在,您可以使用“ tvon”和“ tvoff”打开或关闭电视。
现在,您可以安排一项夜间工作,以防万一您入睡时关闭电视:
crontab -e
添加以下内容:
00 03 * * * /opt/scripts/turntv.sh off
我还写了一些脚本来帮助解决这个问题。尽管他做得很好,但我比CaptainRewind走得更远。这只是编写用来控制电视的Shell脚本,所以我没有包含它不支持的任何内容(例如音量和频道控制;我仍在寻找一种无需购买任何额外设备即可完成上述任何一项操作的方法)硬件),并且包含特定于安装程序的详细信息,例如“电视输入raspi”与“电视输入3”同义,但是我将其保留了下来,以便您可以自己了解如何进行此类自定义。
您可以轻松使用它。如果通过发出诸如“ tv on”,“ tv off”或“ tv input 1”之类的命令将其放在/ usr / local / bin / tv上,或者可以将其作为TV放在主目录中即可。 sh并直接从那里使用。
我希望这对某些人有帮助。
#!/bin/bash
# must be called with a parameter
# tv.sh [command]
# will send the associated command to the TV over CEC.
if [ $# -lt 1 ] #Check to see if at least one parameter was supplied
then
echo "Must be called with the command to send to the television"
echo "Examples include on, off, and input."
echo "example: " $0 "input PC" # $0 is the name of the program
echo "For help, use: " $0 " -? "
exit 1
fi
case $1 in
"-?") echo "Supported commands include: on, off, status, as,"
echo "input [source]" ;;
## begin list of commands.
## most of these came from http://www.cec-o-matic.com/
## more can be added, including proprietary commands.
"on") echo "on 0" | cec-client -s ;;
"off") echo "standby 0" | cec-client -s ;;
"status") echo "pow 0" | cec-client -s |grep "power status:" ;;
"as") echo "as" | cec-client -s ;;
"input")
if [ $# -ge 2 ] # if there were 2 or more parameters
then
case $2 in # check the second one
# NOTE: These must all be broadcast to work. (2nd nibble must be F)
"1") echo "tx 1F 82 10 00" | cec-client -s ;;
"bluray") echo "tx 1F 82 10 00" | cec-client -s ;; # same as 1
"2") echo "tx 1F 82 20 00" | cec-client -s ;;
"3") echo "tx 1F 82 30 00" | cec-client -s ;;
"pc") echo "tx 1F 82 30 00" | cec-client -s ;; # same as 3
"raspi") echo "tx 1F 82 30 00" | cec-client -s ;; # same as 3
"4") echo "tx 1F 82 40 00" | cec-client -s ;;
esac
else
echo "input needs a second parameter"
echo "usage: " $0 " input [input name]"
echo "input name is 1-4, bluray, pc, or raspi"
fi
;; # end of the input case
*) echo $1 "is not a recognized parameter. " $0 " -? for a list." ;;
esac
exit 0
您可能想重试最新版本的XBMC(现在称为Kodi'),最好用Samsung UE46F6500电视和OpenELEC(官方)版本:Kodi 5.95.3,尽管在放完电视后CEC控件丢失了待机或再次打开电视:
支持:
回声“待机0” | cec客户端-s
上:
回显“ 0” | cec客户端-s
变更来源:
回声“ as” | cec客户端-s
但是,这些功能使Kodi可以独占控制CEC界面,因此在这些命令中的任何一条之后,Kodi都将失去CEC控制,并且遥控器将停止工作。您需要重新启动Kodi才能使其再次运行:
systemctl重新启动kodi
Kodi(> = 13)具有内置功能CECToggleState,CECActivateSource,CECStandby。有人正在使用这些内置功能通过python传递这些cec命令,或者正在寻找以共享模式打开cec硬件的可能性:http://forum.kodi.tv/showthread.php?tid=207524和https://discourse.osmc.tv/t/control-tv-on-standby-toggle-using-cec-kodi-built-in-功能/ 3638/4
echo "standby 0" | cec-client -s
在我的Panasonic TV上运行良好,尽管此过程在此之后停滞了,我不得不这样kill -9
做。