Xiaomi mi wifi plug & air purifier

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

Awesome :yum:
Works for me!!

@xavV I can confirm I have the same issue with my setup.

Get the same error when I add more than 1 wifi plug.


2017-06-11 11:22:36 ERROR (Thread-6) [xiaomi.xiaomi] got error when receiving: wrong checksum, read b'ffffffffffffffffffffffffffffffff', computed b'09afc4d0cf3f933259ce2ab86b319809'


Please help hass newbie: How can I get the temperature and humidity measurements in the hass using this library?

You can use this one for the temp sensors https://community.home-assistant.io/t/beta-xiaomi-gateway-integration

Do you mean - using other library? This one claims sensors support and has some related code.

yep I use that one for my temp sensors!

How do you get the token from a wifi plug?

After installing construct, I’m getting

2017-06-22 23:28:59 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform xiaomi Traceback (most recent call last): File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 160, in _async_setup_platform SLOW_SETUP_MAX_WAIT, loop=self.hass.loop) File "/usr/lib/python3.4/asyncio/tasks.py", line 372, in wait_for return fut.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/xiaomi.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 14, in <module> from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes ImportError: No module named 'cryptography'

Tried to install cryptography in the same way, but without luck.

I’m running Hassbian on a RPI3.

Edit:

sudo apt-get install libffi-dev

That did the trick.