在既有的Raspberry Pi上安裝Home Assistant
Last updated on August 24, 2024 am
當已經有Pi在運行時,HomeAssistant推薦的整個SD卡安裝就不太合理。
這篇是將 Raspberry Pi 加裝 HomeAssistant 的筆記。
環境:
- Raspberry Pi up and running
第一步 更新Pi
1 |
|
更新後,目前Pi的版本是:
1 |
|
第二步 開HomeAssistant專屬的帳號
1 |
|
設個密碼
1 |
|
第三步 安裝HomeAssistant所需軟體
1 |
|
HomeAssistant 是用python的virtual environment:
1 |
|
設置homeassistant的.bashrc,登入就進入vd
1 |
|
加進這一行:
1 |
|
試試看:
1 |
|
應該會看到prompt變成:
1 |
|
第四步 安裝HomeAssistant
用homeassistant的身份登入,
1 |
|
然後安裝:
1 |
|
安裝需要等一下。
完成後可以手動測試:
1 |
|
CTRL-C 可跳出。
第五步 將 HomeAssistant 安裝成服務
將 HomeAssistant 安裝成服務步驟如下:
從pi user su 為 root user
1
sudo su root
新增服務 script
1
2cd /etc/systemd/system/
vi home-assistant@pi.service內容如下:
1 |
|
- reload 新服務
1 |
|
- 退出root身份
1
exit
第六步 測試
啟動服務:
1
sudo systemctl start home-assistant@pi
停止服務:
1
sudo systemctl stop home-assistant@pi
重啟:
1
sudo systemctl restart home-assistant@pi
服務狀態:
1
sudo systemctl status home-assistant@pi -l
讀log檔
1
sudo journalctl -f -u home-assistant@pi
第七步 更新
1 |
|
update python
download source from official site
Install the required build-tools (some might already be installed on your system).
1
2sudo apt-get update -y
sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -yInstall and compile the Python source
1
2
3tar xf Python-3.x.x.tar.xz
cd Python-3.x.x
./configure; make -j 4; sudo make altinstallReinstall HA
1
2cd /srv/homeassistant
sudo rm homeassistant_venv/update python3 alias to correct version
1
2
3sudo su -s /bin/bash homeassistant
sudo vi ~/.bash_aliasestest:
1
python3
check the version shown.
Reinstall HA (follow 第三步)
Redo the modules
1
2
3
4
5
6sudo su -s /bin/bash homeassistant
pip install hass-nabucasa==0.3
pip install PyNaCl==1.3.0
pip install plexwebsocket==0.0.6
pip install pyatv==0.3.13
References
在既有的Raspberry Pi上安裝Home Assistant
https://mingster.com/2018/01/13/homeassistant_on_existing_pi/