山水的智能家居系统搭建

一、搭建方式

目前主要有四种,不用再看了,比较了很多遍,直接选用OS方式吧,缺点是这个虚拟机就只能跑HASS这一个功能了,但是稳定性强胜过一切
在这里插入图片描述
威联通VirtualizationStation安装HassOS
以虚拟机方式安装HassOS。无论windows、linux、群晖、unraid系统,只要是支持虚拟机的x86主机都可以采用这种方式安装。

第一步:下载HassOS镜像压缩包

有OVA版本的直接下载OVA的,版本转化用不了
github下载地址:

https://github.com/home-assistant/operating-system/releases

选择 hassos_ova-5.13.vmdk.xz

下载HassOS镜像压缩包下载HassOS镜像压缩包

百度网盘下载链接https://pan.baidu.com/s/1meLrpaDYqgyNGA3h1CNdNw,提取码:wcys

第二步:解压镜像文件并导入NAS

文件解压后格式为VMDK,常见的VMware虚拟机创建的虚拟硬盘格式,文件大小为1.61GB。

解压镜像文件并导入NAS解压镜像文件并导入NAS

第三步:转换镜像格式

使用映像转换器将文件由vmdk格式转换为img格式。打开VirtualizationStation,打开转换器,选择源文件和转换后镜像位置。点击确定后,系统后台运行。转换耗时3分钟。

打开映像转换器打开映像转换器

选择源文件和转换后镜像位置选择源文件和转换后镜像位置

系统后台执行转换任务系统后台执行转换任务

第四步:建立HassOS虚拟机

1.点击建立,进入参数配置界面,设置虚拟机名称。

2.操作系统选择linux。HassOS是基于debian的,但版本里没有debian选项,我就随意选择了个Ubuntu版本,个人猜测版本选择应该影响不大的。

3.启动固件一定要选UEFI,一定要选UEFI,一定要选UEFI。

4.cpu和内存参数随意,1核2G是够用的。

5.使用现有镜像,选择转换好的img文件,点击确定。

HassOS虚拟机参数配置HassOS虚拟机参数配置

第五步:打开HassOS虚拟机

虚拟机开机,打开远程桌面,直到显示homeassistant login: 即为虚拟机开启成功。关闭远程桌面,虚拟机列表出现HassOS虚拟机ip地址。

HassOS虚拟机未开启状态HassOS虚拟机未开启状态

远程桌面显示登录即为开启成功远程桌面显示登录即为开启成功

HassOS虚拟机开启后状态HassOS虚拟机开启后状态

第六步:等待

ip:8123即可打开hass界面。等待20分钟。

首次启动耗时较长首次启动耗时较长

第七步:创建账户,进入hass管理界面

出现创建账户界面,设置姓名、用户名和密码。用户名最好为英文。

创建账户创建账户

下一步设置位置、时区、海拔等。

设置位置、时区等信息设置位置、时区等信息

再下一步,点击完成。

默认,下一步默认,下一步

进入hass管理界面。注意左下角有Supervisor。

hassos界面hassos界面

第八步 修改hosts

https://www.bilibili.com/video/BV1X34y1q76k/?spm_id_from=333.788

虚拟机进入终端,输入login
vi /etc/hosts
加入三行
i

140.82.114.4                  github.com
185.199.108.153               github.io
185.199.108.133               githubusercontent.com

esc
:wq
reboot

二、安装HACS-比较繁琐

https://www.bilibili.com/video/BV1Hz4y1k7PE?spm_id_from=333.999.0.0

三、让HACS更好的工作-失败

安装Portainer插件

开启高级模式
在这里插入图片描述
安装Portainer 插件 并禁用保护模式
在这里插入图片描述

管理portainer

关闭隐藏containers
在这里插入图片描述
分别连接 superviser 和 homeassistant 的控制台
在这里插入图片描述
输入
vi /etc/hosts
优化github 优化

140.82.114.4 github.com
140.82.114.10 nodeload.github.com
140.82.114.6 api.github.com
140.82.114.10 codeload.github.com
185.199.108.133 raw.github.com
185.199.108.153 training.github.com
185.199.108.153 assets-cdn.github.com
185.199.108.153 documentcloud.github.com
185.199.108.154 help.github.com

# domain: githubstatus.com
185.199.108.153 githubstatus.com

# domain: fastly.net
199.232.69.194 github.global.ssl.fastly.net

# domain: githubusercontent.com
185.199.108.133 raw.githubusercontent.com
185.199.108.154 pkg-containers.githubusercontent.com
185.199.108.133 cloud.githubusercontent.com
185.199.108.133 gist.githubusercontent.com
185.199.108.133 marketplace-screenshots.githubusercontent.com
185.199.108.133 repository-images.githubusercontent.com
185.199.108.133 user-images.githubusercontent.com
185.199.108.133 desktop.githubusercontent.com
185.199.108.133 avatars.githubusercontent.com
185.199.108.133 avatars0.githubusercontent.com
185.199.108.133 avatars1.githubusercontent.com
185.199.108.133 avatars2.githubusercontent.com
185.199.108.133 avatars3.githubusercontent.com
185.199.108.133 avatars4.githubusercontent.com
185.199.108.133 avatars5.githubusercontent.com
185.199.108.133 avatars6.githubusercontent.com
185.199.108.133 avatars7.githubusercontent.com
185.199.108.133 avatars8.githubusercontent.com
# End of the section

本应就好了的,但实际上还是无法现在,在配置-日志中看到,连不上raw.githubusercontent.com

四、hasibian方法使用HACS

没有科学上网环境?无法访问github?无法从HACS商店下载插件和加载项?无法更新插件?下面手把手教你设置,无需科学上网,一劳永逸。

一、修改默认下载源(此方法参考Anlong大神)
原理:此方法为自动修改HA目录下download.py文件中下载源:/config/custom_components/hacs/helpers/functions/download.py

  1. 下载附件,把文件replace_hacs_download_mirror.sh放到HA主目录/config下(和configuration.yaml文件同一个目录)
# Run this file with sh command in HA docker to auto REPLACE the github download website in HACS download.py file /config/custom_components/hacs/helpers/function/download.py
# Script by chuixue
#! /bin/bash

# The following is the default download.py file path. Change it if yours is not the current path.
download_py_path="/config/custom_components/hacs/helpers/functions/download.py"

# Delete the old lines if it is available
sed  -i '/url = url.replace("raw.githubusercontent.com", "raw.fastgit.org")/,/url = url.replace("\/\/github.com\/", "\/\/hub.fastgit.org\/")/d' $download_py_path


# Add the new lines
sed -i '/if "tags\/" in url:/i\    url = url.replace("raw.githubusercontent.com", "raw.fastgit.org")\n    if "releases/download/" in url or "archive/refs/" in url:\n        url = url.replace("//github.com/", "//hub.fastgit.org/")' $download_py_path

2022年1月9日后版本,该文件换为以下:

# Run this file with sh command in HA docker to auto REPLACE the github download website in HACS download.py file /config/custom_components/hacs/helpers/function/download.py
# Script by chuixue
#! /bin/bash

# The following is the default HACS download URL file path. Change it if yours is not the current path
ha_path="/config"
github_com_mirror="hub.fastgit.org"
raw_githubusercontent_com_mirror="raw.fastgit.org"


#######
ha_path=$(cd ${
    
    ha_path}; pwd)
old_download_url_path="${ha_path}/custom_components/hacs/helpers/functions/download.py"
new_download_url_path="${ha_path}/custom_components/hacs/base.py"

if [ -f "${old_download_url_path}" ]; then
  download_url_path=${
    
    old_download_url_path}
  url_blank="    "
else
  download_url_path=${
    
    new_download_url_path}
  url_blank="        "
fi

# Delete the old lines in hacs url file if it is available
sed  -i '/url = url.replace("raw.githubusercontent.com", "'"${raw_githubusercontent_com_mirror}"'")/,/url = url.replace("\/\/github.com\/", "\/\/'"${github_com_mirror}"'\/")/d' $download_url_path


# Add the new lines in hacs url file
sed -i '/if "tags\/" in url:/i\'"${url_blank}"'url = url.replace("raw.githubusercontent.com", "'"${raw_githubusercontent_com_mirror}"'")\n'"${url_blank}"'if "releases/download/" in url or "archive/refs/" in url:\n'"${url_blank}"'    url = url.replace("//github.com/", "//'"${github_com_mirror}"'/")' $download_url_path




  1. 为防止HACS更新后download.py文件被覆盖,需设置HA启动后,自动更新HACS下载源:
    在/config/packages 文件夹(没有这个文件夹就新建一个)下新建文件update_hacs_download_source.yaml,内容如下:
shell_command:
  update_hacs_download_source: sh /config/replace_hacs_download_mirror.sh
  
automation:
  - alias: HA启动自动更新HACS下载源
    trigger:
      - platform: homeassistant
        event: start
    action:
      - service: shell_command.update_hacs_download_source

在configuration.yaml中添加如下代码,让packages文件夹被识别:

homeassistant:
  packages: !include_dir_named packages
  1. 重启homeassistant 生效

二、设置定时自动更新docker中hosts文件
2021年11月9日更新,从更改宿主机hosts文件,变为更改docker中HA容器的hosts,之前下载老版本的,此部分请重新配置
感谢原作者提供的hosts更新服务:github hosts更新地址

  1. 把附件中github_docker_hosts_update.sh文件放到HA主目录/config下(和configuration.yaml文件同一个目录)
#! /bin/bash
# github mirror updating script written by chuixue
# mirror source from: https://github.com/521xueweihan/GitHub520

# get the new hosts from the internet. You can change the source if you have a better one.
curl 'https://raw.hellogithub.com/hosts' > github_hosts.log

# remove the lines between "github hosts start" and "github hosts end" in /etc/hosts
echo "$(sed '/# github hosts start; Do not remove or change this line/,/# github hosts end; Do not remove or change this line/d' /etc/hosts)" > /etc/hosts

# add the start and end lines
sh -c 'echo "# github hosts start; Do not remove or change this line
# github hosts end; Do not remove or change this line" >> /etc/hosts'

# insert the new hosts into /etc/hosts
echo "$(sed '/# github hosts start; Do not remove or change this line/r github_hosts.log' /etc/hosts)" > /etc/hosts


  1. 在/config/packages 文件夹(参考上面步骤一)下新建文件update_github_docker_hosts.yaml,内容如下:
shell_command:
  update_github_docker_hosts: sh /config/github_docker_hosts_update.sh

automation:
  - alias: HA启动或每两小时自动更新docker中github的hosts
    trigger:
      - platform: homeassistant
        event: start
      - platform: time_pattern
        hours: "/2"
    action:
      - service: shell_command.update_github_docker_hosts
  1. 重启homeassistant生效

三、添加社区商店add-ons(只有hassos/hassio/supervised版本才有add-on商店):
HACS-加载项-加载项商店-右上角添加新的repo,地址填:https://hub.fastgit.org/hassio-addons/repository
注意,上面添加的地址为国内github的镜像,不推荐使用官方github地址,否则因网络不好社区商店插件可能经常会自动消失

社区repo添加成功

官方加载项商店无法加载的问题请参考:https://bbs.hassbian.com/thread-14916-1-1.html

建议还是连个手机什么的

五、设置反向代理通过

进入配置文件
添加

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 172.17.0.1 //frpc地址

猜你喜欢

转载自blog.csdn.net/shenchen2010/article/details/122102991