Using Xiaomi Sensors with Home Assistant without the Xiaomi Gateway
Xiaomi sensors are great additions to anyone’s home automation project. They are extremely inexpensive ($5 – $10 per sensor) and they are battery operated so installation is simple. We have used their door/window sensors and temperature sensors all over our home and they work really well.
Home Assistant has native support for the Xiaomi Gateway and most of the devices that connect to it. So if you want to use all of the inexpensive Xiaomi sensors and switches, you only need to pair them to the Gateway and then add a few lines to your configuration.yaml file. However, the Gateway has a bad habit of phoning home to China. People typically lock this down by using their router’s firewall to block the Gateway’s internet access. The Gateway also adds another step in the process that potentially slows everything down.
We took things a step further and got rid of our Xiaomi Gateway and connected our sensors directly to Home Assistant. Here’s how:
We planned ahead when we built our Home Assistant hub and we purchased a HUSBZB-1 USB stick. This nifty little stick has both z-wave and zigbee radios.
While Home Assistant has built in support for zigbee (zha component), we needed a special version of it. Head on over to Yoda-x’s github page (https://github.com/Yoda-x/ha-zha-new) and grab his new version of the zha component that supports Xiaomi devices. Installation is pretty straightforward:
- Download the zip file
- Extract the files and copy the “custom_components” folder to your Home Assistant configuration folder
- Add this to your configuration.yaml file (you might have to edit the usb_path to match your system):
123zha_new:usb_path: /dev/ttyUSB1database_path: zigbee.db
If you don’t have any zha_new errors in your log, you’re ready to pair your devices.
Pairing Your Xiaomi Sensors:
- In Home Assistant go to Developer Tools \ Services (the remote icon in the Home Assistant menu).
- In the Services drop down list, select zha_new.permit
- Click Call Service to start the pairing process
- Most sensors have a small button and an activity LED. Hold the button down until the LED starts blinking (usually about 3 seconds). Release the button.
- Now you need to keep the device awake while Home Assistant pairs with it. Press and release the button about once a second for 20 seconds.
- In Home Assistant check your list of devices in Developer Tools \ States. You should see 2 – 4 new devices in the list. They usually show the manufacturer as LUMI
- You can also edit the entity_id and the device’s friendly name from here.
And that’s it. Repeat the process for each sensor!