网站首页 > 技术文章 正文
Home Assistant 是一款在 Python 3 上运行的家庭自动化平台。能够跟踪和控制家庭中的所有设备,并提供自动化控制平台。Home Assistant 有一个简单的、适合移动设备的界面来控制你的所有设备,且不会将任何数据存储在云端,以保护个人隐私。下面,我们以step by step的方式演示一下如何在debian11环境下安装Home Assistant Core(之前叫Home Assistant)
1 安装软件依赖包
更新apt软件列表
root@debian:~# apt-get update |
将系统内核及软件包升级到最新版本
root@debian:~# apt-get upgrade -y |
在这里最好重启一下系统,以确保最新的内核被加载
root@debian:~# reboot |
重启后验证一下内核版本
root@debian:~# uname -a Linux debian 5.10.0-19-amd64 #1 SMP Debian 5.10.149-2 (2022-10-21) x86_64 GNU/Linux |
安装软件依赖,Python需要安装3.9及以上版本(包含python3-dev)
apt-get install -y python3 python3-dev python3-venv python3-pip bluez libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 libturbojpeg0-dev tzdata |
2 创建账号
为Home Assistant Core创建一个账号及home目录
root@debian:~# useradd -rm homeassistant |
3 创建虚拟环境
创建Home Assistant Core的安装目录并更改目录属主账号为homeassistant
root@debian:/home# mkdir /srv/homeassistant root@debian:/home# chown homeassistant:homeassistant /srv/homeassistant |
切换到homeassistant账户下,创建并加载Home Assistant Core运行所需的虚拟环境
root@debian:~# sudo -u homeassistant -H -s homeassistant@debian:/root$ cd /srv/homeassistant homeassistant@debian:/srv/homeassistant$ python3 -m venv . homeassistant@debian:/srv/homeassistant$ source bin/activate (homeassistant) homeassistant@debian:/srv/homeassistant$ |
虚拟环境激活后,运行以下命令来安装所需的Python包
(homeassistant) homeassistant@debian:/srv/homeassistant$ python3 -m pip install wheel |
4 安装Home Assistant Core
采用pip3包管理工具安装homeassistant
(homeassistant) homeassistant@debian:/srv/homeassistant$ pip3 install homeassistant |
首次启动Home Assistant Core。将完成应用安装,自动在/home/homeassistant目录中创建.homeassistance配置目录,并安装所有基本依赖项
(homeassistant) homeassistant@debian:/srv/homeassistant$ hass Unable to find configuration. Creating default one in /home/homeassistant/.homeassistant 2022-11-04 16:18:57.015 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: bluetooth 2022-11-04 16:19:06.153 WARNING (MainThread) [homeassistant.setup] Setup of bluetooth is taking over 10 seconds. 2022-11-04 16:20:45.141 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: default_config |
当您第一次运行hass命令时,它将下载、安装和缓存必要的库/依赖项。此过程可能需要5到10分钟。在此期间,访问web界面时可能会出现“站点无法访问”错误。这只会是第一次,随后的重启会更快。
现在可以通过web界面访问Home Assistant Core
http://主机IP:8123
第一次访问会出现如下注册界面,首先为系统配置一个账号
接下来比较简单,按照提示一步一步完成配置即进入可系统界面
5 配置开机自启动
新建rc.local文件,以homeassistant用户执行服务启动命令
root@debian:/srv/homeassistant/bin# vi /etc/rc.local #!/bin/sh su homeassistant -c '/srv/homeassistant/bin/hass' |
添加可执行权限
root@debian:/srv/homeassistant/bin# chmod +x /etc/rc.local |
从/lib下拷贝一份rc-local.service文件模板
root@debian:/srv/homeassistant/bin# cp /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service |
编辑rc-local.service,具体配置如下图所示
root@debian:/srv/homeassistant/bin# vi /etc/systemd/system/rc-local.service # SPDX-License-Identifier: LGPL-2.1-or-later # # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # This unit gets pulled automatically into multi-user.target by # systemd-rc-local-generator if /etc/rc.local is executable. [Unit] Description=/etc/rc.local Compatibility Documentation=man:systemd-rc-local-generator(8) ConditionFileIsExecutable=/etc/rc.local After=network.target [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 RemainAfterExit=yes GuessMainPID=no [Install] WantedBy=multi-user.target ~ ~ " |
设置rc-local服务开机自启动
root@debian:/srv/homeassistant/bin# systemctl enable rc-local Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /etc/systemd/system/rc-local.service. |
ok,到此结束,后续有机会我们再摸索一下如何将家庭智能设备接入Home Assistant。
猜你喜欢
- 2025-05-08 DOCKER(docker安卓版下载)
- 2025-05-08 InstantID模型部署教程(insight模型)
- 2025-05-08 Dockerfile简单使用(docker-file)
- 2025-05-08 Kubernetes Linux安装指南(kubernetes安装配置)
- 2025-05-08 一个Rust小白发布生产级Rust应用的进阶之路 | 得物技术
- 2025-05-08 如何用Linux服务器搭建属于自己的云手机
- 2025-05-08 必看!WSL2 内核选项修改方法,手把手教你编译更新
- 2025-05-08 深入了解,Python 中 type 和 isinstance 的用法
- 2025-05-08 Python 开发工程师必会的 5 个系统命令操作库
- 2025-05-08 PowerDNS可视化管理工具(可视化管理ppt)
- 最近发表
- 标签列表
-
- cmd/c (64)
- c++中::是什么意思 (83)
- 标签用于 (65)
- 主键只能有一个吗 (66)
- c#console.writeline不显示 (75)
- pythoncase语句 (81)
- es6includes (73)
- sqlset (64)
- windowsscripthost (67)
- apt-getinstall-y (86)
- node_modules怎么生成 (76)
- chromepost (65)
- c++int转char (75)
- static函数和普通函数 (76)
- el-date-picker开始日期早于结束日期 (70)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- & (66)
- java (73)
- js数组插入 (83)
- linux删除一个文件夹 (65)
- mac安装java (72)
- eacces (67)
- 查看mysql是否启动 (70)
- 无效的列索引 (74)