建立文件/etc/systemd/system/homeassistant.service
内容:
[Unit]
Description=Homebridge
#After=home-assistant@homeassistant.service
After=network.target
[Service]
Type=simple
#使用pi用户执行
User=pi
#python3环境激活命令
ExecStartPre=source /home/pi/hass/bin/activate
#homeassistant启动命令
ExecStart=/home/pi/hass/bin/hass
[Install]
WantedBy=multi-user.target
最后生效
sudo systemctl daemon-reload
sudo systemctl enable homeassistant.service