构建homeassistant + homebridge 智能家居系统

需要提前安装的依赖

python3.6.5(或更新版本)
pip3
libffi-devel
zlib1g 
zlib1g-devel
python3-pip
libavahi-compat-libdnssd-dev
git

安装Homeassistant

安装pip

$ sudo pip3 install -U pip

安装python虚拟环境

$ sudo pip3 install virtualenv

添加用户

$ sudo useradd -rm homeassistant
$ sudo mkdir /srv/homeassistant
$ sudo chown homeassistant:homeassistant /srv/homeassistant

切换用户

$ sudo su -s /bin/bash homeassistant

创建虚拟运行环境并进入

$ virtualenv -p python3 /srv/homeassistant
$ source ./homeassistant/bin/activate

安装依赖

$ pip3 install netdisco

安装homeassistant

$ pip3 install -U homeassistant

[注意]
如果安装中出现“the ssl module in Python is not available”错误,则需要安装libssl-dev和openssl依赖包,并重新编译安装python3(3.5.3以上)。配置编译时添加–with-ssl参数。

安装homebridge

安装curl

$ sudo apt-get install -y curl

添加安装源

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

如果安装速度慢可以改成国内源

$ sudo nano /etc/apt/sources.list.d/nodesource.list

添加

deb https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_7.x xenial main
deb-src https://mirrors.tuna.tsinghua.edu.cn/nodesource/deb_7.x xenial main )

安装nodejs

$ sudo apt-get update
$ sudo apt-get install -y nodejs

安装homebridge

$ sudo npm install -g --unsafe-perm homebridge

安装中间件

$ sudo npm install -g homebridge-homeassistant

[注意]
如果是用手机Linux Deploy搭建的系统,需要以下额外步骤:
将 /etc/avahi/avahi-daemon.conf 文件中publish部分所有参数都注释掉
将/etc/init.d/avahi-daemon 文件中d_start() 部分 $DAEMON 后面添加 --no-drop-root 参数

启动homebridge需要先启动两个服务

$ sudo /etc/init.d/dbus start
$ sudo /etc/init.d/avahi-daemon start

添加homebridge用户

$ sudo useradd -rm homebridge
$ sudo mkdir /var/opt/homebridge
$ sudo cp -R ~/.homebridge/* /var/opt/homebridge
$ sudo chown -R homebridge:homebridge /var/opt/homebridge

安装mqtt

sudo apt-get install -y mosquitto mosquitto-clients

(测试运行:
订阅主题:mosquitto_sub -h localhost -t hello/world -u username -P password
发布主题:mosquitto_pub -h localhost -t hello/world -m “HELLO” -u username -P password

配置文件 /etc/mosquitto/mosquitto.conf

allow_anonymous 允许匿名
password_file 密码文件
acl_file 访问控制列表

添加用户和密码

$ sudo chown mosquitto:mosquitto mosquitto.conf
$ sudo touch pwfile
$ sudo mosquitto_passwd -b pwfile "username" "password"
$ sudo chown mosquitto:mosquitto pwfile
$ sudo chmod u+rw pwfile

启动mqtt

$ sudo /etc/init.d/mosquitto start

修改homeassistant配置文件

$ vi /home/homeassistant/.homeassistant/configuration.yaml

添加

mqtt:
  broker: xxx.xxx.xxx.xxx
  port: 1883
  username: 
  password: 

broker为本机IP地址

修改homebridge配置文件

$ vi /var/opt/homebridge/config.json

添加

{
 "bridge": {
 "name": "Homebridge",
 "username": "xx:xx:xx:xx:xx:xx",
 "port": 51826,
 "pin": "123-45-678"
},

"platforms": [
 {
 "platform": "HomeAssistant",
 "name": "HomeAssistant",
 "host": "http://xxx.xxx.xxx.xxx:8123",
 "password": "",
 "supported_types": ["automation", "binary_sensor", "climate", "cover", "device_tracker", "fan", "group", "input_boolean", "light", "lock", "media_player", "remote", "scene", "sensor", "switch"],
 "default_visibility": "visible"
 }
]
}

username为设备mac地址

你可能感兴趣的:(IOT,Homeassistant)