搭建自己的智能家居系统homeassistant+homebridge

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jc_deng/article/details/80381141

需要安装的软件和依赖:
python3.6.5
pip3
libffi-devel
zlib zlib devel
python3-pip
libavahi-compat-libdnssd-dev
git
homeassistant
homebridge
homeassistant-homebridge


安装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
启动
sudo /etc/init.d/mosquitto start

配置文件:

/home/homeassistant/.homeassistant/configuration.yaml

添加

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

/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"
 }
]
}

猜你喜欢

转载自blog.csdn.net/jc_deng/article/details/80381141