当玩客云加上红外接收头,智能家居竟然如此好玩,小米华为同框了

大家知道今年我在玩客云玩转智能家居的道路上一意孤行地进行探索,陆续分享了玩客云安装智能家居平台homeassistant的教程,小米米家、涂鸦智能、博联等接入homeassistant的方法,还有给玩客云增加WiFi、蓝牙、zigbee扩展的玩法。今天要分享的这篇给玩客云增加红外接受头,算是补齐了常见的无线协议了,玩客云也将变得更加好玩了。先简单说一下玩客云增加红外接收头后有什么用。最重要的就是玩客云可以听懂红外遥控命令了,你可以用红外遥控器控制ha的任何品牌的任何智能家居,比如你可以用华为智慧屏、华为手机或智能音箱的小艺语音助手控制小米米家的智能家居了。直接视频看效果吧。

视频加载中...

动起手来,智能家居让生活更美好。


一、玩客云加装红外接收头

1、拆掉玩客云外壳,取出玩客云主板

玩客云拆解教程网上已经比较多了,我不赘述了,就是从SD卡那把薄片插进去开始撬开,就露出螺丝了。

2、焊接红外接收头

我从淘宝上买的VS1838B红外接收头,几毛钱一个,便宜的很

把红外接收头插到红外接收位置,在主板背部简单焊接一下就可以,


如果针脚粗的红外接收头,不焊接也可以。比如下面这种

3、为了把主板装到外壳里还能接收红外,需要把前面板黑色塑料挡板挖孔。

二、LIRC相关软件安装设置

安装lirc相关软件

apt-get install lirc liblircclient-dev

设置LIRC及驱动

nano /etc/lirc/lirc_options.conf

驱动和设备设置

driver          = default
device          = /dev/lirc0

内核模块初始化

[modinit]
code = /sbin/modprobe meson-ir

输入时间设置

[lircd-uinput]
add-release-events = True
release-timeout    = 50
release-suffix     = _EVUP

最后该文件如下

# These are the default options to lircd, if installed as
# /etc/lirc/lirc_options.conf. See the lircd(8) and lircmd(8)
# manpages for info on the different options.
#
# Some tools including mode2 and irw uses values such as
# driver, device, plugindir and loglevel as fallback values
# in not defined elsewhere.

[lircd]
nodaemon        = False
driver          = default
device          = /dev/lirc0
output          = /var/run/lirc/lircd
pidfile         = /var/run/lirc/lircd.pid
plugindir       = /usr/lib/aarch64-linux-gnu/lirc/plugins
permission      = 666
allow-simulate  = No
repeat-max      = 600
#effective-user =
#listen         = [address:]port
#connect        = host[:port]
#loglevel       = 6
#release        = true
#release_suffix = _EVUP
#logfile        = ...
#driver-options = ...

[lircmd]
uinput          = False
nodaemon        = False

[modinit]
# code = /usr/sbin/modprobe lirc_serial
# code1 = /usr/bin/setfacl -m g:lirc:rw /dev/uinput
# code2 = ...
code = /sbin/modprobe meson-ir

# [lircd-uinput]
# add-release-events = False
# release-timeout    = 200
# release-suffix     = _EVUP
[lircd-uinput]
add-release-events = True
release-timeout    = 50
release-suffix     = _EVUP

测试软件及硬件是否工作正常,输入以下命令,然后拿着遥控器对着红外接收头按下按键,如果工作正常,窗口会输入一串串数字,如下所示

mode2 -d /dev/lirc0
pulse 629
space 518
pulse 627
space 523
pulse 628
space 523
pulse 631
space 517
pulse 629

三、红外码配置与录制

1、直接查找

最简单的方法是去lirc红外码库找自己遥控器对应的配置文件,比如我家的LG电视遥控器是可以找到的。网址如下http://lirc.sourceforge.net/remotes/。

找到配置文件直接放置到/etc/lirc/lircd.conf.d/路径下就可以了

2、录制

找不到我们也可以自己录制

输入下面命令进行红外码获取

mode2 -m -d /dev/lirc0

此时按下华为遥看小苹果万能遥控器,获取的对应开灯的红外按键,其结果如下图所示

Using driver default on device /dev/lirc0
Trying device: /dev/lirc0
Using device: /dev/lirc0
Warning: Running as root.
 16660004

    61730-space

     9000     4460      600      520      600      530
      580      530      580      540      610      570
      560      550      610      530      590      520
      560     1690      580     1670      610     1660
      580     1660      590     1660      580     1670
      610     1710      580     1660      560     1690
      580     1670      600     1660      590      530
      580      530      610      530      590     1690
      560      550      610      530      570      540
      600      530      590     1660      640     1660
      580     1660      580      540      610     1660
      580   130400-pulse  1756003-space

然后把“9000” 到”580“之间这串数值进行复制,写入下面文件中,替换对应按键下的一串数字即可。

nano /etc/lirc/lircd.conf.d/myremote.lircd.conf

文件格式如下所示

begin remote
 #名字可以自己定义
  name  ykd2  
  flags RAW_CODES|CONST_LENGTH
  eps            30
  aeps          100
  gap          108265
      begin raw_codes
          name key_on
              8939     4516      585      545      568      589
               608     1684      567      545      577      537
               584      532      591      546      560      551
               572     1699      592     1675      568      544
               528     1717      589     1658      617     1674
               570     1675      569     1676      579     1674
               586      544      569      545      577      537
               583     1639      615      545      566      546
               581      551      577      542      567     1676
               577     1673      577     1707      591      545
               528     1717      580     1669      589     1675
               569

          name key_off
              3513     1665      526      329      529      324
               534     1252      517     1257      521      381
               528     1191      536      337      565      350
               541      330      548     1265      529      326
               534      388      512     1257      524      328
               528     1242      536      338      511     1202
               522      332      536      382      469     1252
               468      332      526      328      535      337
               512      336      474     1293      527     1247
               535     1203      516     1257      512      397
               547     1250      532      343      513      389
               512      337      516     1255      529     1242
               536      337      513      342      543     1169
               532      322      547      324      530

      end raw_codes
end remote

然后按CTRL + X ,再按下Y回车保存文件

测试

输入irw命令进行测试,看设备能否识别刚才录制的红外码,如果能识别,会显示码值、按键名和遥控器名。

service lircd restart
irw
0000000000000002 00 key_on ykd2
0000000000000002 00 key_on ykd2
0000000000000002 00 key_on ykd2

按同样的方式复制其他按键,到此完成遥控器的配置工作

三、写lircrc文件,串起LIRC和homeassistant

输入下面的命令

nano /etc/lirc/lircrc

写入内容如下所示,其中的remote即上一步中中遥控器配置文件中名字,button即上一步中的按键名字,该配置文件将起到把红外码传给homeassistant的桥梁作用

begin
    remote = ykd2
    button = key_on
    prog   = home-assistant
    config = key_on
end
begin
    remote = ykd2
    button = key_off
    prog   = home-assistant
    config = key_off
end

然后按CTRL + X ,再按下Y回车保存文件

四、homeassitant配置

1、添加LIRC组件

在ha配置文件中添加lirc组件,见第三行

# Loads default set of integrations. Do not remove.
default_config:
lirc:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

2、手动安装python-lirc==1.2.3

添加lirc组件重启ha后会提示”Unable to install package python-lirc==1.2.3“

我们需要进行如下操作来手动安装python-lirc==1.2.3

apt install -y git 
sudo -u ha -H -s
cd /srv/ha
source bin/activate
pip3 install cython
git clone https://ghproxy.com/https://github.com/tompreston/python-lirc.git
find python-lirc -name '*.pyx' -exec cython {} \;
pip3 install python-lirc/

安装完成重启ha不再报警

3、编写自动化

打开ha自动化文件,添加如下内容,将实现ha接收到打开灯的红外码时打开对应的灯,接收到关闭灯的红外码时关闭灯。

- id: '1656854309098'
  alias: 打开网关灯
  description: ''
  trigger:
  - platform: event
    event_type: ir_command_received
    event_data:
        button_name: key_on
  condition: []
  action:
  - type: turn_on
    device_id: cad9ce32e9815ca357faa920db364bd2
    entity_id: light.gateway_light_f0b429b44248
    domain: light
  mode: single
- id: '1656854309099'
  alias: 关闭网关灯
  description: ''
  trigger:
  - platform: event
    event_type: ir_command_received
    event_data:
        button_name: key_off
  condition: []
  action:
  - type: turn_off
    device_id: cad9ce32e9815ca357faa920db364bd2
    entity_id: light.gateway_light_f0b429b44248
    domain: light
  mode: single

4、测试

现在你就可以用小爱红外遥控音箱、或者华为遥看小苹果、或者小度、天猫精灵万能遥控器,语音控制接入HA任何品牌的任何设备了。并且是官方渠道正规途径接入,相对稳定可靠。

总结

玩客云通过添加几毛钱的红外接收头,就打开了一片智能家居新天地,想接入任何语音平台,只要花几十块钱买个它的万能遥控器就可以。就是这么简单,我们还有必要花一百多买什么射频扩展吗?

这就是HA的魔力所在,HA的可玩性非常高。也欢迎大家留言,告诉我您智能家居的需求,您的需求就是我创作的方向。

举报
评论 0