3

树莓派 + Homebridge 接入 Homekit

 2 years ago
source link: https://blog.huangyafei.com/post/raspberrypi-homebridge-yeelight/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

树莓派 + Homebridge 接入 Homekit

树莓派安装 Homebridge 实现 Yeelight 接入 Homekit

更新软件源

在更新软件源之前,为了避免众所周知的原因造成的下载失败,建议先更换镜像源

sudo nano /etc/apt/sources.list # 用 # 注释掉原有的 source, 输入阿里云镜像. deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi sudo nano /etc/apt/sources.list.d/raspi.list # 注释掉原来的, 输入中科大镜像 deb https://mirrors.ustc.edu.cn/archive.raspberrypi.org/ stretch main ui

更新完镜像源后,再更新软件源

sudo apt-get update sudo apt-get upgrade

安装 Node.js

HomeBridge 官方推荐的方法:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt-get install -y nodejs

使用 nvm 安装的安装方法:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash nvm install 8.11.3 nvm use 8.11.3

安装 AVahi

sudo apt-get install libavahi-compat-libdnssd-dev

安装 AVahi 可能会会提示依赖错误,很多人都遇到了 libdbus-1-3 版本造成的冲突问题,可在文末链接自行寻找解决方法。

安装 Homebridge 及相关插件

安装 Homebridge

sudo npm install -g --unsafe-perm homebridge

安装基于 Homebridge 的 Yeelight 插件 homebridge-yeelight

sudo npm install -g homebridge-yeelight

安装基于 HomeBridge 的小米网关插件 homebridge-mi-aqara

sudo npm install -g homebridge-mi-aqara

 配置 HomeBridge 的 config.json 文件

sudo nano ~/.homebridge/config.json

文件内容:

{ "bridge": { "name": "Homebridge", "username": "CC:22:3D:E3:CE:30", "port": 51826, "pin": "031-45-154" }, "description": "This is an example configuration file with one fake accessory and one fake platform. You can use this as a template for creating your own configuration file containing devices you actually own.", "accessories": [], "platforms": [{ "platform": "MiAqaraPlatform", "gateways": { "7c49eb18d32d": "808B50897CB9436F" } }] }

运行 HomeBridge 并在 iOS 上添加设备

运行 HomeBridge

homebridge

打开 iOS 上的 Home,添加设备。

设置 Homebridge 开机自启动

新建文件:

sudo nano /etc/init.d/homebridge

然后粘贴:

#!/bin/sh ### BEGIN INIT INFO # Provides: homebridge # Required-Start: $network $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start daemon at boot time # Description: Enable service provided by daemon. ### END INIT INFO dir="/home/pi" cmd="DEBUG=* /usr/bin/homebridge" user="pi"

最后给权限:

sudo chmod 755 /etc/init.d/homebridge sudo update-rc.d homebridge defaults

完整安装流程参考:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK