Xiaomi IR Remote Commands

I’ve setup my Xiaomi IR device in the Xiaomi Home app and integrated it as a device into Home Assistant. However, I have no idea what I have to do next inorder to be able to send commands from the device. The integrations page talks about commands being learned or pronto values etc, but it’s not very clear as to how you get these commands.

I’d really appreciate some assistant as to how I can now start adding commands to my HA config and then get them sent via the IR device.

P.s. I have my remote setup in the Xiaomi Home app along with my TV and Soundbar.

Thanks.

1 Like

Run this service without any paramter, and then blast your remote to xiaomi IR. You will see a code in notification pane. Try this at first.

I’ll give that a try. Thanks!

Hey @Phill_Healey if this works can you share a small review on how well it operates? I’m also wondering on buying this device… where did you get it?

It works really well outside of HA but I’ve yet to get around to HA setup. I got it via banggood.com

Example:

  1. In Services choose xiaomi_miio.remote_learn_command and you device remote.xiaomi_miio_192_168_1_63 for example
  2. Click call service
  3. Blast your remote to Xiaomi IR
  4. See a code in notification pane
  5. Paste your code in configuration.yaml like this:
remote:
  - platform: xiaomi_miio
    host: 192.168.1.63
    token: your token
    commands:
      tv_turn_off:
        command:
          - raw:mc0m0wlkxm80mEsmkwADIAwppMgECmYBhgIVNAIDAHOZgD+A/4A/gD+DBYHHgoeAv4SFgoeChAJHgD+Cx4JHgkeAhABHgV+Bn4W1zGZgGGB34FfgIdMIAA==
  1. Now you can add a script like this:
'tv_turn_off':
  alias: TV Turn Off
  sequence:
    - service: remote.send_command
      entity_id: 'remote.xiaomi_miio_192_168_1_63'
      data:
        command:
          - 'tv_turn_off'
2 Likes

Excellent. Thanks for the extra clarification.

I’ve tried that but i just get a notification at the bottom of the screen saying "Failed to call remote/learn_command

And this is what I’m getting in the logs:

2020-02-08 17:45:35 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.2366024624] 
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/websocket_api/commands.py", line 134, in handle_call_service
    connection.context(msg),
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py", line 1226, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/core.py", line 1251, in _execute_service
    await handler.func(service_call)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_component.py", line 198, in handle_service
    self._platforms.values(), func, call, required_features
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 356, in entity_service_call
    future.result()  # pop exception if have
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/service.py", line 384, in _handle_service_platform_call
    result = await result
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/remote/__init__.py", line 134, in async_learn_command
    await self.hass.async_add_executor_job(ft.partial(self.learn_command, **kwargs))
  File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/remote/__init__.py", line 130, in learn_command
    raise NotImplementedError()
NotImplementedError

try this in your service
xiaomi_miio.remote_learn_command
instead of
remote.learn_command
it should be work now.

2 Likes

I did the setup exactly as mentioned. I do receive raw codes, I did make the commands but when I am trying to send them, the light of the Mi Remote blinks, it looks like the code is being sent but my IR devices do not respond.

Any tips? Also my received raw codes don’t look as long as yours.

Thanks

i didnt managed to make it blink at all. all i m getting is magic error. can you share how do you make it work, at least to make it blink

I have returned it and bought a Broadlink RM4 Mini instead.

IT works perfectly for me. I did notice that after calling the service that I needed to wait for the led to blink before holding down the key on the remote that I want to clone. Then just keep the key pressed until you get the notification bubble on the sidebar icon.

Be sure to include the entity_id of your miio remote device. This may not be the same as the name you gave it in config. Go to unused entities and search for miio, then you should see the actual entity_id of your miio remote.

1 Like

unfortunately for me, i checked against the unused entities and it matched what i used in the automation yaml. i managed to capture the code from remote that i wanted to copy, just could not get it to transmit the copied IR (with magic error) and it didnt blink at all.
Is it possible for you to share your code for automation? and also the confi.yaml

edit: nvm. i managed to get it to work. somehow, when i learn the command, i need to only momentarily press the button to get the right code. Press a bit too long, the code learnt is different (longer code, with == at the end). The correct code doesnt have == at the back and shorter. This might be right only for my Panasonic Ceiling Fan, but that is the idea.

I don’t have access to my HA backend at the moment. Would you care to share yours for reference?

Thanks.

Sure…

This is for remote configuration in config.yaml.

- platform: xiaomi_miio
  host: 192.168.0.141
  token: 'your token here, in the single quote'
  name: Remote Hall

This is for automation. I use script to put in the command, you can also key that in the config.


ir_fan_off:
    sequence:
    - service: remote.send_command
      entity_id: remote.xiaomi_miio_192_168_0_141
      data:
        command:
          - 'Z6VzALMBAAAeBQAAsgYAAJ4NAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAjABAAAAAAAAAAAAAAABAAAAAAAAAQABAQAAAQAAAAABAAAAAAEBAAABAAAAAQEAAAEAAQABAAEAAA'

now it works perfectly

hello
i learn how send command to xiaomi ir.
But seems impossible to read a command for automation, for a trigger.
I’m wrong?
there is some solution?
Thanks

Thank you all. Very usefull to read this topic.
BTW, I’ve used the very efficient token extractor available here: GitHub - PiotrMachowski/Xiaomi-cloud-tokens-extractor: This tool/script retrieves tokens for all devices connected to Xiaomi cloud and encryption keys for BLE devices. Thanks to the author.

That gives this kind of output:
Devices found for server “cn”:

NAME: Xiaomi-remote
ID: 123456789
MAC: 40:31:3C:XX:XX:XX
IP: 192.168.0.202
TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MODEL: chuangmi.remote.v2