本帖最后由 孤叶寒 于 2020-2-28 19:25 编辑
本文参考(20180630更新)Ubuntu安装HomeAssistant教程(ubuntu17.10无坑版)
https://bbs.hassbian.com/thread-27-1-1.html
#可选项,如果在安装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/ bionic main restricted
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ bionic universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ bionic-security universe
deb http://mirrors.aliyun.com/ubuntu/ bionic-security multiverse
#########################################################################
#更新源信息,安装更新
sudo apt-get update && sudo apt-get upgrade -y
#做一些清理工作
sudo apt-get autoclean
sudo apt-get clean
#安装各种依赖库等
sudo apt install python3.7 python-dev python3.7-dev build-essential libssl-dev libffi-dev
sudo apt install libxml2-dev libxslt1-dev zlib1g-dev python3.7-pip
sudo apt install *python3.7*
#直接安装python3-pip
sudo apt-get install python3-pip
#安装Python3虚拟环境
sudo apt install python3 python3-dev build-essential libssl-dev libffi-dev
sudo apt install libxml2-dev libxslt1-dev zlib1g-dev python3-pip
#添加一个名为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.7 -m venv homeassistant_venv
source /srv/homeassistant/homeassistant_venv/bin/activate
#虚拟环境下更新pip, setuptools(此步非常重要,否则安装HASS时会报错)
pip3.7 install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip3.7 install --upgrade setuptools -i https://pypi.tuna.tsinghua.edu.cn/simple/
#设置pip源为清华源(国内源避免访问不到国外的源而报timeout错)
pip3.7 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
#安装依赖netdisco和warrant(此步非常重要,否则安装完HASS会报discovery等错误)
pip3.7 install netdisco -i https://pypi.tuna.tsinghua.edu.cn/simple/
pip3.7 install warrant -i https://pypi.tuna.tsinghua.edu.cn/simple/
#正式安装HomeAssistant,速度会非常快
pip3.7 install homeassistant -i https://pypi.tuna.tsinghua.edu.cn/simple/
#测试Hass是否安装成功可以详细看看有没有报错
#出现[homeassistant.core] Timer:starting 表示安装成功访问ip:8123即可
#如果打不开网站那就是没安装成功,查看有没有error报错
hass --open-ui
#安装完毕,退出虚拟环境
exit
#设置开机启动,建立service文件,将#中间的部分拷入,按ctrl + x, y 退出。
sudo nano /etc/systemd/system/[email protected]
#########################################################################
[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 [email protected]
#启动HomeAssistant
sudo systemctl start [email protected]
#重新启动HomeAssistant
sudo systemctl restart [email protected]
#查看HomeAssistant状态
sudo systemctl status [email protected]
|