HomeAssistant (ubuntu 18 Installation in virtualenv) - HelloMorningStar/HomeAssistant GitHub Wiki

Installation in virtualenv

运行环境:

dell optiplex 3020
操作系统
ubuntu18.04 desktop(运行在SSD)
windows10(运行在SSD)
ubuntu18.04 lts server(运行在HDD)

开篇安装的homeassistant运行在ubuntu18.04 desktop,24小时开机运行还是放在HDD上比较好吧?

偶然看到homeassistant中文官方网站 写得很清楚(相见恨晚),决定试一试(部署一切顺利!我没有配置 Z-Wave。实现开机自动启动hass和frpc)

安装好了之后,常用的指令

切换为homeassistant用户: sudo su -s /bin/bash homeassistant
开启虚拟环境: source /srv/homeassistant/bin/activate
运行: hass hass后面参数
打印错误 sudo journalctl -f -u home-assistant@YOUR_USER | grep -i 'error'

homeassistant 版本0.144.0
python-miio 版本不要自动升级到0.4.5,包括最新的0.5.3(目前使用0.4.0比较正常,新版本会丢失一系列小米的wifi设备)

本篇没有作为home页面,主要是配置外网访问时出现了拒绝连接本地服务器。
问题排查(待测试):
1,frp 是成功的,提示为本地ip拒绝连接。(check-pass)
2,尝试一下http连接?(check-pass)
3,尝试一下htpps连接?...(check-pass)
4,以前配置成功的是ubuntu桌面版本,这次是服务器版本,难道服务器还缺少设置?
以上问题结论是:所有问题都出在SSL密钥和证书上,用这种方法安装的homeassistant对自签名证书不承认,用letsencrypt的证书是可以的。

安装步骤

0,INSTALL SOME DEPENDENCIES

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install python3-pip python3-dev
$ sudo pip3 install --upgrade virtualenv

1,CREATE A HOME ASSISTANT USER & GROUP

$ sudo adduser --system homeassistant
$ sudo addgroup homeassistant
This step is optional, but it’s a good idea to give services like Home Assistant their own user. It gives you more granular control over permissions, and reduces the exposure to the rest of your system in the event there is a security related bug in Home Assistant. This is a reasonably Linux oriented step, and will look different on other operating systems (or even other Linux distributions).
Home Assistant stores its configuration in $HOME/.homeassistant by default, so in this case, it would be in /home/homeassistant/.homeassistant

$ sudo usermod -G dialout -a homeassistant
If you plan to use a Z-Wave controller, you will need to add this user to the dialout group

2,CREATE A DIRECTORY FOR HOME ASSISTANT

$ sudo mkdir /srv/homeassistant
$ sudo chown homeassistant:homeassistant /srv/homeassistant

3,BECOME THE NEW USER

$ sudo su -s /bin/bash homeassistant

4,SET UP THE VIRTUALENV

$ virtualenv -p python3 /srv/homeassistant

5,ACTIVATE THE VIRTUALENV

$ source /srv/homeassistant/bin/activate

6,INSTALL HOME ASSISTANT

(homeassistant)$ pip3 install --upgrade homeassistant

7,RUN HOME ASSISTANT

If you are in the virtualenv, you can just run hass and it will work as normal.

If the virtualenv is not activated, you just use the hass executable in the bin directory mentioned earlier. There is one caveat… Because Home Assistant stores its configuration in the user’s home directory, we need to be the user homeassistant user or specify the configuration with -c.
$ sudo -u homeassistant -H /srv/homeassistant/bin/hass
The -H flag is important. It sets the $HOME environment variable to /home/homeassistant so hass can find its configuration.

UPGRADING HOME ASSISTANT

Upgrading Home Assistant is simple, just repeat steps 3, 5 and 6.

STARTING HOME ASSISTANT ON BOOT

The autostart instructions will work just fine, just be sure to replace /usr/bin/hass with /srv/homeassistant/bin/hass and specify the homeassistant user where appropriate.

补充:开机启动homeassistant和frpc
1)hass
sudo nano /etc/systemd/system/[email protected]

[Unit]
Description=Home Assistant
After=network-online.target

[Service]
Type=simple
User=%i
ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant"

[Install]
WantedBy=multi-user.target

接下来:
sudo systemctl --system daemon-reload
sudo systemctl enable home-assistant@homeassistant
(如果要禁止开机启动: sudo systemctl disable home-assistant@homeassistant)
(如果要现在就启动: sudo systemctl start home-assistant@homeassistant)

2)frpc
sudo nano /etc/systemd/system/frpc@YOUR_USER_NAME.service

[Unit]
Description=frpc
After=network-online.target

[Service]
Type=simple
User=%i
#ExecStart=/usr/local/bin/frpc -c /etc/frp/frpc.ini
ExecStart=/home/YOUR_USER_NAME/frp/frpc -c /home/YOUR_USER_NAME/frp/frpc.ini

[Install]
WantedBy=multi-user.target

sudo systemctl --system daemon-reload
sudo systemctl enable frpc@YOUR_USER_NAME
(如果要禁止开机启动: sudo systemctl disable frpc@YOUR_USER_NAME)
(如果要现在就启动: sudo systemctl start frpc@YOUR_USER_NAME)

try upgrade homeassistant to latest ver. I need more than 20 minutes...

⚠️ **GitHub.com Fallback** ⚠️