搭建homebridge的部分

#先更新和升级当前环境

sudo apt-get update

sudo apt-get -y upgrade

-------------------------

#安装三个系统组件 screen ,samba, git

sudo apt-get install screen

sudo apt-get install samba

sudo apt-get install git

--------------------------

sudo apt-get install git make

sudo apt-get install g++

curl -sL https://deb.nodesource.com/setup_7.x |sudo -E bash -

sudo apt-get install nodejs=v7.x

#安装必要的依赖包

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

#安装homebridge,hap-nodejs , node-gyp

sudo npm install -g --unsafe-perm homebridge hap-nodejs node-gyp

sudo npm install -g homebridge-homeassistant@2.2.1

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

###假如你不是用我上述的方法安装的NodeJS的话,那么很有可能/usr/lib/这个目录会变成/usr/local/lib/。

cd /

#安装与homebridge关联的 homeassistant

sudo npm install -g --unsafe-perm homebridge

sudo npm install -g homebridge-homeassistant

##(摄像头插件)

sudo npm install -g homebridge-ip-camera

###(博联插件)

sudo npm install -g homebridge-broadlink-rm

#####(升级)
#
sudo npm upgrade -g homebridge-homeassistant

#运行homebridge试试看是否正常运行,如果可以正常运行,就ctrl+c退出来

homebridge

cd /home/lyp/.homebridge

#建立config.json的配置文件

sudo nano config.json

#鼠标右键粘贴如下内容

------------------------------
{
"bridge": {
"name": "Homebridge",
"username": "00:0X:2X:CX:9X:X1",
"port": 51826,
"pin": "123-55-888"
},

"platforms": [
{
"platform": "HomeAssistant",
"name": "HomeAssistant",
"host": "http://192.168.1.122:8123",
"password": "rocketer",
"supported_types": ["binary_sensor", "climate", "cover", "fan", "garage_door", "device_tracker", "input_boolean", "light", "lock", "media_player", "rollershutter","sensor", "scene", "switch"]
}
]
}


--------------------------------

上面的内容,注意格式,注意大小写、粘贴完毕后,按键盘上的Ctrl+X键,输入 Y,保存退出。

另外:请注意这几段段代码
"username": "aX:XC:a9:4X:8X:36", ###这个MAC地址大写就可以}
"port": 51826, ###通讯端口,可以修改,但我觉得不用修改###
"pin": "123-22-999" ###PIN码,任意修改,格式是XXX-XX-XXX,只能是数字####

"host": "http://192.168.121.195:8123",
###其中的192.168.121.195是你的树莓派的局域网IP地址####

"password": "mimamima",
###这个是密码,因为我们没有修改Ubuntu的登录密码,所以这里是mimamima####

#再次输入homebridge 回车,检查运行有没有错误
#
#搭建homebridge的部分

#先更新和升级当前环境

sudo apt-get update

sudo apt-get upgrade

####将homebridge设置成随系统启动######
cd /

sudo adduser --system homebridge

sudo mkdir /var/homebridge

sudo cp /home/lyp/.homebridge/config.json /var/homebridge/ (注意使用自己的用户名和路径)

sudo cp -r /home/lyp/.homebridge/persist /var/homebridge

sudo chmod -R 0777 /var/homebridge

cd /etc/default

sudo nano homebridge

#########将下面的内容复制粘贴进去,然后Ctrl+X,然后Y,回车,保存退出####

# 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)
HOMEBRIDGE_OPTS=-U /var/homebridge

# 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

sudo reboot ####重启####

###最后,你想返回去修改PIN码,MAC地址等等参数,可以按以下命令行来做####

sudo systemctl stop homebridge ###停止homebridge运行###

cd /var/homebridge ###进入目录###

sudo nano config.json ###编辑配置文件###

sudo reboot ###重启####

 

参与评论