HomeAssistant 添加自定义的红外遥控器,并支持天猫精灵和小度小度

准备工作

  • 已联网的米家万能遥控器,且已添加到HomeAssistant
  • 米家万能遥控器IP 地址token

IP 地址如何获取?
在手机端打开米家 APP,选择已绑定小米账号的设备
点击进入,然后点右上角的...->更多设置->网络信息,即可查看设备的IP 地址

token如何获取?
参考1:使用开源工具导出小米Token
参考2:Retrieving the Access Token

学习自定义指令

  1. 打开HomeAssistant->开发者工具->服务,在服务里面输入xiaomi_miio.remote_learn_command,然后实体里面找到对应的,比如我的『entity_id』是remote.mo_neng_yao_kong_sh
  2. 点击按钮调用服务,然后在30秒内,拿遥控器对准米家万能遥控器,按需要学习的按键
  3. 如果操作无误,系统会收到一条通知,通知内容就是按键红外指令的base64编码。

配置自定义指令

  1. 打开HomeAssistant->Supervisor->File editor->打开 Web UI->/config/configuration.yaml
  2. 在已有的remote段落下面,增加commands
    完整的示例配置如下
remote:
  - platform: xiaomi_miio
    host: 192.168.1.86
    token: 8ec29e26xxxxxxxxxfcxxxxd3c9ef9
    model: chuangmi.remote.v2
    name: 万能遥控 SH
    slot: 1
    timeout: 30
    hidden: false
    commands:
      bladeless_fan_on_off:
        command:
          - raw:mMynEwlk0mEwlkxmU1AIKZABlMQDDmwCNANeAQUzAIOaAI2AQk3As8Bp5xMwGrAj8AQwhimc5AasGLwffAaIEfwa/BrUFlg1/Br8GtACPBr8Gvwa/AjwBpBXoCG8GLwofCY8GsgFSEo8UPxyvE68H3wmKCGsNdga4C88GJ4A
      bladeless_fan_shake_head:
        command:
          - raw:mMynEwlkznMwlgBETSaAGHMwEaAa8AjwCPA+cDEpmByQCJziZgLIAiYKCAEMBZwNfgs+AR4H3g1+Ch4NfhQ2Cz4BDzUBHw1/Br8UPwa/Bi8Ajwa/Br8ZTwa/Fe8FnwCPEW8NfwUPBryAAA==
      bladeless_fan_speed:
        command:
          - raw:mMymswlk0mUwlkxmU4AIKYABlMQDDmwCNANTMwDDmgBFAfQBrAEfgNLOJnNwLKA18BrAaymc5BH8GtQofAIUFkgEcBr8LzwhvBH8AgwofAI8Ol5xMwJyCzgDXwa/BQ8CPgGvBr8GtQUPGv8UOwR/A18a/BQ/GU8ZSwGngAA=
      bladeless_fan_timer:
        command:
          - raw:mMymswlk0mUwlgBETSYAGHNwEaAamYgNMBHACMgEeARIHyTeazMFHwbPAa8Ej5ZNAQkmgDXg2eDZ4NngNeA1gNngx+A1kxmU4BsMBdACSmc5AIYE0wbPDZ8L7wCCmwBHgNYGzYNkBfeDZ4JHgtIGzoNngjsGzIKPi16AiUAA
      bladeless_fan_wind_type:
        command:
          - raw:mMymswlk0mUwlgBETSYgGHNgEaAa8AjwLMAa8AhZxMAR0ANMFDwPmAagAhgR/AIKaAEGAIk4mEsmc5ARoAjJvOQGiAjgCzpmA14DWAEeBH4DSBH2DWwXkAWeDX4MXg1+BH4BFhr+AIQNfAIsAQoE5Aj+BZ4EfgEMM4U3nIDRARwBZIDRAfZAAA==

上面的示例配置文件,我加入了5条自定义红外命令。

配置命令脚本(将命令实体化)

  1. 打开HomeAssistant->Supervisor->File editor->打开 Web UI->/config/scripts.yaml
  2. 增加配置文件,示例如下
bladeless_fan_on_off:
  alias: 开关
  sequence:
    - service: remote.send_command
      entity_id: 'remote.mo_neng_yao_kong_sh'
      data:
        command: 'bladeless_fan_on_off'
bladeless_fan_shake_head:
  alias: 摇头
  sequence:
    - service: remote.send_command
      entity_id: 'remote.mo_neng_yao_kong_sh'
      data:
        command: 'bladeless_fan_shake_head'
bladeless_fan_speed:
  alias: 风速
  sequence:
    - service: remote.send_command
      entity_id: 'remote.mo_neng_yao_kong_sh'
      data:
        command: 'bladeless_fan_speed'
bladeless_fan_wind_type:
  alias: 风类
  sequence:
    - service: remote.send_command
      entity_id: 'remote.mo_neng_yao_kong_sh'
      data:
        command: 'bladeless_fan_wind_type'

HAVCS 设备添加

命令实体化以后,设备添加就非常简单了

  1. 打开HomeAssistant->HAVCS 设备->+
  2. 按各项内容填写即可,填完完成后点击添加
  3. 所有的HAVCS设备添加完成后,点击刷新按钮即可

参考文章