Xiaomi mi wifi plug & air purifier

I’m also curious about this - how to find token and where to put files?

I 'm also wondering how to get this integration working, any chance for a step by step guide or even some sample code?

Does the wifi switch work for you?
I’m currently just using the mirobo component in a switch from here.
I can discover the device by running “mirobo discover”. I even get the ip and they key back.

This is my config.

switch:

  • platform: mirobo
    name: ‘name’
    host: Ip
    token: Token

I get the error as below

2017-05-17 11:12:18 ERROR (Thread-8) [custom_components.switch.mirobo] Got exception while fetching the state: timed out

Hi, i’m also very interested about the integration between Xiaomi air purifier 2 and Home assistant. Can you write a step by step guide to do it?
I actually have the xiaomi gateway with zigbee socket plugs, switches, door sensors and temperature sensor, everything works except for the purifier and a Smart Wifi Socket Plug ZNCZ02CM

My wifi plug arrives today.
+1 on the Step-by-Step guide.

No one on the token?
EDIT 1:
I get the following error (assuming it is because of the missing token):

Got exception while fetching the state: cannot import name 'Device'

EDIT 2:

You can get your tokens like this: https://github.com/aholstenson/miio/blob/master/docs/management.md
Unfortunately this does not solve my error message.

See above. I got my token by implementing mirobo library on the pi. I’m not sure i wasnt to install node.js for just getting the token.

Did you find a solution? I get the following error:

2017-06-04 13:43:41 INFO (Thread-3) [custom_components.switch.mirobo] initializing with host 192.168.0.81 token b'8735e7bd8f10b45ea6708ba89c1a4f7b'
2017-06-04 13:43:41 ERROR (Thread-3) [custom_components.switch.mirobo] Got exception while fetching the state: non-hexadecimal number found in fromhex() arg at position 0

I’m using (trying to…) the mirobo-component as a switch for the plug as well.

I havent been able to integrate the socket with HA; but have managed to get the token working - which is of no use as of now :frowning:

I think your problem is that your are using b'token instead of just token

Yes, if I eliminate the " b’ " and the " ’ " from the token - I get the same error as you. Connection timed out. :frowning:

I’ve got some success with the miio platform


It also offers CLI to manage devices. I’m thinking of heading down the path of using this only for the switch.
I’m holding back as it seems like a bit of an overkill to install node.js on the pi to just switch on/off a switch with HA.

In which way did you succeed? Did you just install the miio-component as described?

Well I assume this repo isn’t maintained anymore? Currently I’m stuck with the error

Cannot import name ‘device’

I’ve opened an issue at his GitHub-repo… Just in case.
For now I’ve to schedule my plug with the Xiaomi-App. But maybe someday someone with more knowledge of python than me (which shouldn’t be difficult :-D) integrates this thing into HA.

@eiolos @maunsen @FletchNZ @seesopento

If anyone of you is still interested: it works now for me. I did the following (assuming you have the token and the device’s IP).

  1. Where to put the files:
    custom_components/switch/xiaomi.py --> /home/homeassistant/.homeassistant/custom_components/switch/xiaomiplug.py (I had to rename it - because of my integration of the Gateway)

I put the folder “xiaomi” under:
/home/homeassistant/.homeassistant/

And after adding the following to my configuration.yaml I got it working (remember to change the platform according to the name of the file you put under custom_components:

switch:
  - platform: xiaomiplug
    host: 192.168.0.81
    name: Kaffeemaschine
    token: 8735e7bd8f10b45ea6708ba89c1a4f7b

If there’re any questions just ask. I’ll try my best.

1 Like

which files did you get? just the switch/xiaomi.py??? or did you get the whole platform?

No. I put the xiaomi.py under my /home/homeassistant/.homeassistant/custom_components and the folder (!) xiaomi under /home/homeassistant/.homeassistant/ (ie. one level above the custom_components-folder

Didn’t see that too excited :grin:

Awesome!!! Works for me too.

1 Like

Great news! Glad it works for you too! :slight_smile:

Any ideas as to why I get this error please ?

2017-06-08 14:28:32 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform wifiplug
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 155, in _async_setup_platform
    entity_platform.schedule_add_entities, discovery_info
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/switch/wifiplug.py", line 17, in setup_platform
    import xiaomi
  File "/home/homeassistant/.homeassistant/xiaomi/__init__.py", line 2, in <module>
    from .protocol import Message, Utils
  File "/home/homeassistant/.homeassistant/xiaomi/protocol.py", line 7, in <module>
    from construct import (Struct, Bytes, Const, Int16ub, Int32ub, GreedyBytes,
ImportError: No module named 'construct'

You dont have construct installed.

  1. Activate virtual environment
    source /srv/homeassistant/homeassistant_venv/bin/activate
  2. Install construct
    pip3 install construct