Home Assistant

安装过程

Update the system

sudo apt-get update

Install the packages

sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev

Install python

wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
tar xzvf Python-3.6.5.tgz
cd Python-3.6.5/
./configure
make
sudo make install



Cleanup

sudo rm -r Python-3.6.5
rm -f Python-3.6.5.tgz
sudo apt-get --purge remove build-essential tk-dev
sudo apt-get --purge remove libncurses5-dev libncursesw5-dev libreadline6-dev
sudo apt-get --purge remove libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev
sudo apt-get --purge remove libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev
sudo apt-get autoremove
sudo apt-get clean

Home Assistant

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python3-pip python3-dev
sudo pip3 install --upgrade virtualenv
sudo adduser --system homeassistant
sudo addgroup homeassistant
sudo usermod -G dialout -a homeassistant
sudo mkdir /srv/homeassistant
sudo chown homeassistant:homeassistant /srv/homeassistant
sudo su -s /bin/bash homeassistant
sudo su -s /bin/bash homeassistant
cd /srv/homeassistant
python3.6 -m venv .
source bin/activate
pip3 install --upgrade homeassistant

Home Assistant系统服务

su -c 'cat <<EOF >> /etc/systemd/system/home-assistant@homeassistant.service
[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=homeassistant
ExecStartPre=source /srv/homeassistant/bin/activate
ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant"

[Install]
WantedBy=multi-user.target
EOF'
systemctl --system daemon-reload
systemctl enable home-assistant@homeassistant
systemctl start home-assistant@homeassistant

MQTT

sudo apt-get install libwebsockets-dev
useradd mosquitto
cd /var/lib/
mkdir mosquitto
chown mosquitto:mosquitto mosquitto
cd /srv/homeassistant/homeassistant/src
curl -O http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
apt-key add mosquitto-repo.gpg.key
cd /etc/apt/sources.list.d/
curl -O http://repo.mosquitto.org/debian/mosquitto-jessie.list
apt-get update
apt-cache search mosquitto
apt-get install -y mosquitto mosquitto-clients
cd /etc/mosquitto
touch pwfile
chown mosquitto: pwfile
chmod 0600 pwfile
sudo mosquitto_passwd -b pwfile pi raspberry
sudo chown mosquitto: mosquitto.conf

Homebridge

sudo apt-get install libavahi-compat-libdnssd-dev
npm install -g node-gyp
npm install -g --unsafe-perm homebridge hap-nodejs
cd /usr/local/lib/node_modules/homebridge/
sudo npm install --unsafe-perm bignum
cd /usr/local/lib/node_modules/hap-nodejs/node_modules/mdns
sudo node-gyp BUILDTYPE=Release rebuild
npm install -g homebridge-homeassistant
sudo npm upgrade -g homebridge-homeassistant

Homebridge系统服务

su -c 'cat <<EOF >> /etc/systemd/system/homebridge.service
[Unit]
Description=Node.js HomeKit Server
After=syslog.target network-online.target

[Service]
Type=simple
User=homebridge
EnvironmentFile=/etc/default/homebridge
ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-failure
RestartSec=10
KillMode=process

[Install]
WantedBy=multi-user.target
EOF'

常见问题

安装报错

sudo apt-get build-dep python3-lxml
pip install -U setuptools pip

GPIO问题

sudo usermod -G gpio -a homeassistant

声音问题

sudo usermod -G audio -a homeassistant

PyXiaomiGateway安装错误

pip3 install --upgrade setuptools

蓝牙问题

sudo atp-get install libbluetooth-dev

postgresql

sudo apt-get install libpq-dev