Hassbian

Hassbian is our customized operating system for the Raspberry Pi 3. It is the easiest way of installing Home Assistant.

  Hassbian是我们为Raspberry Pi 3定制的操作系统。它是安装Home Assistant的最简单方法。

  • 安装Hassbian
  • 自定义您的安装
  • Pi具体集成
  • 了解如何执行常见任务

在您的Raspberry Pi上安装Home Assistant的最简单的方法是使用HASSBian:内置Home Assistant 的Raspberry Pi镜像。 镜像将在初始启动(约10分钟)时安装最新版本的Home Assistant。

  1. 下载Hassbian镜像(364 MB)
  2. 使用 Etcher 将镜像烧录到您的SD卡
  3. 确保您的Raspberry Pi使用有线网络访问互联网。
  4. 将SD卡插入Raspberry Pi并将其打开。 Home Assistant 的初始安装大约需要5分钟。

上述步骤也有视频说明。 此视频中提供了其他信息。

初次启动后,您可以在浏览器地址 http://hassbian.local:8123 找到Home Assistant。 如果要通过SSH登录,默认用户名为 pi,密码为 raspberry (请通过运行 passwd 进行更改)。 Home Assistant配置位于 /home/homeassistant/.homeassistant/

镜像中包含以下附加组件:

  • GPIO引脚可以使用。
  • 蓝牙已准备就绪(仅支持 models ,无蓝牙LE)。
  • 启用SSH服务器
  • 一个名为 hassbian-config 的工具。  

Technical Details

  • Home Assistant is installed in a virtual Python environment at /srv/homeassistant/
  • Home Assistant will be started as a service run by the user homeassistant
  • The configuration is located at /home/homeassistant/.homeassistant

技术细节

 

  • Home Assistant安装在虚拟Python环境中,位于 /srv/homeassistant/
  • Home Assistant 将作为由用户 homeassistant 运行的服务启动
  • 配置位于 /home/homeassistant/.homeassistant  

安装Home Assistant

Home Assistant 提供多种安装方式。 一个要求是你安装了 Python 。 对于Windows,我们至少需要Python 3.5和其他操作系统,至少Python 3.4.2

Python 3.4.2.

29211242_fLcs.png

Hassbian

29211243_JHv0.png

Rasbian

29211244_462y.png

ArchLinux

29211246_GvBz.png

armbian

29211248_yK2U.png

Fedora

29211249_5VV5.png

CentOS/RHEL

29211253_lkcB.png

Windows

29211254_8YbL.png

macOS

29211255_qUAr.png

Synology

29211257_2ECp.png

Docker

29211257_NBlu.png

Vagrant

29211259_PiZm.png

FreeNAS

一旦Home Assistant安装完了,请在控制台/终端中执行以下代码,检查设置是否成功:

$ hass

第一次启动可能需要一两分钟,因为所需的软件包将被下载并安装。 Web界面 http://localhost:8123

有关 hass 的更多详细信息,请参阅工具部分

如果您正在运行基于Linux的平台,我们建议您遵循 VirtualEnv 说明以避免使用 root

可能需要根据您要使用的平台/组件安装附加库。

在 Armbian 系统上安装

armbian 运行在各种各样的ARM开发板上。 目前,有大约50个板级支持包,包括OrangePi系列,Cubieboard,Pine64和Odroid。

 

安装Python and pip

 

$ sudo apt-get update
$ sudo apt-get install python3-dev python3-pip

现在你安装了python,有两种方法来安装Home Assistant:

  1. 建议在虚拟环境中安装Home Assistant,以避免使用 root
  2. 或者,您可以为首次启动Armbian时创建的用户安装Home Assistant:
$ sudo pip3 install homeassistant
$ hass --open-ui

     运行这些命令将:

  • 安装 Home Assistant
  • 启动 Home Assistant ,并在 http://localhost:8123 上提供Web界面
  • 配置文件将在/home/{user}/.homeassistant中创建  

在 Virtualenv 中安装

在虚拟环境中运行Home Assistant有多种原因。 virtualenv 将Python环境的所有方面封装在单个目录树中。 这意味着您为Home Assistant安装的Python软件包不会与系统的其余部分进行交互,反之亦然。 这意味着您的计算机上某些其他程序的随机升级将不会影响Home Assistant,也意味着您不需要以root身份安装Python软件包。

Virtualenvs非常容易设置。 这个例子将通过一种设置方法(肯定还有其他的方法)。 我们将在这个例子中使用Debian(许多Home Assistant用户在Raspberry Pi上运行Raspbian),但是所有与Python相关的步骤在任何平台上都应该是一样的。

Step 0: 安装依赖

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install python-pip python3-dev
$ sudo pip install --upgrade virtualenv

Step 1: 创建 Home Assistant 用户和组

这个步骤是可选的,但最好给 Home Assistant 等服务提供自己的用户。 如果 Home Assistant 中存在安全相关的错误,它可以更精确地控制权限,并减少对系统其余部分的影响。 对于 Linux 这是一个合理的的步骤,这跟其他操作系统(甚至其他Linux发行版)上看起来会有所不同。

$ sudo adduser --system homeassistant
$ sudo addgroup homeassistant

默认情况下,Home Assistant将其配置存储在 $HOME/.homeassistant 中,因此在这种情况下,它将在 /home/homeassistant/.homeassistant

如果您打算使用Z-Wave控制器,则需要将此用户添加到 dialout

$ sudo usermod -G dialout -a homeassistant

Step 2: 创建 Home Assistant 目录

这可以是你想要的任何地方。例如我们把它放在 /srv 中。您还需要将目录的所有权更改为上面创建的用户(如果您创建了用户)。

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

Step 3: 成为新用户

很显然只有在你创建了一个 homeassistant 用户的时候才需要,但是如果你这样做了的话,每当你在virtualenv中安装它们时,一定要切换到那个用户,否则你最终会遇到权限问题。

$ sudo su -s /bin/bash homeassistant

su 命令表示“切换”用户。我们使用'-s'标志,因为 homeassistant 用户是系统用户,默认情况下没有默认shell(以防止攻击者能够以该用户身份登录)。

Step 4: 创建 virtualenv

这步所做就是在我们使用的目录中附加一个Python环境而已。这只是一个目录。没有什么特别的,它是完全独立的(self-contained)。

它将包含一个 bin 目录,它将包含virtualenv中使用的所有可执行文件(包括Home Assistant本身)。它还包括一个名为ac activate 的脚本,我们将使用它来激活virtualenv。

$ virtualenv -p python3 /srv/homeassistant

Step 5: 激活 virtualenv

$ source /srv/homeassistant/bin/activate

之后,你的命令提示符将包括命令 (homeassistant).

Step 6: 安装 Home Assistant

一旦你的virtualenv被激活,你不需要使用 sudo 执行任何 pip 命令。 pip 将在virtualenv中安装东西, homeassistant 用户有权修改它。

(homeassistant)$ pip3 install --upgrade homeassistant

你现在已经安装了Home Assistant,你可以确定它的每一位都包含在 /srv/homeassistant

最后运行 Home Assistant

启动 Home Assistant 有两种方法。如果你在virtualenv环境,你可以运行 hass ,它将正常工作。如果没有激活virtualenv,则只需在前面提到的 bin 目录中使用 hass 可执行文件。有一个警告...由于Home Assistant将其配置存储在用户的主目录中,我们需要是 homeassistant 用户或使用 -c 指定配置。

$ sudo -u homeassistant -H /srv/homeassistant/bin/hass

-H 参数是重要的。它将 $HOME 环境变量设置为 /home/homeassistant ,以便 hass 可以找到其配置。

升级 Home Assistant

升级家庭助理很简单,只需重复步骤3,5和6。

启动时运行 Home Assistant

The autostart instructions will work just fine, just be sure to replace /usr/bin/hass with /srv/homeassistant/bin/hass and specify the homeassistant user where appropriate.

自动启动指令将正常工作,请务必使用 /srv/homeassistant/bin/hass 替换 /usr/bin/hass ,并在适当的地方指定 homeassistant 用户。

事件

Home Assistant 的核心是事件总线。 事件总线允许任何组件触发或监听事件。 它是一切的核心。 例如,任何 State 改变将在事件总线上作为包含实体的先前和新状态的 state_changed 事件被公布。

Home Assistant 包含一些用于在各种组件之间进行协调的内置事件。

Event homeassistant_start

当配置中的所有组件都被初始化时,事件 homeassistant_start 被触发。进而启动定时器触发 time_changed 事件。

Event homeassistant_stop

当 Home Assistant 关闭时,事件 homeassistant_stop 被触发。该事件用于关闭任何打开的连接或释放任何资源。

Event state_changed

Event state_changed is fired when a state changes. Both old_state and new_state are state objects.

事件 state_changed 在 state 改变时触发。 old_statenew_state 都是 state 对象。关于 state 对象的文档。

字段说明
entity_idEntity ID of the changed entity. Example: light.kitchen
old_stateThe previous state of the entity before it changed. This field is ommitted if the entity is new.
new_stateThe new state of the entity. This field is ommitted if the entity is removed from the state machine.

Event time_changed

事件 time_changed 每秒钟由定时器触发一次并包含当前时间。

字段说明
nowA datetime object containing the current time in UTC.

Event service_registered

Event service_registered is fired when a new service has been registered within Home Assistant.

当在 Home Assistant 中注册新服务时,事件 service_registered 被触发。

字段说明
domainDomain of the service. Example: light.
serviceThe service to call. Example: turn_on

Event call_service

Event call_service is fired to call a service.

字段说明
domainDomain of the service. Example: light.
serviceThe service to call. Example: turn_on
service_dataDictionary with the service call parameters. Example: { 'brightness': 120 }.
service_call_idString with a unique call id. Example: 23123-4.

Event service_executed

服务处理程序触发事件 service_executed 以指示服务已经完成

字段说明
service_call_idString with the unique call id of the service call that was executed. Example: 23123-4.

Event platform_discovered

事件 platform_discovered 在 discovery 组件发现新平台时被触发。

字段说明
serviceThe service that is discovered. Example: zwave.
discoveredInformation that is discovered. Can be a dict, tuple etc. Example: (192.168.1.10, 8889).

Event component_loaded

当一个新组件被加载和初始化时,事件 component_loaded 被触发。

字段说明
componentDomain of the component that has just been initialized. Example: light.

State 对象

您的设备在 Home Assistant 表示为实体(entities)。实体会将其当前 states 写入状态机,以供其他 entities/templates/frontend 访问。 States 是该实体的当前表示。

如果您通过开发工具或API覆盖 state ,则不会影响实际设备。如果正在轮询设备 state ,它将覆盖状态机中的下一次轮询 state 。

当上次更新和上次更改时,所有 state 将始终具有实体ID、状态和时间戳

字段说明
state.state实体当前状态的字符串表示形式。例如 off
state.entity_id 实体 ID. 格式: <domain>.<object_id>. 例如: light.kitchen.
state.domain实体的域。例如:light.
state.object_id实体的对象 Object ID:例如: kitchen.
state.name实体名称。. Based on friendly_name attribute with fall back to object ID. Example: Kitchen Ceiling.
state.last_updatedTime the state was written to the state machine. Note that writing the exact same state including attributes will not result in this field being updated. Example: 14:10:03 13-03-2016.
state.last_changedTime the state changed. This is not updated when there are only updated attributes. Example: 14:10:03 13-03-2016.
state.attributesA dictionary with extra attributes related to the current state.

实体的属性是可选的。 Home Assistant 以特定方式表示实体的一些属性。每个组件还将拥有自己的属性来表示关于该实体的额外的状态数据。例如,light 组件具有当前亮度和颜色的属性。当属性不可用时,Home Assistant 不会将其写入状态。

使用模板时,名称属性是可用的。例如 state.attributes.assumed_state

属性说明
friendly_name实体的名称。示例: Kitchen Ceiling.
icon用于前端实体的图标。示例: mdi:home.
hidden如果实体不应该在前端显示,则为Boolean。示例: true.
entity_picture使用指定URL图片显示而不是域图标。示例:  http://example.com/picture.jpg.
assumed_state如果当前状态是假设,则为布尔值。 More info 示例: True.
unit_of_measurement表示状态的测量单位。用于分组图形或理解实体。示例:°C.

当属性包含空格时,可以像这样检索: states.sensor.livingroom.attributes["Battery numeric"]

转载于:https://my.oschina.net/u/3379895/blog/1073855

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
树莓派安装Home Assistant有以下几种方法: 1. 标准安装方式:使用Hassbian镜像,这是一个专门为Home Assistant设计的操作系统镜像。步骤如下: 1. 下载最新的Hassbian镜像并将其解压缩; 2. 将解压缩后的.img文件写入SD卡中; 3. 将SD卡插入树莓派并启动; 4. 访问树莓派的IP地址并完成Home Assistant的配置。 2. 使用Docker容器方式:使用Docker容器运行Home Assistant。步骤如下: 1. 在树莓派上安装Docker; 2. 创建一个Home Assistant容器; 3. 配置Home Assistant。 3. 使用HassOS镜像: HassOS是专门为Home Assistant设计的操作系统。步骤如下: 1. 下载最新的HassOS镜像并将其解压缩; 2. 将解压缩后的.img文件写入SD卡中; 3. 将SD卡插入树莓派并启动; 4. 访问树莓派的IP地址并完成Home Assistant的配置。 下面是标准安装方式的详细步骤: 1. 下载最新的Hassbian镜像并将其解压缩。可以从官网下载最新版本的Hassbian镜像文件,解压缩后得到一个.img文件。 2. 将解压缩后的.img文件写入SD卡中。可以使用Etcher等软件将.img文件写入SD卡中。将SD卡插入读卡器,连接到计算机上,打开Etcher软件,选中.img文件和SD卡,点击“Flash”按钮即可。 3. 将SD卡插入树莓派并启动。将SD卡插入树莓派,连接键盘、鼠标、显示器等设备,接通电源,树莓派会自动启动。 4. 访问树莓派的IP地址并完成Home Assistant的配置。在树莓派启动后,可以通过浏览器访问http://树莓派的IP地址:8123,进入Home Assistant的配置页面,按照提示完成Home Assistant的配置即可。 注意:如果树莓派没有连接显示器等设备,可以通过SSH连接到树莓派进行配置。首先需要在计算机上安装SSH客户端,然后通过SSH连接到树莓派的IP地址,输入用户名和密码即可进入树莓派的终端界面,进行配置。默认的用户名是pi,密码是raspberry

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值