1. 程式人生 > >在 Raspberry Pi安裝Docker,運行Home Assistant

在 Raspberry Pi安裝Docker,運行Home Assistant

config ups ssi syslog mes 智能 groups inf prepare

docker 是個好東西,想著Raspbian 是基於 Debian的系統,那定然是支持 docker的。

而有了docker,再raspberry pi上安裝 Home Assistant就有了一種極其簡單的方法。

1. 在Raspberry Pi 上安裝docker

curl -sSL https://get.docker.com | sh

參考:https://www.raspberrypi.org/blog/docker-comes-to-raspberry-pi/

2. 驗證docker的安裝是否正確

pi@raspberrypi:~ $ sudo docker --version
Docker version 
18.06.0-ce, build 0ffa825
pi@raspberrypi:~ $ sudo docker info
Containers: 3
 Running: 2
 Paused: 0
 Stopped: 1
Images: 2
Server Version: 18.06.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan 
null overlay Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init
...

參考:https://docs.docker.com/get-started/#prepare-your-docker-environment

3. 在Raspberry Pi上基於Docker安裝 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:0.XX.x
註意:
1. /path/to/your/config 指的是你本地的HA配置目錄,用來在本地存放你要運行的 HA 配置,比如  configuration.yaml 等配置文件

2. :/config 這裏的config指的是你 docker 鏡像中HA的配置目錄,如果/path/to/your/config 這個目錄在本地存在,則HA啟動時會讀取本地的配置,入伏哦/path/to/your/config 在本地不存在,則讀取docker鏡像中HA的配置目錄

3. 0.XX.x 指的是要指定的HA版本,比如0.72.0,具體版本可以到HA官網查詢 https://www.home-assistant.io/

實際在本機安裝案例:

mkdir /home/pi/workplace/config -p

sudo
docker run -d --name="home-assistant" -v /home/pi/workplace/config:/config -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/raspberrypi3-homeassistant:0.72.0

安裝成功後驗證

pi@raspberrypi:~ $ sudo docker image ls
REPOSITORY                                 TAG                 IMAGE ID            CREATED             SIZE
homeassistant/raspberrypi3-homeassistant   0.72.0              df8da8840c1d        8 weeks ago         1.06GB

4. 在Raspberry Pi 上啟動Docker中的

homeassistant/raspberrypi3-homeassistant, 註意要指定版本0.72.0,不然docker會提示本地不存在,然後又重新去docker hup去下載
pi@raspberrypi:~ $ sudo docker run -v /home/pi/workplace/config:/config homeassistant/raspberrypi3-homeassistant:0.72.0
starting version 3.2.4
2018-08-18 07:33:44 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=turn_off>
2018-08-18 07:33:44 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=turn_on>
2018-08-18 07:33:44 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=toggle>
2018-08-18 07:33:44 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=stop>
2018-08-18 07:33:44 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=restart>
2018-08-18 07:33:44 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=check_config>
2018-08-18 07:33:44 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=homeassistant, service=reload_core_config>
2018-08-18 07:33:44 INFO (MainThread) [homeassistant.bootstrap] Home Assistant core initialized
2018-08-18 07:33:45 INFO (MainThread) [homeassistant.loader] Loaded frontend from homeassistant.components.frontend
2018-08-18 07:33:46 INFO (MainThread) [homeassistant.loader] Loaded api from homeassistant.components.api2018-08-18 07:33:46 INFO (MainThread) [homeassistant.loader] Loaded introduction from homeassistant.components.introduction
2018-08-18 07:33:46 INFO (MainThread) [homeassistant.setup] Setting up introduction
2018-08-18 07:33:46 INFO (MainThread) [homeassistant.components.introduction] 

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        Hello, and welcome to Home Assistant!

        Well hope that we can make all your dreams come true.

        Here are some resources to get started:

         - Configuring Home Assistant:
           https://home-assistant.io/getting-started/configuration/

         - Available components:
           https://home-assistant.io/components/

         - Troubleshooting your configuration:
           https://home-assistant.io/getting-started/troubleshooting-configuration/

         - Getting help:
           https://home-assistant.io/help/

        This message is generated by the introduction component. You can
        disable it in configuration.yaml.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

5. 登陸HAweb查看

http://192.168.1.x:8123

註意: 該ip是裝docker的宿主ip,也就是你的本機ip

6. 修改配置文件,定制你喜歡的智能家居系統

pi@raspberrypi:~/workplace/config $ ls /home/pi/workplace/config
automations.yaml  configuration.yaml  customize.yaml  deps  groups.yaml  home-assistant_v2.db  scripts.yaml  secrets.yaml  tts

在 Raspberry Pi安裝Docker,運行Home Assistant