本文章在树莓派 ubuntu14 测试可用其他Linux发行版本自行测试

#首先改一下sudoer设置,省得sudo时总要求输密码
sudo nano /etc/sudoers

#在最下面(看好,是此文件的最下方,否则会被下面的设置所覆盖而无效!)添加以下内容(jones改为你的用户名):
jones ALL=NOPASSWD: ALL

#可选项,如果在安装ubuntu时没有更改时区的,使用下面的代码更改时区
sudo dpkg-reconfigure tzdata

#必选项!更换国内源!如果不更换,sudo apt-get update会非常慢
#首先是备份原源地址,然后将虚线间的代码加入sources.list,contrl + x, y 退出
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak
sudo nano /etc/apt/sources.list
---------------------------------------------------------------------------------------------------------
deb http://mirrors.aliyun.com/ubuntu/ yakkety main restricted
deb http://mirrors.aliyun.com/ubuntu/ yakkety-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ yakkety universe
deb http://mirrors.aliyun.com/ubuntu/ yakkety-updates universe
deb http://mirrors.aliyun.com/ubuntu/ yakkety multiverse
deb http://mirrors.aliyun.com/ubuntu/ yakkety-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ yakkety-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ yakkety-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ yakkety-security universe
deb http://mirrors.aliyun.com/ubuntu/ yakkety-security multiverse
---------------------------------------------------------------------------------------------------------

#更新源信息,安装更新
sudo apt-get update && sudo apt-get upgrade -y

#做一些清理工作,安装python3,默认应该是已经安装的
sudo apt-get autoclean
sudo apt-get clean
sudo apt-get purge -y python3-pip
sudo apt-get install python3

#安装PIP
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 ./get-pip.py
sudo apt-get install python3-pip

#安装Python3虚拟环境
sudo apt-get install python3-venv

#添加一个名为homeassistant的用户
sudo useradd -rm homeassistant

#转到/srv目录,建立homeassistant文件夹
cd /srv
sudo mkdir homeassistant

#更改此文件夹的所有者和所属组
sudo chown homeassistant:homeassistant homeassistant

#更换用户
sudo su -s /bin/bash homeassistant

#切换目录,创建并进入虚拟环境
cd /srv/homeassistant
python3 -m venv homeassistant_venv
source /srv/homeassistant/homeassistant_venv/bin/activate

#虚拟环境下安装pip
pip install --upgrade pip

#安装依赖netdisco,理论上直接默认安装即可,但有的Hass版本需要指定1.0.0rc3,则按下面的命令输入
pip3 install netdisco
#pip3 install netdisco==1.0.0rc3

#正式安装HomeAssistant,速度会非常快
pip3 install homeassistant

#安装完毕,退出虚拟环境
exit

#设置开机启动,建立service文件,将#中间的部分拷入,按ctrl + x, y 退出。
sudo nano /etc/systemd/system/home-assistant@homeassistant.service

#########################################################################
[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=homeassistant
Environment=PATH="$VIRTUAL_ENV/bin:$PATH"
ExecStart=/srv/homeassistant/homeassistant_venv/bin/hass -c "/home/homeassistant/.homeassistant"

[Install]
WantedBy=multi-user.target
#########################################################################

#更新系统设置
sudo systemctl daemon-reload

#设置HomeAssistant开机启动
sudo systemctl enable home-assistant@homeassistant.service

#启动HomeAssistant
sudo systemctl start home-assistant@homeassistant.service

#重新启动HomeAssistant
sudo systemctl restart home-assistant@homeassistant.service

#查看HomeAssistant状态
sudo systemctl status home-assistant@homeassistant.service

本教程转自瀚思彼岸论坛!!如有其他需要请自行百度瀚思彼岸

参与评论