meishild 发表于 2019-8-22 12:40:10

篇二:基础配置以及页面说明

本帖最后由 meishild 于 2019-8-22 13:46 编辑

目录位置:https://bbs.hassbian.com/forum.php?mod=viewthread&tid=8041


# 篇二:基础配置以及页面说明

按照篇一已经完成了hass的安装,并且现在已经能打开控制页面了:



## 主界面



默认装好就已经有一个插件了,自带的天气插件,左侧基本就是导航,常用的 `概览` `hass.io` `开发者工具` 这几个用的最多。

我们先把几个常用的插件先装了,要不配置起来太麻烦。


### Hass.io插件
> 如果想保留一个比较干净的配置,在弄挂了以后能恢复,或者装了一部分想做个备份,进入 Hass.io --> snapshot 创建一个快照可以下载下来。



插件位置,Hass.io --> ADD-ON STORE

> 所有的插件都是点完INSTALL等着,因为他这个是在后台docker在启动一个镜像是比较慢的,要先下载然后在启动,有一些还特别的大。


插件如果点安装了一直没反应,并且按钮变成红色,去看一下日志.Hass.io --> System



#### Configurator
通过页面方式编辑配置文件,并提供简单的文件管理功能,这个最常用先装,否则配置默认的yaml都比较烦。


安装好了,然后把上面的 `show in sidebar` 勾选上,至于自动更新 `auto update` 我是默认更新,看自己需求把。然后就可以start了。


装好了点那个文件夹选择主配置文件 `/config/configuration.yaml`


### Log Viewer
可以直接在页面看现在系统打印出来的日志,会一直刷屏。



### Terminal
对于有linux基础的可以直接通过这种方式进入控制台下。注意这个如果不配置config是无法启动的主要配置的也就是访问的username和password。

```yaml
{
"ssh": {
    "username": "username",
    "password": "password",
    "authorized_keys": [],
    "sftp": false,
    "compatibility_mode": false,
    "allow_agent_forwarding": false,
    "allow_remote_port_forwarding": false,
    "allow_tcp_forwarding": false
},
"web": {
    "ssl": false,
    "certfile": "fullchain.pem",
    "keyfile": "privkey.pem"
},
"share_sessions": false,
"packages": [],
"init_commands": []
}
```


## HASS几个常用的设备概念


#### sensor:传感器
顾名思义就能能返回一些信息,但是不能控制,常见的比如温度、湿度、甲醛、二氧化碳、电池等所有用来展示的都绑定成这个。


#### binary_sensor:开关类状态
状态只有两个值,on/off比如门,设备状态等等。




#### device_tracker:设备追踪
最常用的就是根据路由器追踪某个设备是否连接,可以做家人是否在家的追踪。



#### weather:天气



####

#### switch:开关
这个是可以控制但是只有开关状态,需要通过配置。

```yaml
- platform: mqtt
    name: light_sr_main
    # friendly_name: "洗手间镜主灯"
    # 状态返回,通过这个获取开关当前状态
    state_topic: hassmart/switch/hassmart_3key_module_8E93C4_3/state
    # 状态设置,就是用来开关的。
    command_topic: hassmart/switch/hassmart_3key_module_8E93C4_3/set
    qos: 1
    retain: false
```


## HASS界面常用功能


### 未使用实体
可以看到很多自己加进去了但是还没用到的实体。

比如:



##

### 配置UI
可以直接图形化修改,也可以在上面再点击一次切换到原始编辑器,有很多前端插件需要通过原始编辑器添加。

> 注意:原始编辑器.如果页面配置错误了,什么都不见了也可以通过这种方式删除。


```yaml
resources:
- type: module
    url: /local/custom-lovelace/hf-weather-card/hf-weather-card.js
- type: module
    url: /local/custom-lovelace/hf-weather-card/hf-weather-more-info.js
- type: module
    url: /local/floorplan/floorplan-card.js?v=1.1.14
- type: module
    url: /community_plugin/banner-card/banner-card.js
- type: js
    url: /community_plugin/list-card/list-card.js
title: Home
```


## 配置
虽然配置这东西因人而异,但是能写规范点当然规范点好,而且方便备份和维护。


#### 特别说明

```bash
mqtt:
broker: !secret mqtt_broker
port: !secret mqtt_prot

# 配置自动发现
discovery: true
# 自动发现使用的主题位置前缀,缺省为homeassistant
discovery_prefix: homeassistant

recorder:
db_url: !secret recorder_db_url

```


这里有两个比较特殊的配置,一个是mqtt,如果你需要使用mqtt来绑定其他设备,推荐安装一个新的,我直接使用docker方式在我的虚拟机公共linux内安装了一个。

**MQTT,消息中间件**

```bash
docker run --init -d --restart=always -p 1883:1883 -p 9001:9001 -d --restart=always -v /home/mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto
```

我的配置目录是:/home/mosquitto/mosquitto.conf

里面其实是mosquitto的默认配置,我没有打开密码,因为我这个纯局域网内使用,为了安全有些人可能需要打开。

> 我自己是不推荐在hassio里面直接启动一个,这个很多内部我需要公用并且,hassos还是纯粹点把,谁知道哪天又有问题了。


**mariadb**,数据库。

**注意:新版 Home Assistant 已经加入数据库定时清理机制,因此非高级玩家没有任何必要更换数据库。**
**注意:一旦更换数据库,数据内容都会丢失,如果要更换推荐安装好就换。**

Home Assistant 原生使用 SQLite 作为数据库,使用体验如何大家肯定都有感触了:加载数据慢 + 数据文件庞大,必须换。需要声明的是数据库的替换并不会转移之前的数据,因此尽量在初次安装后即进行数据库替换工作。原数据都存放在配置文件夹的 `home-assistant_v2.db`文件中。

既然 HA 数据库是 SQL 架构,意味着我们的选择面很广。DB-Engines 上排名靠前的几个关系型数据库都能使用,例如 MySQL、MariaDB、PostgreSQL 和 MS SQL Server。

我直接用docker在其他公用机器上启了一个mariadb,然后在里面需要创建一个数据库名字随意反正可以配置。

```bash
docker run --init -d --restart=always -p 3306:3306 -v /home/mariadb/data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root --name mariadb -d --restart unless-stopped docker.io/mariadb:latest
```

如果配置第三方数据库需要配置:recorder_db_url

我的配置: `recorder_db_url: "mysql://用户名:密码@数据库地址:3306/库名?charset=utf8"`


#### 基础配置
```bash
homeassistant:
# 名字按照自己的来吧
name: !secret name
# 位置
unit_system: metric
time_zone: !secret time_zone
packages: !include_dir_named packages
whitelist_external_dirs:
    - !secret motion_dir
    - !secret recording_dir
```

> default_config:这行先别删,这个引入和很多默认的配置,如果删了会发现很多东西都不见了。


这里面所有配置的 `!secret` 已这个开头的都是代表这个配置是来自安全文件 `secret.yaml` 文件的,推荐是把自己所有自定义相关的特别是密码类的放进去,这样还不影响分享,也保证了安全。

`crtl+s`或者右上角红色的保存是保存文件,这里系统会有一个检查如果右上角的标志不是绿色对号,代表yaml配置文件有错误,一定要改成绿色的。

这是secret.ymal这几项的配置,时区大家都一样。

两个目录是白名单访问目录:
```bash
name: "MyHome"
time_zone: "Asia/Shanghai"
motion_dir: "/tmp"
recording_dir: "/share"
```

`packages`是引入所有组合,

> 注意:一旦使用配置文件的方式配置name、位置、时区等会导致通过页面上的配置无法在使用。


好现在重启了,点击右上角的齿轮,选择restart hass,如果这时没提示,左下角没有个通知,那么就是配置检查没有问题,真的重启了,如果有错误,那么需要看一下具体哪里配置有问题。

点 `开发者工具` --> `信息` --> 滑倒最下面



额这是找不到secret name,哦我写错了写成title了。

重启好了,进入 `配置` --> `通用` 发现都灰色了,并且有提示。



#### 部分配置说明

> **系统配置**


```bash
# 历史记录 https://www.home-assistant.io/components/history/
# 左侧显示的历史
history:


# https://www.home-assistant.io/components/config/
config:

# 系统健康
system_health:

# 设备发现 discovery,会主动发现一些支持的设备,我是关了否则一直有通知比较烦
# discovery:

# 默认系统地址,包括ssl证书相关,注意secret需要配置参数
# https://www.home-assistant.io/components/http/
http:
base_url: !secret base_url
# ssl_certificate: /ssl/fullchain.pem
# ssl_key: /ssl/privkey.pem
# ip_ban_enabled: true
# login_attempts_threshold: 3
```

> **HOME KIT 或者 CLOUD**


我把配置文件拆分了,很多相关都扔到对应的目录下,简历目录 `assistants` 增加配置文件 `homekit.yaml` ,

```bash
# ########################################
# ###         ASSISTANTS             ###
# ########################################
cloud: # !include assistants/cloud.yaml
homekit: !include assistants/homekit.yaml
```

这几个是被homekit透出的设备,如果没有先不用配置filter。

```bash
auto_start: true
filter:
    include_entities:
      - light.gateway_light_04cf8ca9d363
      - sensor.humidity_158d00036311c9
      - sensor.temperature_158d00033e78c1
      - binary_sensor.motion_sensor_158d00033aed57
```

> **MOBILE**


```bash
# ########################################
# ###             MOBILE               ###
# ########################################
# IOS设备通知 https://www.home-assistant.io/components/mobile_app/
ios: !include notify/ios_config.yaml
# 移动设备绑定,显示电量等
mobile_app:
```

电量显示这个在ios上因为app无法后台运行的原因,只能打开app的时候刷新。

> **GUI**


```bash

# ########################################
# ###                GUI               ###
# ########################################
# lovelace:
#   mode: yaml

# 是否要打开地图,我用不到就关了,在国内如果用最好也换成别的,这个默认google的
# 如果启用地图记得配置设备地点,经纬度。
# curl https://api.ip.sb/geoip
# map:

# 前端配置
frontend:
# 我建了个themes目录里面是各种主题
themes: !include_dir_named themes
#   extra_html_url:
#   - /local/hass-bha-icons.html

# 这个是我引入了floorplan户型图,如果不需要都关掉
# panel_custom: !include panels/panel_custom.yaml
panel_custom:
- name: floorplan
    sidebar_title: Floorplan
    sidebar_icon: mdi:bulletin-board
    url_path: floorplan
    config: !include floorplan.yaml
```

给你们两个主题,其他外面很多自己区找找新增进去就好了

`dark-green.yaml`

```yaml

    # Main colors that can be changed
      primary-color: "#389638"
      disabled-text-color: "#545454"
      divider-color: "rgba(255, 255, 255, 0.12)"
      paper-card-background-color: "#202020"
      paper-grey-200: "#191919"
      paper-item-icon-color: "#d3d3d3"
      paper-listbox-background-color: "#202020"
      paper-listbox-color: "#FFFFFF"
      primary-background-color: "#303030"
      primary-text-color: "#cfcfcf"
      secondary-background-color: "#2b2b2b"
      secondary-text-color: "#389638"
    # Colors based on variables, see above
      label-badge-background-color: "var(--secondary-background-color)"
      label-badge-text-color: "var(--text-primary-color)"
      paper-card-header-color: "var(--paper-item-icon-color)"
      paper-grey-50: "var(--primary-text-color)"
      # paper-item-icon-active-color: "#d8bf50" #"var(--primary-color)"
      paper-item-icon_-_color: "var(--primary-text-color)"
      paper-slider-active-color: "#d8bf50" #"var(--primary-color)"
      paper-slider-knob-color: "var(--primary-color)"
      paper-slider-knob-start-color: "var(--primary-color)"
      paper-slider-pin-color: "var(--primary-color)"
      paper-slider-secondary-color: "var(--light-primary-color)"
      paper-toggle-button-checked-ink-color: "var(--dark-primary-color)"
      paper-toggle-button-checked-button-color: "var(--primary-color)"
      paper-toggle-button-checked-bar-color: "var(--light-primary-color)"
      paper-toggle-button-unchecked-bar-color: "var(--primary-text-color)"
      label-badge-red: 'var(--primary-color)'
      sidebar-icon-color: "var(--paper-item-icon-color)"
      lumo-body-text-color: "var(--primary-text-color)"
```

配置进去重启就能在,点左下角你的用户,然后选择主题就可以了.



> **日志打印**


```bash

# ########################################
# ###            LOGGING             ###
# ########################################
logger: !include logging/logger.yaml
```

日志配置文件:

```bash
############################################################
#
# LoggerYou can filter anything betwen the []'s in the logger.
#
############################################################

# Log Severities: notset, debug, info, warn, warning, error, fatal, critical

default: debug
logs:
homeassistant.components.sensor: debug
root: debug
```

平时我都用info级别,打开debug是为了查询很多比较坑的问题,可以看到更多的信息。日志可以直接进入服务器内找到/config/home-assistant.log,不推荐使用网页这个打开,特别debug级别日志量太大了。

> 服务信息


```bash
# ########################################
# ###             SERVICES             ###
# ########################################
# 打开日出日落,有一些插件依赖需要打开
sun:
# 这个只是在菜单上增加一个列表,可以不用
shopping_list:

```

个人实体:

```bash
# ########################################
# ###            ENTITIES             ###
# ########################################
# https://www.home-assistant.io/components/person/
person:
```


## 插件推荐和常用的配置方法

这几个插件都不需要硬件支持,需要硬件的我们在单开一篇。

> 注意:每种类型在yaml里只能出现一次,比如你要写多个sensor,那就一个sensor下面配一堆设备,不能出现两个。



### 天气插件
默认的天气插件不能说难用,但是还有很多选择可以用,我直接用了hf_weather,并在原作者上做了部分修改,配置过程都一样,我增加了紫外线强度,所以原有的城市配置就改成了通过ip,或者经纬度,因为这个对地区要求比较高。

代码地址:[https://github.com/meishild/hass ... e/master/hf-weather](https://github.com/meishild/hass ... e/master/hf-weather)

yaml配置:
```bash
weather:
- platform: hf_weather
    name: !secret hf_weather_name
    location: !secret hf_weather_location
    appkey: !secret hf_weather_appkey
```


#### 简介

基于和风天气的lovelace天气卡片,主要功能:

- 支持生成多个天气Entity
- 天气数据统一存储
- 天气卡片增加空气质量、小时预报、生活建议、数据更新时间
- 天气卡片更多信息增加生活建议详细数据
- 天气卡片图表增加下雨概率
- 天气卡片使用动态图标
- 增加紫外线强度以及位置配置


#### 使用说明

#### 组件

- 下载文件,hf_weather目录放置在{HA配置目录}/custom_components/下。
- 启用hf_weather组件([要先在api平台申请key](https://wx.jdcloud.com/market/datas/26/10610))。

```yaml
# 配置 configuration.yaml
weather:
- platform: hf_weather
    name: test                  # entity_id,自定义
    location: {{YOUR_LOCATION}} # 支持local_ip,根据ip获取,101.21.221.31,指定ip以及22.25,114.1667指定经纬度三种方式。
    appkey: {{YOUR_API_KEY}}    # api平台申请的key
```

> INFO:重复即可增加多个实体。


- 启用sun组件,用于提供卡片的日出日落数据。。

```yaml
# 配置 configuration.yaml
sun:
```


#### 自定义卡片

> 下载文件,hf_weather-card目录放置在{HA配置目录}/www/custom-lovelace/下。


- lovelace启用天气卡片

```yaml
# 配置lovelace(使用UI的原始编辑器编辑即可)
# 引入自定义卡片hf_weather-card
resources:
- type: module
    url: /local/custom-lovelace/hf-weather-card/hf-weather-card.js
- type: module
    url: /local/custom-lovelace/hf-weather-card/hf-weather-more-info.js
```

快速配置,在页面点右下角加号随便选个类型,选切换编辑器,然后粘贴进去保存就好了。

```yaml
entity: weather.dieyuan
icons: /local/custom-lovelace/hf-weather-card/icons/static/
mode: both
title: 天气
type: 'custom:hf-weather-card'
```

> 所有的配置都集中到了一个实体中如果需要可以通过模版拆分


```yaml
# 拆分天气
- platform: template
    sensors:
      weather_current_temp:
      friendly_name: "当前温度"
      unit_of_measurement: '°C'
      value_template: "{{ state_attr('weather.entity_id', 'temperature') }}"
      weather_current_uv:
      friendly_name: "当前紫外线强度"
      value_template: "{{ state_attr('weather.entity_id', 'uv')['uv'] }}"
      weather_current_rain:
      friendly_name: "当前下雨概率"
      unit_of_measurement: '%'
      value_template: "{{ state_attr('weather.entity_id', 'forecast')['probable_precipitation'] }}"
      weather_today_max_temp:
      friendly_name: "今天最高温度"
      unit_of_measurement: '°C'
      value_template: "{{ state_attr('weather.entity_id', 'forecast')['temperature'] }}"
      weather_today_min_temp:
      friendly_name: "今天最低温度"
      unit_of_measurement: '°C'
      value_template: "{{ state_attr('weather.entity_id', 'forecast')['templow'] }}"
```


### 热映电影
这个是别人直接写好的插件,论坛里也能找到,我为了方便就直接集成到了一起.


#### 简介

抓取互联网上最新热映的电影名称及票房信息(默认8小时更新一次数据)

数据源地址: [http://58921.com/](http://58921.com/)


#### 安装
放入 /custom_components/ 目录


#### 配置
**Example configuration.yaml:**

```yaml
sensor:
- platform: hotmovies
    name: 热映电影
```


#### 前台界面

原始的界面是这样的,只能看到数量



建议采用(https://github.com/custom-cards/list-card)进行展示,效果是这样的



list-card 快速配置,在页面点右下角加号随便选个类型,选切换编辑器,然后粘贴进去保存就好了。

```bash
columns:
- field: title
    style:
      - height: 30px
    title: 电影名称
- field: day
    title: 昨日票房
- field: total
    title: 累计票房
- field: ptime
    title: 发布时间
entity: sensor.re_ying_dian_ying
feed_attribute: entries
title: 热映电影
type: 'custom:list-card'
```



### 系统日期时间

```yaml
sensor:
    # 日期时间
- platform: time_date
    display_options:
      - 'time'
      - 'date'
```

这个有一些插件需要使用,还是打开把。


### 一些设备通过ping方式获取状态

```yaml
binary_sensor:
- platform: ping
    name: TV
    host: 10.0.0.69
- platform: ping
    name: 衣柜单开
    host: 10.0.0.151
- platform: ping
    name: 次卫三开
    host: 10.0.0.152
- platform: ping
    name: 主位双开
    host: 10.0.0.153
```

比如我这一堆开关或者电视、通过ping来看设备是否在线,效果大概这样。



可以配合一些联动使用。





发表于 2019-8-22 13:58:59

严重感谢楼主分享,内容翔实,新手福音!

lpswxu 发表于 2019-8-22 14:51:35

拜读中,先问一个一直好奇的问题:人员离开之类的状态如何关联,现在页面上显示未知,谢谢!

meishild 发表于 2019-8-22 14:54:29

lpswxu 发表于 2019-8-22 14:51
拜读中,先问一个一直好奇的问题:人员离开之类的状态如何关联,现在页面上显示未知,谢谢! ...

那个是默认用户的,你做人员跟踪用设备跟踪,就是直接配置路由器的,或者ping指定用户的ip

ghostist 发表于 2019-8-22 15:16:17

楼主坚持把目录文章完善起来
当初要是有这样的帖子 我也不至于起步撞墙那么多~哈哈哈

lpswxu 发表于 2019-8-22 16:10:05

meishild 发表于 2019-8-22 14:54
那个是默认用户的,你做人员跟踪用设备跟踪,就是直接配置路由器的,或者ping指定用户的ip ...

有点感觉了,正在看device tracker。华硕路由器的配置好像比其它小米、华为路由的简单,直接asuswrt,不用device_tracker,不知道理解的对不对?

602293544 发表于 2019-8-22 19:32:17


dalaoios不显示小时安卓可以 能修复修复不

xyz1943 发表于 2019-8-23 08:58:13

謝謝大大的分享 ^^y

meishild 发表于 2019-8-23 09:06:11

602293544 发表于 2019-8-22 19:32
dalaoios不显示小时安卓可以 能修复修复不

https://github.com/meishild/hass-custom-components/tree/master/hf-weather

你去下载我那个版本把,我那个修复了。

602293544 发表于 2019-8-23 09:35:33

meishild 发表于 2019-8-23 09:06
https://github.com/meishild/hass-custom-components/tree/master/hf-weather

你去下载我那个版本把, ...

下的是你的这个因为以前用的city忘记改报错了,改的location才显示的。。。
大佬你的ios可以吗
页: [1] 2 3 4 5 6 7 8 9 10
查看完整版本: 篇二:基础配置以及页面说明