拥抱Home Assistant

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/Joseph_Thunder/article/details/99706165

前言: 最近入手了个失去服务器的 垃圾 智能插排,经过一番查阅,找到了一些可以领插排复活的攻略,就是接入Home Assistant再由其控制。在接触了Home Assistant之后,也发现了其强大和有趣之处。

一、安装Home Assistant

Home Assistant是一款基于Python的智能家居开源系统。安装Home Assistant之前,先要确认树莓派的Python版本是Python3.5.3以上。

1.更换pip下载源

pip默认是国外的下载源,更换成国内源,下载会快一点。命令行输入以下命令打开pip的配置文件。

sudo vi /etc/pip.conf

修改成以下内容:

[global]
index-url=https://mirrors.aliyun.com/pypi/simple/
extra-index-url=https://www.piwheels.org/simple

如果安装Home Assistant的时候出现依赖库由于下载超时而安装失败的情况,就屏蔽掉上面最后一行,再重新安装对应的依赖库。

2.更新pip

将pip更新到最新的版本,命令行输入:

sudo pip3 install pip --upgrade

3.安装Home Assistant

由于Home Assistant是基于Python的开源系统,所以需要用pip安装。命令行输入:

sudo pip3 install homeassistant

会自动安装Home Assistant的依赖程序,耐心等待的下载安装完成。

二、启动Home Assistant

1.首次启动Home Assistant

启动Home Assistant,在命令行输入:

扫描二维码关注公众号,回复: 7614680 查看本文章
hass

Home Assistant的首次启动会自动安装运行时的依赖库,所以启动的时间会比较长。
当出现提示Timer:starting时,证明Home Assistant已经启动了。

2.检查Home Assistant的启动情况

再打开一个Session使用SSH登陆树莓派,命令行下检查Home Assistant的启动情况。

(1)检查Home Assistant进程

Linux系统使用ps命令查看系统进程。命令行输入:

ps -ef|grep hass

可以查看到hass进程正在运行。
hass_process

(2)检查Home Assistant网络

使用netstat命令查看Home Assistant的8123端口是否开放。命令行输入:

netstat -an|grep 8123

8123是Home Assistant的默认端口。
hass_port

(3)查看Home Assistant的运行日志文件

查看Home Assistant的运行日志文件内容,可以了解到Home Assistant是否正常运行或者有无异常。命令行输入:

cat .homeassistant/homeassistant.log

三、登陆Home Assistant

通过浏览器登陆Home Assistant,推荐使用Chrome浏览器。
使用地址栏,通过http协议访问树莓派的IP地址的8123端口,就能进入Home Assistant的操作界面。
registered_account
首次登陆需要注册用户,注册完成后登陆进去,就能使用Home Assistant了。
hass_ui

四、配置Home Assistant自启动

配置Home Assistant开机自动启动。命令行输入:

sudo vi /etc/systemd/system/[email protected]

将以下内容填写到[email protected]中。

[Unit]
Description=Home Assistant
After=network.target
[Service]
Type=simple
User=%i
ExecStart=/usr/local/bin/hass
[Install]
WantedBy=multi-user.target

使用systemctl命令将配置文件加载到系统中,命令行输入:

sudo systemctl enable home-assistant@pi

可以看到命令行返回加载的信息。

Created symlink /etc/systemd/system/mulit-user.target.wants/[email protected] → /etc/systemd/system/[email protected]

最后,重启树莓派。

sudo reboot

往后,使用systemctl命令可以控制Home Assistant服务,常用的控制命令如下:

sudo systemctl start home-assistant@pi		#启动服务
sudo systemctl stop home-assistant@pi		#停止服务
sudo systemctl restart home-assistant@pi 	#重启服务

写在最后: Home Assistant是一款非常强大的智能家居开源系统,可以在Home Assistant上安装形形色色的智能设备的插件,将它们统一管理,就像堆砌积木一般,搭建自己的智慧空间。

猜你喜欢

转载自blog.csdn.net/Joseph_Thunder/article/details/99706165