Xiaomi mi wifi plug & air purifier

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.

See my post above

Has anybody been able to change the intensity of the air purifier through home assistant?
All I get by following the instructions is an on/off switch.

Sorry, I missed the context.

  1. Where is xiaomi.py coming from?
  2. Where is the folder “xiaomi” coming from?
  3. Where do I get the token from?
  4. Does this work with https://github.com/Danielhiversen/homeassistant/ or https://github.com/lazcad/homeassistant

Thanks,

Both - folder an xiaomi.py - are coming from the repo mentioned in the first post.

I’ve linked to a tutorial on how to get the token above.

It doesn’t work with the Xiaomi-component (because it isn’t the Zigbee version, just WiFi). But you can install them next to each other. Just remember to rename the xiaomi.py from the repo above. As stated here.

Hope it helps.

Cheers.

Hi @syssi, thanks for the help. I have moved this conversation to the appropriate forum. I think I am getting closer… I can almost taste victory! The below is my most recent error logs after trying to implement the plug protocol.

I have the xiaomi folder in /hassbian/homeassistant/
I have teh xiaomiplug.py (renamed xiaomi from switch) in homeassistant/custom_components/ (and also in /switch).

My yaml is as follows:

switch:
  - platform: xiaomiplug
    host: 10.xx.xxx.xxx
    name: Lounge Lamp
    token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I tried sudo pip3 install construct, which is now installed but I am still getting the below:

2017-07-12 01:07:39 ERROR (MainThread) [homeassistant.components.switch] Error while setting up platform xiaomiplug
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 164, 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/xiaomiplug.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'

Any more advice on where I may be going wrong?

Thanks for all the help!

It looks like you didn’t install “construct” properly. Do you use hassbian? You must install the package at the virtualenv:

su - homeassistant
source /srv/homeassistant/bin/activate
pip3 install construct

I am using hassbian, when I run the command su - homeassistant using PuTTY its asking for a password, but its not accepting what I believe it to be. Any hints or tips. Sorry to be such a pain!

Check homeassistant is the correct user.
If so, you can reset the password by doing sudo passwd homeassistant.

If you are “root” the command will not ask for a password.