HASSHOME

debian11安装python虚拟容器版本homeassistant代码

1031
发表时间:2022-12-03 17:29

1、更换国内源:

更改软件源文件权限:

sudo chmod 777 /etc/apt/sources.list

更新软件源:

sudo apt-get update

sudo apt-get upgrade -y


2、安装依赖:

sudo apt-get install -y python3 python3-dev python3-venv python3-pip bluez libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 libturbojpeg0-dev tzdata


3、新建账户:

sudo useradd -rm homeassistant

sudo mkdir /srv/homeassistant

sudo chown homeassistant:homeassistant /srv/homeassistant


4、新建虚拟容器并安装homeassistant

sudo -u homeassistant -H -s

cd /srv/homeassistant

python3 -m venv .

source bin/activate

python3 -m pip install wheel

pip3 install homeassistant -i https://pypi.tuna.tsinghua.edu.cn/simple


5、访问网页

127.0.0.1:8123


6、设置开机自启动:

(1)新建服务:

sudo nano /etc/systemd/system/home-assistant@homeassistant.service

(2)代码
[Unit]

Description=Home Assistant

After=network-online.target

[Service]

Type=simple

User=%i

WorkingDirectory=/home/%i/.homeassistant

ExecStart=/srv/homeassistant/bin/hass -c "/home/%i/.homeassistant"

RestartForceExitStatus=100

[Install]

WantedBy=multi-user.target

(3)启动服务

sudo systemctl --system daemon-reload

sudo systemctl enable home-assistant@homeassistant