本帖最后由 遥远 于 2017-9-21 01:33 编辑
教程来源为老高,自己整理了一下,经过n次验证,没有任何问题
镜像下载地址:https://github.com/home-assistant/pi-gen/releases
下载后用写盘工具写入tf卡后,装上机器上电启动,记得要通上网线。
大约几分钟左右,你就可以在chrome中打开:http://树莓派ip:8123 (如果有梯子速度会快很多)
然后用ssh工具连上树莓派,用户名是pi,密码是raspberry
接着你就下面的做吧
#更新-升级
sudo apt-get update
sudo apt-get upgrade -y
#设置语言、时间等
sudo raspi-config
#下载安装Nodejs(更新8版本,会有二行红色报错,无视)
curl -sL [url=https://deb.nodesource.com/setup_8.x]https://deb.nodesource.com/setup_8.x[/url] | sudo -E bash -
sudo apt-get install -y nodejs git libavahi-compat-libdnssd-dev
sudo npm install -g --unsafe-perm hap-nodejs node-gyp homebridge homebridge-homeassistant
cd /usr/lib/node_modules/homebridge/
sudo npm install --unsafe-perm bignum
cd /usr/lib/node_modules/hap-nodejs/node_modules/mdns
sudo node-gyp BUILDTYPE=Release rebuild
#这里先运行一次程序
homebridge
#键盘输入Ctrl+C停止,然后建立config.json配置文件
sudo nano /home/pi/.homebridge/config.json
#鼠标右键粘贴如下内容(XX处修改为树莓派的mac)
{
"bridge": {
"name": "Homebridge",
"username": "XX:XX:XX:XX:XX:XX",
"port": 51826,
"pin": "123-45-678"
},
"platforms": [
{
"platform": "HomeAssistant",
"name": "HomeAssistant",
"host": "http://127.0.0.1:8123",
"password": "raspberry",
"supported_types": ["binary_sensor", "climate", "cover", "device_tracker", "fan", "input_boolean", "light", "lock", "media_player", "remote", "scene", "sensor", "switch"]
}
]
}
#将homebridge设置成随系统启动
cd /
sudo useradd --system homebridge
sudo mkdir /var/homebridge
sudo cp ~/.homebridge/config.json /var/homebridge/
sudo cp -r ~/.homebridge/persist /var/homebridge
sudo chmod -R 0777 /var/homebridge
cd /etc/default
sudo nano homebridge
#将下面的内容复制粘贴进去,然后Ctrl+X,然后Y,回车,保存退出
HOMEBRIDGE_OPTS=-U /var/homebridge
# Defaults / Configuration options for homebridge
# The following settings tells homebridge where to find the config.json file and where to persist the data (i.e. pairing and others)
# If you uncomment the following line, homebridge will log more
# You can display this via systemd's journalctl: journalctl -f -u homebridge
# DEBUG=*
#分界线
cd /etc/systemd/system
sudo nano homebridge.service
#将下面的内容复制粘贴进去,然后Ctrl+X,然后Y,回车,保存退出
[Unit]
Description=Node.js HomeKit Server
After=syslog.target network-online.target
[Service]
Type=simple
User=homebridge
EnvironmentFile=/etc/default/homebridge
ExecStart=/usr/lib/node_modules/homebridge/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target
#分界线
cd /
sudo systemctl daemon-reload
sudo systemctl enable homebridge
sudo systemctl start homebridge
sudo systemctl status homebridge
#安装Samba(强烈建议安装,方便远程文件访问)
sudo hassbian-config install samba
#安装MQTT(安装后会要求输入用户名和密码)
sudo hassbian-config install mosquitto
#按需求安装HDMI CEC功能
sudo hassbian-config install libcec
#重启树莓派
sudo reboot
#修改homebridge参数(备用)
sudo systemctl stop homebridge
cd /var/homebridge
sudo nano config.json
sudo reboot
|