Xiaomi Chuangmi_ir (Universal IR Remote Controller)

hi to all and sorry for my bad english…

I’m trying to make work with homeassistant the xiaomi universal ir remote controller (https://www.gearbest.com/smart-home/pp_229556.html)

i’ve found this plugin: https://github.com/homeassistantchina/custom_components

i’ve extracted the token using my rooted phone using this procedure: https://github.com/homeassistantchina/custom_components/blob/master/doc/chuang_mi_ir_remote.md

in the switch part of my configuration file i’ve added:

  • platform: chuangmi_ir
    name: “livingroomirremote”
    host: !secret chuangmi_ip
    token: !secret chuangmi_key
    timeout: 20
    switches:
    reciever:
    command_on: ‘’
    command_off: ‘’

as the guide says in the service menu of homeassistant i used the learn_command_ipaddress to learn my remote code… but nothing appears… and watching my logs i can see this:
2017-08-29 17:07:00 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=1974081712-1011, service=learn_command_192_168_1_189, service_data=, domain=chuangmi>

2017-08-29 17:07:05 ERROR (MainThread) [miio.miio] got error when receiving: timed out
2017-08-29 17:07:06 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved

Traceback (most recent call last):
File “/usr/lib/python3.4/asyncio/tasks.py”, line 237, in _step
result = next(coro)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py”, line 1025, in _event_to_service_call
yield from service_handler.func(service_call)
File “/home/homeassistant/.homeassistant/custom_components/switch/chuangmi_ir.py”, line 67, in _learn_command
ir_remote.send(“miIO.ir_learn”, {‘key’: str(key)})
File “/srv/homeassistant/lib/python3.4/site-packages/miio/miio.py”, line 128, in send
data, addr = s.recvfrom(1024)
socket.timeout: timed out

2017-08-29 17:07:06 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

1 Like

@syssi :slight_smile:

Alright. :slight_smile: As next step please enable the debug logging for the custcom component:

logger:
  default: warn
  logs:
    custom_components.switch.chuangmi_ir: debug

And try again. Please post your home-assistant.log.

My first impression: Your device isn’t available. It’s possible to ping the device (ping 192.168.1.189)?

Yes… I’ve two of them. Both are pingable… When i came back from work i’ll add the logger component and post the output. Thanks :wink:

1 Like

@syssi this is the output when i try to learn a remote:

2017-08-30 17:12:13 ERROR (MainThread) [miio.miio] got error when receiving: timed out
2017-08-30 17:12:13 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py", line 1025, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/home/homeassistant/.homeassistant/custom_components/switch/chuangmi_ir.py", line 67, in _learn_command
    ir_remote.send("miIO.ir_learn", {'key': str(key)})
  File "/srv/homeassistant/lib/python3.4/site-packages/miio/miio.py", line 128, in send
    data, addr = s.recvfrom(1024)
socket.timeout: timed out
2017-08-30 17:12:14 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

this is when i try to send a ir command

2017-08-30 17:16:13 ERROR (MainThread) [miio.miio] got error when receiving: timed out
2017-08-30 17:16:13 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/switch/chuangmi_ir.py", line 98, in _send_packet
    ir_remote.send("miIO.ir_play", {'freq':38400, 'code': str(packet)})
  File "/srv/homeassistant/lib/python3.4/site-packages/miio/miio.py", line 128, in send
    data, addr = s.recvfrom(1024)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py", line 1025, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/usr/lib/python3.4/asyncio/coroutines.py", line 141, in coro
    res = func(*args, **kw)
  File "/home/homeassistant/.homeassistant/custom_components/switch/chuangmi_ir.py", line 100, in _send_packet
    except (socket.timeout, ValueError):
NameError: name 'socket' is not defined
2017-08-30 17:16:13 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

Is your chuangmi_key hexadecimal and has a length of 32 characters?

is hex and the length is 33 char

Are you sure? Put the cursor in front of the last char. :wink:

sorry, i’m a stupid… all of them are 32 chars

@ec-blaster Can you help here? I know you are using the device: Xiaomi mi wifi plug & air purifier - #125 by ec-blaster

I think changing the timeout doesn’t help because the timeout is used at L71 and the code fails at L68 already.

@hangy Could you try to change the following line:

Increase the timeout a bit (10 seconds?) for testing. This timeout is applied here and later used at L128. The implementation and used library is pretty old… I will try to rewrite the component this weekend.

1 Like

I’ve fixed some issues. Please give it a try:

The code looks a bit unstable because of timing issues.

1 Like
2017-08-31 00:38:50 INFO (MainThread) [custom_components.switch.chuangmi_ir] Press the key you want HASS to learn
2017-08-31 00:38:50 ERROR (MainThread) [custom_components.switch.chuangmi_ir] <class 'str'>
2017-08-31 00:38:50 ERROR (MainThread) [custom_components.switch.chuangmi_ir] 
2017-08-31 00:38:51 ERROR (MainThread) [custom_components.switch.chuangmi_ir] <class 'str'>
2017-08-31 00:38:51 ERROR (MainThread) [custom_components.switch.chuangmi_ir] 
2017-08-31 00:38:52 ERROR (MainThread) [custom_components.switch.chuangmi_ir] <class 'str'>
2017-08-31 00:38:52 ERROR (MainThread) [custom_components.switch.chuangmi_ir] 
2017-08-31 00:38:53 ERROR (MainThread) [custom_components.switch.chuangmi_ir] <class 'str'>
2017-08-31 00:38:53 ERROR (MainThread) [custom_components.switch.chuangmi_ir] Z6VHAPwBAABvAgAAVAYAAI8IAABjEQAAbyMAAAidAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABFIQEBAQEBAQEBISEhISEhIQEBAQEhASEBISEhIQEhASFhNQE=
2017-08-31 00:38:53 INFO (MainThread) [custom_components.switch.chuangmi_ir] Captured infrared command: Z6VHAPwBAABvAgAAVAYAAI8IAABjEQAAbyMAAAidAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABFIQEBAQEBAQEBISEhISEhIQEBAQEhASEBISEhIQEhASFhNQE=

it works… the learning method… tomorrow i’ll try to fully integrate :wink:

thankssssssssss

ok i’ve tryed to send a packet and it works perfect :slight_smile:

1 Like

Sorry, I didn’t get the thread notification until late night, although I see that you solved it.
I am using the same component by SchumiHao, and I got that error only twice: once when I hadn’t set the timeout parameter and another time that I couldn’t understand why. I solved this last one by rebooting my router.

1 Like

i have tried this and learn_command works perfect, but when i try to send_command i get this error:
2017-09-03 13:15:09 ERROR (MainThread) [mirobo.device] Unable to discover a device at address 192.168.1.143
2017-09-03 13:15:09 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.4/asyncio/tasks.py”, line 237, in _step
result = next(coro)
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/core.py”, line 1025, in _event_to_service_call
yield from service_handler.func(service_call)
File “/usr/lib/python3.4/asyncio/coroutines.py”, line 141, in coro
res = func(*args, **kw)
File “/home/homeassistant/.homeassistant/custom_components/switch/chuangmi_ir.py”, line 101, in _send_packet
“miIO.ir_play”, {‘freq’: 38400, ‘code’: str(packet)})
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/mirobo/device.py”, line 120, in send
self.do_discover()
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/mirobo/device.py”, line 72, in do_discover
raise DeviceException(“Unable to discover the device %s” % self.ip)
mirobo.device.DeviceException: Unable to discover the device 192.168.1.143
2017-09-03 13:15:09 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

i have checked that the ip and token was right.

Any suggestion?

thanks

It looks like you hit this bug, too:

thanks, i’ve tried this commands before
miio --ip 1.2.3.4 --token 1653
mirobo --ip 1.2.3.4 --token 165
3
with errors

After your response i’ve tried
“miio --control 1.2.3.4 --token 1653 --method miIO.info" and gives me this error
Error: no such option: --control
but
"mirobo --ip 1.2.3.4 --token 165
3 -d info” gives me this
DEBUG:mirobo.vacuum_cli:Full response: {‘ap’: {‘bssid’: ‘xxxxxxxx’, ‘rssi’: -59, ‘ssid’: ‘wifi’},
‘cfg_time’: 0,
‘fw_ver’: ‘1.2.4_38’,
‘hw_ver’: ‘MC200’,
‘life’: 1126458,
‘mac’: ‘’,
‘mmfree’: 46192,
‘model’: ‘chuangmi.ir.v2’,
‘netif’: {‘gw’: ‘1.2.3.1’,
‘localIp’: ‘1.2.3.4’,
‘mask’: ‘255.255.255.0’},
‘ot’: ‘otu’,
‘ott_stat’: [1,2,3,4],
‘otu_stat’: [1, 2, 3, 4, 5],
‘token’: ‘165***3’,
‘wifi_fw_ver’: ‘xxxx’}
DEBUG:mirobo.vacuum_cli:Writing {‘manual_seq’: 0, ‘seq’: 2} to /tmp/python-mirobo.seq

can i try something more? thanks

If the following command just works

mirobo --ip 1.2.3.4 --token 165xxx3 -d info

the ir_play command should also work:

mirobo --ip 1.2.3.4 --token 165xxx3 -d raw_command miIO.ir_play '["freq":"38400","code":"your-captured-command"]'

Please give it a try.

Yes, it works with that command. I’ve replaced [] to {} to make it work.
Now, back in homeassistant, when i try to send this same captured command, the blue led flashed several times and then it turned off. I’ve must to reset manually the chuangmi_ir to make it be usable again.

i’ve updated the python-miio and python-mirobo to version 0.0.11 and 0.1.4.

Thanks-