一、什么是Homebridge

Homebridge is a lightweight NodeJS server you can run on your home network that emulates the iOS HomeKit API. It supports Plugins, which are community-contributed modules that provide a basic bridge from HomeKit to various 3rd-party APIs provided by manufacturers of “smart home” devices.

HomeKit是苹果的智能家居平台,是iOS系统层面支持的平台,拥有其它平台无法比拟用户体验。可惜大部分米家设备及其它平台的设备都不支持HomeKit,但是可以通过Homebridge作为桥接,实现HomeKit控制其它平台的设备。

387d405333a0546f694749cbffedc354

二、如何在树莓派上搭建Homebridge

https://github.com/homebridge/homebridge/wiki/Install-Homebridge-on-Raspbian

562e7f425d01d86f52f15567c363b282 0048c88f9c0ba43c8235a20d386fcbaa 0638eebebe1e467b00cb548ac3b73dab

三、安装插件

在这个网址https://www.npmjs.com/search?q=keywords%3Ahomebridge-plugin上可以通过关键字搜索插件,

92672193b785e2e16ffe5d4d79179357

常用插件:

1.Aqara套装:homebridge-mi-aqara
2.米家空调伴侣:homebridge-mi-acpartner
3.米家yeelight台灯:homebridge_yeelight
4.小米风扇:homebridge-mi-fan
5.米家智能摄像机:homebridge-mi-camera
6.米家智能排插:homebridge-mi-outlet
7.米家空气净化器:homebridge-mi-airpurifier
8.飞利浦灯泡:homebridge-mi-philips-light
9.智能插座:homebridge-mi-outlet
...

四、配置设备

在Homebridge上,插件利用设备的IP地址及设备的token即可以实现控制某个设备,IP地址我们可以登录路由器查看已连接的设备获取,获取token有以下几种方法:

1、使用安卓手机下载旧版本的米家app,导出里面的数据库找到设备token 2、使用miio discover命令获取(米家新的设备基本都隐藏了token,这种方法基本失效) 3、利用Charles抓包

059c08db26f43e551a0dce918b752f4f

Homebridge具体配置如下:

{
    "bridge": {
        "name": "Homebridge D535",
        "username": "0E:E2:26:BC:D5:35",
        "port": 51762,
        "pin": "720-92-067"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "platform": "config"
        },
        {
            "deviceCfgs": [
                {
                    "type": "MiPhilipsSmartBulb",
                    "ip": "192.168.31.183",
                    "token": "3f94f9fd80bcef65478ca59464522c93",
                    "lightName": "灯泡",
                    "lightDisable": false
                }
            ],
            "platform": "MiPhilipsLightPlatform"
        },
        {
            "platform": "MiOutletPlatform",
            "deviceCfgs": [
                {
                    "type": "MiPlugBase",
                    "ip": "192.168.31.29",
                    "token": "83a7c8f83f44f2adefac68ce828aa084",
                    "outletName": "客厅插座",
                    "outletDisable": false,
                    "temperatureName": "客厅插座温度",
                    "temperatureDisable": false,
                    "switchLEDName": "客厅插座指示灯",
                    "switchLEDDisable": false
                }
            ]
        }
    ]
}

注意:每次修改完配置都需要重启Homebridge服务

五、效果

5c0d4c5dc3c5b42ba868916051435539 71973f9f9944eac3cda598a4d06158e9