智慧家庭 - HA(1) - 在樹莓派上架設(shè) Home Assistant

本文索引:

Home Assistant 簡(jiǎn)介

Home Assistant(以下簡(jiǎn)稱 HA) 是一個(gè)開源的智能家居網(wǎng)關(guān)項(xiàng)目,它可以將市面上所有支持的智能硬件設(shè)備整合到一起進(jìn)行統(tǒng)一管理,并提供了默認(rèn)的 Web UI。HA 社區(qū)開發(fā)了海量組件以支持市面上主流的設(shè)備,在 IoT 中扮演了大腦的角色。在家庭服務(wù)器上架設(shè) HA 有多種實(shí)現(xiàn)方式,官方也制作了對(duì)應(yīng)的系統(tǒng)鏡像 Hass.io,并推薦使用「樹莓派3B+」作為其宿主機(jī)器。

前提條件

為了驗(yàn)證預(yù)期效果,最好提前準(zhǔn)備好以下設(shè)備:

安裝 Home Assistant

通過 Docker Image 安裝及更新一種服務(wù)免去了為該服務(wù)準(zhǔn)備依賴環(huán)境的繁瑣步驟,HA 官方推出了對(duì)應(yīng)的 Docker Image 且支持樹莓派的 CPU 架構(gòu),本文主要介紹通過 Docker 安裝 HomeAssistant。如果你不喜歡 Docker,可以參考 Install Home Assistant 以其他方式安裝。

拉取 HomeAssistan Docker Image

使用 Docker 安裝 HA 是非常簡(jiǎn)單的,官方提供了支持 Raspberry Pi 3Docker Image 和「安裝指南」:

$ docker run -d --name="home-assistant" -v /path/to/your/config:/config -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/raspberrypi3-homeassistant

參數(shù) /path/to/your/config:/config 映射 container/config 至本地主機(jī)的物理路徑,此處我選擇了 ~/.homeassistant。如果希望安裝指定版本的 Image,參考「HA 在 Docker Hub 上的 Tag 列表」選擇版本,例如 0.69.1:

$ docker run -d --name="home-assistant" -v ~/.homeassistant:/config -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/raspberrypi3-homeassistant

Unable to find image 'homeassistant/raspberrypi3-homeassistant:0.69.1' locally
0.69.1: Pulling from homeassistant/raspberrypi3-homeassistant
95d54dd4bdad: Pull complete
72bf7d76c392: Pull complete
9620ed938a4f: Pull complete
a16372392f2e: Pull complete
cd5a28710c58: Downloading [===================================>               ]  2.695MB/3.766MB
9b376789f5cb: Downloading [====>                                              ]   1.49MB/16MB
428cd24e8c1b: Download complete
3e7ded663f3a: Downloading [=>                                                 ]  45.59kB/2.24MB
5ad200a39e9a: Waiting
47c50281d4f4: Waiting
34a35918edbb: Waiting
ff968d62969e: Waiting
88d8e837fc65: Waiting
0048f1b252d1: Waiting
fe24e50f4c0c: Waiting
8a894406a1f7: Waiting
c521d5fa0262: Waiting
b87db931bad3: Waiting
faa8f2005c47: Waiting
0316d5cde9e4: Waiting
aca6725ed6a1: Waiting

# ...Docker 正從遠(yuǎn)程拉取所需的 image...

Digest: sha256:76d8f1dee1d372fee469f688275854865e12ca662d4090800bb1a3ea5cefdf0f
Status: Downloaded newer image for homeassistant/raspberrypi3-homeassistant:0.69.1
c360dbc77bede87b4eae2210d7b2df11c80f13a5acb227feaf53b3b8554ef2cd

安裝完成后,HomeAssistantcontainer 已經(jīng)開始運(yùn)行:

$ docker ps

CONTAINER ID        IMAGE                                             COMMAND                  CREATED             STATUS              PORTS               NAMES
c360dbc77bed        homeassistant/raspberrypi3-homeassistant:0.69.1   "/usr/bin/entry.sh p…"   5 minutes ago       Up 5 minutes                            home-assistant

查看剛剛指定的配置文件目錄,出現(xiàn)了以下文件及目錄:

$ ls -l .homeassistant

-rw-r--r-- 1 root root      2 May 21 03:42 automations.yaml
-rw-r--r-- 1 root root   1800 May 21 03:42 configuration.yaml
-rw-r--r-- 1 root root      0 May 21 03:42 customize.yaml
drwxr-xr-x 2 root root   4096 May 21 03:42 deps
-rw-r--r-- 1 root root      0 May 21 03:42 groups.yaml
-rw-r--r-- 1 root root    106 May 21 03:43 home-assistant.log
-rw-r--r-- 1 root root 126976 May 21 04:11 home-assistant_v2.db
-rw-r--r-- 1 root root      0 May 21 03:42 scripts.yaml
-rw-r--r-- 1 root root    157 May 21 03:42 secrets.yaml
drwxr-xr-x 2 root root   4096 May 21 03:43 tts

config 目錄(此處為 ~/homeassistant/)下的 configuration.yaml 是配置文件的入口點(diǎn),其他由 yaml 為擴(kuò)展名的配置文件均是為了實(shí)現(xiàn)獨(dú)立管理而單獨(dú)分離出來的文件,可在 configuration.yaml 文檔中找到如下入口載入這些配置文件:

  customize: !include customize.yaml
  group: !include groups.yaml
  automation: !include automations.yaml
  script: !include scripts.yaml

8123Web UI 的默認(rèn)端口,嘗試在瀏覽器中輸入 http://{ip-address-to-raspberry}:8123 訪問,得到如下結(jié)果:

成功啟動(dòng)的 Web UI 歡迎頁面

HA 會(huì)自動(dòng)查找接入同一網(wǎng)絡(luò)中的智能設(shè)備,是因?yàn)?configuration.yaml 中默認(rèn)配置了 Discovery 組件:

# Discover some devices automatically
discovery:

接入 HA 的設(shè)備無需打開相應(yīng)的 App 進(jìn)行綁定。

開機(jī)啟動(dòng) HA Container

一切正常之后,每次重啟樹莓派必須手動(dòng)執(zhí)行 docker container start [Container ID]/NAME 的方式來啟動(dòng) HA 服務(wù),我們需要將其做成服務(wù)或加入開機(jī)啟動(dòng)腳本,編輯 /etc/rc.local 文件:

$ sudo nano /etc/rc.local

docker container start home-assistant

該腳本文件具體可參考 RC.LOCAL

重啟樹莓派,HA 開機(jī)啟動(dòng)成功,至此,一個(gè)基本款的家庭 HA 搭建就完成了。

更新 HA

HA 目前仍然在快速迭代中,對(duì)應(yīng)的 Docker Image 也會(huì)同步放出。要更新以 Docker Container 運(yùn)行的 HA 實(shí)例,只要重新拉取最新版本的 Image 即可:


$ docker stop home-assistant
$ docker pull homeassistant/raspberrypi3-homeassistant
$ docker container rm home-assistant
$ docker run -d --name="home-assistant" -v /path/to/your/config:/config -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/raspberrypi3-homeassistant

只要保持 containername 一致,已添加至開機(jī)啟動(dòng)腳本中的代碼在更新完 Image 之后無需更改。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容