HomeKit is Apple’s framework for smart home devices. Users can control their connected accessories using the Home app on their iPhone, even via Siri. However, homekit enabled products are way overpriced. For example, D-Link’s homekit verified “The Guardian” series camera costs $199, compare to Xiaomi’s dome camera which has similar specs and functions priced at $70.
Xiaomi does have limited official support for Apple Homekit. However, you are required to have a Xiaomi router with HDD built in, and the plugin is reportedly unstable. Luckily Xiaomi does provide their API for everyone to use. So we can run a program called homebridge(project github here) on raspberry pi to send the command to Xiaomi devices. Your raspberry pi serves as a “bridge” or a “hub” between Homekit and your Xiaomi devices. There are many homebridge scripts available for Xiaomi devices. I’ll only install homebridge-aqara & Yeelight which only supports yeelight and devices using Xiaomi Mi Home ZigBee gateway. There are scripts out there for other xiaomi smart home devices like robot vacuum. You can find them on here.
Step 1. Make sure you have SSH access to your Raspberry Pi.
Step 2. Install node.js
sudo apt-get update
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash –
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential
Step 3. Install avahi
sudo apt-get install libavahi-compat-libdnssd-dev
Step 3.5. Try step 4. first! If console returned npm command not found, run the following script:
sudo apt-get install npm
Step 4. Install Homebridge
sudo npm install -g –unsafe-perm homebridge
Step 5. Install homebridge-aqara/yeelight
sudo npm install -g homebridge-aqara
sudo npm install -g homebridge-yeelight
Step 6. Create config.json
Step 7. Change config.json
The name is the bridge name shown in Home app. You don’t have to change the username and the port. The pin is your homekit passcode for the bridge.
You can find “sid” and “password” in Mi Home app on your phone.
Open Mi Home app, click on your gateway.
Click the ” ··· ” icon on the top right corner to enter the settings page.
Tap the software version about five times till the additional options “local area network communication protocol” and “gateway information” show up. Now you entered the developer mode.
Click on the forth line “local area network communication protocol”
Switch on the first button. The second line is your API password. Copy your password then click OK. Now go back to the upper menu, then click on “gateway information”.
You should see a screen like this. Copy and paste the MAC address and rewrite it in lowercases without colons. For example, the MAC address in the picture should be rewritten as a00f60ea1699 in the json config.
After fill in all the information in config.json, use Ctrl+O to save the file, then use Ctrl+x to exit the editor.
“sid”: [“MAC address for your Mi Home gateway, lowercases only without colon”],
“password”: [“API Password for your Mi Home gateway”]
If you have Yeelight devices, you need to open the Yeelight app on your phone. Then enter the device you wish to control from HomeKit, and open Developer Mode in device settings.
Step 9. Install Cron
sudo apt-get install gnome-schedule
Step 10. Configure Cron
@reboot homebridge &
at the bottom of the file.
Step 8. Run Homebridge
If you see a screen looks like this, you are now successfully linked Mi Home gateway to Apple HomeKit. Now go on your phone and open Home app. RaspBridge should show up when you try to add a new accessory.