中文 English

Home Assistant: Add a Custom IR Remote and Support Tmall Genie and Xiaodu

Published: 2021-05-12
homeassistant HAVCS Remote

Preparation

How do you get the IP address? Open the Mi Home app on your phone, select the device bound to your Xiaomi account, enter it, then tap the ... in the top right -> More settings -> Network information to view the device IP address.

How do you get the token? Reference 1: Use an open-source tool to export Xiaomi Token Reference 2: Retrieving the Access Token

Learn Custom Commands

  1. Open Home Assistant -> Developer Tools -> Services, enter xiaomi_miio.remote_learn_command in Services, then find the corresponding entity in Entity. For example, my entity_id is remote.mo_neng_yao_kong_sh.
  2. Click Call Service, then within 30 seconds point the remote at the Mi Home universal remote and press the button you want to learn.
  3. If everything is correct, the system will receive a notification containing the base64 encoded infrared command.

Configure Custom Commands

  1. Open Home Assistant -> Supervisor -> File editor -> Open Web UI -> /config/configuration.yaml
  2. Under the existing remote section, add commands. The full sample configuration is as follows:
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==

The sample configuration above adds 5 custom infrared commands.

Configure Command Scripts (turn commands into entities)

  1. Open Home Assistant -> Supervisor -> File editor -> Open Web UI -> /config/scripts.yaml
  2. Add the configuration below:
bladeless_fan_on_off:
  alias: Toggle
  sequence:
    - service: remote.send_command
      entity_id: 'remote.mo_neng_yao_kong_sh'
      data:
        command: 'bladeless_fan_on_off'
bladeless_fan_shake_head:
  alias: Swing
  sequence:
    - service: remote.send_command
      entity_id: 'remote.mo_neng_yao_kong_sh'
      data:
        command: 'bladeless_fan_shake_head'
bladeless_fan_speed:
  alias: Speed
  sequence:
    - service: remote.send_command
      entity_id: 'remote.mo_neng_yao_kong_sh'
      data:
        command: 'bladeless_fan_speed'
bladeless_fan_wind_type:
  alias: Wind Mode
  sequence:
    - service: remote.send_command
      entity_id: 'remote.mo_neng_yao_kong_sh'
      data:
        command: 'bladeless_fan_wind_type'

Add HAVCS Devices

After turning commands into entities, adding devices becomes very easy.

  1. Open Home Assistant -> HAVCS Devices -> +
  2. Fill in the fields as required and click Add
  3. After all HAVCS devices have been added, click Refresh

References