Xiaomi Chuangmi_ir (Universal IR Remote Controller)

@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-

I think I see the difference. @hangy and @ec-blaster are using the component as switch(es). You are trying to use the send_packet service, right?

1 Like

Right, i’m using Developer Tools
Domain chuangmi
Service send_packet_IP
Service_data:
{“packet”:“command_captured”}
I was trying to make it work with developer tools but now i’ve tried to add this command to switch configuration and it works perfectly.

Thanks for all the help.

I made some changes. The service should work now. Please test the latest revision! :slight_smile:

1 Like

I cannot test it right now, but I remember that the packet must be an array of strings (may be just with one element). If you send the parameter as a string, the service interprets it as an array of chars and sends a lot of packets making the device collapse. Most of the times you have to reset or disconnect it to make it work again.

Mine works flawlesly as a switch. But I have an automatio based on a slider that aims to set the air conditioner temperature sending different IR codes for each temperature setting. It uses the component service, but it fails as I must provide the packet as an array of one string element, and I don’t have the expression set very well yet…