Xiaomi Gateway Integration

Door sensor works but the only problem is after it is open for like 5 minutes the status stays as off untill I do something then it changes

Hey guys.

I set this up but getting this error, any help?

16-12-26 11:05:06 homeassistant.loader: Error loading homeassistant.components.xiaomi. Make sure all dependencies are installed
Traceback (most recent call last):
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/loader.py”, line 139, in get_component
module = importlib.import_module(path)
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/importlib/init.py”, line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 2254, in _gcd_import
File “”, line 2237, in _find_and_load
File “”, line 2226, in _find_and_load_unlocked
File “”, line 1200, in _load_unlocked
File “”, line 1129, in _exec
File “”, line 1471, in exec_module
File “”, line 321, in _call_with_frames_removed
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/xiaomi.py”, line 11, in
from Crypto.Cipher import AES
ImportError: No module named ‘Crypto’
16-12-26 11:05:06 homeassistant.loader: Unable to find component xiaomi

I’ve reinstall Crypto and Pycrypto, not sure what else I’m doing wrong? :confused:

You’re using virtual environment. You need to follow the steps in the manual installation guide to switch to the virtual environment and change to the right directory. Then instead of running pip3 install homeassistant, you’ll need to run pip3 install pycrypto

Anyway, if you can wait for a day or so, I’ll post an update that make the installation easier so you can use it as a custom component

Yeah, should of mentioned, I’ve already tried that but get this when installing:

Requirement already satisfied: pycrypto in /usr/local/lib/python3.4/dist-packages

But are you doing that from the virtual environment? If yes, the files should be somewhere in the homeassistant venv folder

Yep, here is where it’s running from:

(homeassistant_venv) pi@raspberrypi:~ $ sudo pip3 install pycrypto

The files were placed here:

/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components

Then run the command without sudo. That’s how i did it.

Yikes, now I get this :frowning: Sorry to trouble you.

Exception:
Traceback (most recent call last):
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/pip/basecommand.py”, line 215, in main
status = self.run(options, args)
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/pip/commands/install.py”, line 342, in run
prefix=options.prefix_path,
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/pip/req/req_set.py”, line 784, in install
**kwargs
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/pip/req/req_install.py”, line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/pip/req/req_install.py”, line 1064, in move_wheel_files
isolated=self.isolated,
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/pip/wheel.py”, line 345, in move_wheel_files
clobber(source, lib_dir, True)
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/pip/wheel.py”, line 316, in clobber
ensure_dir(destdir)
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/pip/utils/init.py”, line 83, in ensure_dir
os.makedirs(path)
File “/srv/homeassistant/homeassistant_venv/lib/python3.4/os.py”, line 237, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: ‘/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/Crypto’

What about switching to home assistant user,then install?

Still same as before:

Requirement already satisfied: pycrypto in /usr/local/lib/python3.4/dist-packages

Try exit from the virtual environment and uninstall that first.

Right, fixed it! Thank you for your help.

I had to add homeassistant to sudoers (as its not there by default). Then install pycrpyto in virtualenv using pip3 install pycrypto.

Thanks rave, appreciate it.

New update!

  • Can be installed into custom_components folder
  • Pycrypto will install automatically
  • Fixed bug with door sensor
2 Likes

you’re right, it’s fixed now.

1 Like

I’m testing motion sensor. I’ve noticed that it needs 2 minutes to turn off. In mi home app it needs only 1 minute to turn off. Is it possible to turn off in 1 minute? Thanks for making this.

The data was sent from the hub so the logic on how long it activates is determined by the hub. You can of course modify it to turn off in a minute but it would be wrongly reported if the motion sensor is actually still activated

But let me look in details how the hub reports the data

Cheers Mate !

Just donated something for your hardwork . It works pretty well and it’s very fast compared to Mi Home App. I mean that thing routes from china servers to here , but in this app everything is done automatically

Thanks! My next task is to get another hub and a Zigbee cube and make those works in HA. Keep watching this thread :grinning:

I think we can take a look at homebridge aqara. The person there managed to get 2 gateway to work. Maybe it’s something we can do

Also homebridge and home assistant doesn’t play nice when both have Xiaomi plugin. Suspect both conflicting with one another

Edit : Combining MAC Address of gateway + Key may help us to have multiple gateways with multiple connections

Thanks Rave. I had to rename some Mi sensors since I was using fooxy. Too bad that I have the wifi plugs.Looking forward on the development on the gateway control :smiley: