HASS 安裝 Raspberry Pi Home Assistant Setup

sudo apt-get update -y

// 安裝Python
sudo apt-get -y install python3 python3-venv python3-pip libffi-dev

// 增加使用者及目錄
sudo useradd -rm homeassistant -G dialout,gpio
cd /srv/
sudo mkdir homeassistant
sudo chown homeassistant:homeassistant homeassistant/
sudo mkdir /home/homeassistant/.homeassistant
sudo chown homeassistant:homeassistant /home/homeassistant/.homeassistant

// 設定操作環境
sudo su -s /bin/bash homeassistant
cd homeassistant
python3 -m venv homeassistant_venv
source /srv/homeassistant/homeassistant_venv/bin/activate

// 在虛擬環境安裝軟體
python3 -m pip install wheel
python3 -m pip install --user --upgrade requests
sudo pip3 install homeassistant
exit (back to /srv)

設定啟動環境

cd /etc/systemd/system
vi home-assistant.service

// home-assistant.service

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

[Service]
Type=simple
User=homeassistant
ExecStartPre=source /srv/homeassistant/homeassistant_venv/bin/activate
ExecStart=/srv/homeassistant/homeassistant_venv/bin/hass -c "/home/homeassistant/.homeassistant"

[Install]
WantedBy=multi-user.target

系統啟動時自動啟動服務

sudo systemctl --system daemon-reload
sudo systemctl enable home-assistant
sudo systemctl start home-assistant
sudo systemctl status home-assistant

使用web

* 使用瀏覽器進入: http://locahost:8123/

* 啟動Pi GPIO
```
sudo adduser homeassistant gpio
cd /home/assistant/assistantant/
suod vi configuration.yaml
```
* configuration.yaml
```
// 增加開關
switch:
- platform: rpi_gpio
ports:
11: TestLED1
12: TestLED2
```

```
sudo su -s /bin/sh homeassistant // 進入虛擬環境
hass --script check_config
exit
sudo systemctl stop home-assistant
sudo systemctl start home-assistant
//
sudo su -s /bin/bash homeassistant
hasss --script check_config
sudo vim configuration.yaml
```

* 使用 IFTTT
- search maker
- google(Say a simple phrase) -> creeate trigger

```
ifttt:
key:
```