美文网首页
树莓派4B/Raspberry Pi4B 安装Home Assi

树莓派4B/Raspberry Pi4B 安装Home Assi

作者: BohanL | 来源:发表于2022-02-25 10:04 被阅读0次

    参考了官网指南和网络经验https://github.com/home-assistant/supervised-installer

    更新系统源至清华源

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak          #备份源文件
    sudo nano /etc/apt/sources.list                        #编辑源列表
    

    清空文件后,填入以下内容,系统版本为最新树莓派系统(Raspberry Pi4 64bit Bullseye)

    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
    deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
    

    Ctrl+O 写入 Enter确认 Ctrl+X退出

    更换系统源至国内清华源

    sudo cp /etc/apt/sources.list.d/raspi.list  /etc/apt/sources.list.d/raspi.list.bak
    sudo nano /etc/apt/sources.list.d/raspi.list
    

    替换成以下内容

    deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bullseye main
    

    编辑Python-pip来源列表

    sudo nano /etc/pip.conf            #编辑PIP来源列表
    

    清空文件后,填入以下内容:

    [global]
    extra-index-url=https://www.piwheels.org/simple
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    

    Ctrl+O 写入 Enter确认 Ctrl+X退出

    升级系统渠道源
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get dist-upgrade
    
    安装爬虫常用包
    sudo pip install selenium
    sudo pip install pillow
    sudo pip install opencv-python
    sudo pip install onnxruntime
    sudo apt-get install chromium-chromedriver
    
    更换GitHub Hosts,加速操作

    参考GitHub最新hosts (gitee.com)

    sudo nano /etc/hosts
    

    从最后一行加入以下内容

    185.199.108.154 github.githubassets.com
    140.82.112.21   central.github.com
    185.199.108.133 desktop.githubusercontent.com
    185.199.108.153 assets-cdn.github.com
    185.199.108.133 camo.githubusercontent.com
    185.199.108.133 github.map.fastly.net
    199.232.69.194  github.global.ssl.fastly.net
    140.82.113.4    gist.github.com
    185.199.108.153 github.io
    140.82.114.3    github.com
    140.82.113.6    api.github.com
    185.199.108.133 raw.githubusercontent.com
    185.199.108.133 user-images.githubusercontent.com
    185.199.108.133 favicons.githubusercontent.com
    185.199.108.133 avatars5.githubusercontent.com
    185.199.108.133 avatars4.githubusercontent.com
    185.199.108.133 avatars3.githubusercontent.com
    185.199.108.133 avatars2.githubusercontent.com
    185.199.108.133 avatars1.githubusercontent.com
    185.199.108.133 avatars0.githubusercontent.com
    185.199.108.133 avatars.githubusercontent.com
    140.82.112.10   codeload.github.com
    52.217.161.249  github-cloud.s3.amazonaws.com
    52.217.229.65   github-com.s3.amazonaws.com
    52.217.96.28    github-production-release-asset-2e65be.s3.amazonaws.com
    52.217.77.92    github-production-user-asset-6210df.s3.amazonaws.com
    52.217.172.9    github-production-repository-file-5c1aeb.s3.amazonaws.com
    185.199.108.153 githubstatus.com
    64.71.144.202   github.community
    185.199.108.133 media.githubusercontent.com
    

    Ctrl+O 写入 Enter确认 Ctrl+X退出

    安装Home Assistant Core

    先确认你的Python是3.9以上

    先安装依赖包

    sudo apt-get install -y python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 libturbojpeg0-dev tzdata
    

    创建一个用户名为homeassistant,“-rm”参数给与一个系统账号并且建立一个home文件夹下目录。“-G dialout,gpio,i2c”是为了给账号添加dialout, gpio和i2c用户组,方便操控外围设备。

    sudo useradd -rm homeassistant -G dialout,gpio,i2c
    

    我们将创建一个用于安装Home Assistant Core的目录,并将所有者更改为homeassistant帐户。

    sudo mkdir /srv/homeassistant
    sudo chown homeassistant:homeassistant /srv/homeassistant
    

    接下来是为Home Assistant Core创建并更改为虚拟环境。这将作为homeassistant帐户完成。

    sudo -u homeassistant -H -s
    cd /srv/homeassistant
    python3.9 -m venv .
    source bin/activate
    

    激活虚拟环境后(请注意,提示符更改为(homeassistant),接下来的步骤都在homeassistant用户权限下操作

    homeassistant@raspberrypi:/srv/homeassistant $)
    

    您将需要运行以下命令来安装所需的Python包。并开始安装Homeassistant Core。

    python3 -m pip install wheel
    pip3 install homeassistant
    

    安装完成后,控制台输入hass启动运行,Homeassistant Core将开始第一次启动,大概花5-10分钟开始运作,可以访问http://X.X.X.X:8123

    (homeassistant) homeassistant@raspberrypi:/srv/homeassistant $ hass
    Unable to find configuration. Creating default one in /home/homeassistant/.homeassistant
    

    接下来,使用(Autostart using system)方法开启HomeAssistant Core开机自启动

    1.创建home-assistant@homeassistant.service服务
    su pi
    sudo nano /etc/systemd/system/home-assistant@homeassistant.service
    sudo chmod 555 /etc/systemd/system/home-assistant@homeassistant.service
    
    输入以下内容:
    [Unit]
    Description=Home Assistant
    After=network-online.target
    
    [Service]
    Type=simple
    User=homeassistant
    WorkingDirectory=/home/homeassistant/.homeassistant
    ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant"
    RestartForceExitStatus=100
    Restart=on-failure
    RestartSec=5s
    
    [Install]
    WantedBy=multi-user.target
    

    下一步重新加载systemd,激活home-assistant@homeassistant服务

    sudo systemctl --system daemon-reload
    sudo systemctl enable home-assistant@homeassistant
    

    激活服务

    sudo systemctl start home-assistant@homeassistant
    

    至此,安装HomeAssistant Core完成

    开始安装HACS商店

    第一步切换到homeassistant用户

    sudo su homeassistant
    

    第二部运行安装脚本,如果卡在网络下载,请翻到上面的更改github解析IP.

    sudo wget -O - https://get.hacs.xyz | sudo bash -
    

    安装完成后重启系统。

    接下来要设置HACS

    第一步,点击设置-设备与服务 第二步,点击
    第三步,输入HACS
    第四步,homeassistant会自动安装依赖包
    第五步,全部打钩点submit
    第六步,会自动提醒你将设备链接github,这一步不要急着提交,先点击链接打开新登录窗口 第七步,登录github 第八步,复制第六步的代码输入,点击继续
    第九步点击授权
    第十步,授权成功
    第十一步,回到第六步homeassistant界面submit
    此时HACS安装设置成功

    相关文章

      网友评论

          本文标题:树莓派4B/Raspberry Pi4B 安装Home Assi

          本文链接:https://www.haomeiwen.com/subject/chkxrrtx.html