当前位置: 首页 > article >正文

Ubuntu 22.04 上安装 Home Assistant

在 Ubuntu 22.04 上安装无桌面的 Home Assistant 可以通过以下步骤完成。Home Assistant 是自动化爱好者常用的平台,我们将使用 Home Assistant 的容器(docker)版本以确保灵活性和易于管理。

安装步骤

1. 更新系统

首先,确保系统是最新的,运行下面的命令来更新包管理器和软件包。

sudo apt update && sudo apt upgrade -y
2. 安装 Docker

Home Assistant 的容器版要求 Docker 的运行环境,因此首先要安装 Docker。

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io

确保 Docker 安装成功:

sudo systemctl status docker
3. 安装 Docker Compose

Docker Compose 是用于定义和运行多容器 Docker 应用程序的工具。在这里我们将使用它来管理 Home Assistant。

sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

验证安装:

docker-compose --version

如果下载失败,可以自己通过其它电脑获取 docker-compose
注意: ( u n a m e − s ) − (uname -s)- (unames)(uname -m)

准备 Home Assistant 的运行环境

创建一个目录来保存 Home Assistant 的配置文件和 Docker Compose 文件。

mkdir ~/homeassistant
cd ~/homeassistant

创建一个 docker-compose.yml 文件:

services:
  homeassistant:
    container_name: home-assistant
    image: "ghcr.nju.edu.cn/home-assistant/home-assistant:stable"
    volumes:
      - ./config:/config
    environment:
      - TZ=Asia/Shanghai    # 替换 YOUR_TIME_ZONE 为您的时区,例如 America/New_York
    restart: unless-stopped
    network_mode: host

确保将 YOUR_TIME_ZONE 替换为实际的时区名称。

timedatectl 是一个用于查看和设置系统时钟的命令。你可以通过运行以下命令来查看当前时区:

timedatectl
5. 启动 Home Assistant

运行以下命令以拉取镜像并启动容器:

docker-compose up -d
6. 访问 Home Assistant

在浏览器中打开 http://<你的服务器IP>:8123,你应该可以看到 Home Assistant 的初始设置页面。

离线获取 Docker 镜像

  1. 在联网机器上导出镜像:

    在一台可以访问 Docker Registry 的机器上,首先拉取所需的 Docker 镜像:

    docker pull ghcr.io/home-assistant/home-assistant:stable
    

    导出镜像到一个 tar 文件:

    docker save -o home-assistant-stable.tar ghcr.io/home-assistant/home-assistant:stable
    
  2. 将镜像传输到离线机器:

    使用 USB 驱动器、局域网或其他传输方法,将 home-assistant-stable.tar 文件传输到离线机器。

  3. 在离线机器上导入镜像:

    在离线机器上,使用以下命令导入镜像:

    docker load -i home-assistant-stable.tar
    

    通过这种方法,镜像就会被加载到你的 Docker 环境中,你可以像通常那样运行它。

更新Linux apt 源

sudo vi /etc/apt/sources.list

替换配置

#deb cdrom:[Ubuntu 22.04.2 LTS _Jammy Jellyfish_ - Release amd64 (20230223)]/ jammy main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy universe
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu jammy-security main restricted
# deb-src http://security.ubuntu.com/ubuntu jammy-security main restricted
deb http://security.ubuntu.com/ubuntu jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu jammy-security universe
deb http://security.ubuntu.com/ubuntu jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu jammy-security multiverse

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

卸载 Home Assistant:

  1. 列出正在运行的容器以找到 Home Assistant 容器的ID(如果未提供明确名称):

    sudo docker ps
    
  2. 停止并删除 Home Assistant 容器:

    sudo docker stop <container_id_or_name>
    sudo docker rm <container_id_or_name>
    
  3. 删除镜像:

    sudo docker rmi homeassistant/home-assistant
    

http://www.kler.cn/a/587881.html

相关文章:

  • Linux centos 7 grub引导故障恢复
  • 2025-03-15 Python深度学习2——Numpy库
  • UI基础概念+Canvas相关知识
  • 【漫话机器学习系列】141.灵敏度(Sensitivity)
  • 如何手动使用下载并且运行 QwQ-32B-GGUF
  • 强大的CSS变量
  • LiveData 与 ViewModel 协同工作:从原理到面试实战
  • dns域名双栈解析
  • 【MySQL数据库】函数
  • pycharm专业版连接远程服务器用远程conda环境run和debug
  • 如何设计高效的数据湖架构?
  • kettle ETL 配置
  • 图片标注及流程
  • 996引擎-自定义属性-方法2:setitemcustomabil
  • 基于nodejs中@langchain/langgraph框架实现workflow
  • QT中的线程同步机制
  • 视觉slam十四讲(四)——相机与图像
  • Vue3 + Vite + Yarn + Fabricjs构建的开源演示系统
  • 基于 Verilog 的时序设计:从理论到实践的深度探索
  • 蓝桥杯每日一题01背包拔高·小A点菜