一鍵部署Home Assistant ubuntu 20.4.3 樹莓派3b+腳本


 
樹莓派3b+安裝好 Ubuntu Server 20.04.3 LTS 32bit 后即可適用此腳本,其他版本樹莓派/系統可能需要微調腳本
*為方便一些未知/已知錯誤排查 腳本存在
冗余部分,足夠了解linux的可自行精簡,Y/N在需要時手動鍵入
下面HA驅動處根據需要修改
# 樹莓派3b+安裝好 Ubuntu Server 20.04.3 LTS 32bit 后即可適用此腳本,其他版本樹莓派/系統可能需要微調腳本
# 下面HA驅動處根據需要修改
# author: bright

# docker安裝 # 更新源
cat>/etc/apt/sources.list<<EOF deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main non-free contrib deb [arch=armhf] https://download.docker.com/linux/ubuntu focal stable # deb-src [arch=armhf] https://download.docker.com/linux/ubuntu focal stable

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

EOF

# 服務密鑰重置
gpg --keyserver  keyserver.ubuntu.com --recv-keys 9165938D90FDDD2E
gpg --export --armor  9165938D90FDDD2E | sudo apt-key add -
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository    "deb [arch=armhf] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
sudo apt-get update && sudo apt-get upgrade 
# 安裝步驟
sudo apt-get install docker-ce
apt-get install docker.io
apt-get install runc >= 1.0.0
apt install docker

# docker拉取&&安裝homeassistant
docker pull homeassistant/raspberrypi3-homeassistant


# 啟動homeassistant
docker run -d --name homeassistant -p 8123:8123 homeassistant/raspberrypi3-homeassistant

# 配置HA自啟動
# 獲取容器id
cid=$(docker ps -a|grep "homeassistant" | awk '{print $1}')
echo $cid
# 添加homeassistant自啟動配置文件
touch /etc/init.d/homeassistant.sh
cat>/etc/init.d/homeassistant.sh<<EOF
#!/bin/bash
docker restart $cid
exit 0
EOF
touch /etc/rc.local
cat>/etc/rc.local<<EOF
#!/bin/bash
docker restart $cid
exit 0
EOF
# 權限+自啟
chmod 755 /etc/rc.local
chmod 755 /etc/init.d/homeassistant.sh
update-rc.d homeassistant.sh defaults 90

# homeassistant配置Xiaomi_gateway3 和 air_condition驅動
# 進入容器


# 如需直接跑跳到終端不運行可將下面命令新建一個setup.sh 腳本
# docker exec -it $cid /bin/bash
#
docker ps -a 可以拿到cid
# touch setup.sh # 復制下面這些命令到腳本中在ha container中跑 # vi setup.sh # bash setup.sh


# 驅動相關
# 進行驅動拉取 docker restart $cid docker exec -i $cid mkdir custom_components docker exec -i $cid cd custom_components docker exec -i $cid mkdir bak docker exec -i $cid cd bak # XiaomiGateway3 docker exec -i $cid git clone https://github.com/AlexxIT/XiaomiGateway3 docker exec -i $cid cp -r XiaomiGateway3/custom_components/xiaomi_gateway3 ../../custom_components/ # 01 02 11LM 空調伴侶驅動 docker exec -i $cid git clone https://github.com/syssi/xiaomi_airconditioningcompanion.git docker exec -i $cid cp -r xiaomi_airconditioningcompanion/custom_components/xiaomi_miio_airconditioningcompanion ../../custom_components/ # 如需其他驅動仿照此中方式添加進來 # 修改yaml主配置文件 docker exec -i $cid cd /config && mv configuration.yaml configuration.bak docker exec -i $cid touch configuration.yaml docker exec -i $cid cat>configuration.yaml<<EOF # Configure a default setup of Home Assistant (frontend, api, etc) default_config: # Text to speech tts: - platform: google_translate group: !include groups.yaml automation: !include automations.yaml script: !include scripts.yaml scene: !include scenes.yaml climate: - platform: xiaomi_miio_airconditioningcompanion name: Aqara Air Conditioning Companion host: 192.168.1.xx # 需要修改空調伴侶的ip token: xx # 修改空調伴侶對應的token target_sensor: sensor.temperature_158d0001f53706 scan_interval: 60 EOF docker exec -i $cid exit

apt install ntpdate
ntpdate us.pool.ntp.org

reboot

 

其他home assistant iot參考:

https://www.cnblogs.com/cutesnow/p/15511959.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM