1. 程式人生 > >在OrangePI上搭建homeassitant過程記錄

在OrangePI上搭建homeassitant過程記錄

1.更換Python版本

由於在新版的homeassistant當中需要使用python3.5.3及以後的版本,但由於apt源中只包含3.5.2的版本,所以需要升級到python3.6。

具體更換方式:

sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6 python3.6-venv python3.6-dev

具體可參考:https://github.com/home-assistant/home-assistant/issues/13089

安裝Python3.6的pip【2】:

curl https://bootstrap.pypa.io/get-pip.py | sudo -H python3.6

具體可參考:https://github.com/home-assistant/home-assistant/issues/13089

關於更換到國內映象:

pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

具體可參考:https://mirror.tuna.tsinghua.edu.cn/help/pypi/

更換預設python版本:

sudo
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2 sudo update-alternatives --config python3

具體可參考:https://blog.csdn.net/s_lisheng/article/details/78296177

2.homeassistant的安裝

具體的安裝過程可參考:https://juejin.im/post/5a74a2515188257a814ce254

cd /home/pi/Desktop && python3 -m venv homeassistant
cd homeassistant
source bin/activate
python3 -m pip install wheel
python3 -m pip install homeassistant
hass --open-ui

3.設定自啟動

1.建立 home-assistant.service ,並放入以下內容 sudo vim /etc/systemd/system/home-assistant.service

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

[Service]
Type=simple
User=pi
Environment=PATH="$VIRTUAL_ENV/bin:$PATH"
ExecStart=/home/pi/Desktop/homeassistant/bin/hass -c "/home/pi/.homeassistant"

[Install]
WantedBy=multi-user.target

2.更新系統設定 

sudo systemctl --system daemon-reload

3.設定HomeAssistant開機啟動

sudo systemctl enable home-assistant.service

4.啟動

sudo systemctl start home-assistant.service

 

常見錯誤資料:

Fix ‘E: Could not get lock /var/lib/dpkg/lock’ Error in Ubuntu [Quick Tip]

缺少ffi.h  sudo apt-get install libffi-dev