Home Assistant配置入门:从基础配置到前端资源管理
创作时间:
作者:
@小白创作中心
Home Assistant配置入门:从基础配置到前端资源管理
引用
CSDN
1.
https://blog.csdn.net/Dbh321/article/details/142452460
本章节将详细介绍Home Assistant(HA)的配置入门,包括基本配置文件的设置、前端资源的加载方式、配置文件的分隔方法以及模板脚本的使用等技术细节。
一、路径解释
在HA中,内部资源的访问路径有以下两种方式:
/local/community/xxxx/yyyyy.js:表示HA配置目录下的www文件夹。/hacsfiles/xxoxyyy-js:表示HA的/config/community路径。
二、下载前端的三种方式
1. HACS商店搜索下载
这是最简单的方式,直接在HACS商店中搜索并下载所需的插件。
2. 通过GitHub仓库地址添加
当HACS商店中找不到所需插件时,可以通过添加GitHub仓库地址来手动添加。具体步骤如下:
- 下载插件的JS文件。
- 在
/config/www/community目录下创建与该组件名相同的名字,并将JS文件保存进去。 - 在设置->仪表盘->资源中写入组件路径,添加前端资源。
三、configuration文件基本配置
在HA的早期版本,需要将HA的基本配置放在配置文件中,这里一块记录,当然这些配置都可以通过页面进行配置。
homeassistant:
# 你HA的名字
name: "My Home Assistant Instance"
# 经纬度
latitude: 37
longitude: -121
# 时区
time_zone: "America/Los_Angeles"
四、分隔配置文件
(一)基本用法
使用!include语法可以将configuration.yml以外的配置拉入主配置。例如:
automation: !include automation.yaml
zone: !include zone.yaml
sensor: !include sensor.yaml
switch: !include switch.yaml
device_tracker: !include device_tracker.yaml
(二)高级用法
1. !include_dir_list
将目录的内容作为一个列表返回,其中每个文件的内容都是列表中的一个条目。需要注意的是,在使用!include_dir_list时,每个文件必须只包含一个条目。
2. !include_dir_named
将返回目录的内容作为一个字典,该字典将文件名映射到文件的内容。
3. !include_dir_merge_list
会将一个目录的内容作为一个列表返回,方法是将所有文件(这些文件应该包含列表)合并成一个大的列表。重要的是要注意,当使用!include_dir_merge_list时,你必须在每个文件中包含一个列表(每个列表项都用连字符[-]表示)。每个文件可以包含一个或多个条目。
4. !include_dir_merge_named
将加载目录中的每个文件,并将它们合并成一个大的字典,然后返回这个字典的内容。
五、Templating(脚本)
简单来说就是在配置文件中使用脚本来访问一些集成和环境信息,举个例子。
script:
msg_who_is_home:
sequence:
- action: notify.notify
data:
message: >
{% if is_state('device_tracker.paulus', 'home') %}
Ha, Paulus is home!
{% else %}
Paulus is at {{ states('device_tracker.paulus') }}.
{% endif %}
其中if-else判断就是Templating。这里不做详细介绍了,用到哪里,再去看看吧,官方地址。
六、引入前端文件
在lovelace中更改mode为yaml。
全部改为yaml模式
lovelace:
mode: yaml
# Include external resources only add when mode is yaml, otherwise manage in the resources in the dashboard configuration panel.
resources:
- url: /local/my-custom-card.js
type: module
- url: /local/my-webfont.css
type: css
# Add more dashboards
dashboards:
lovelace-generated: # Needs to contain a hyphen (-)
mode: yaml
filename: notexist.yaml
title: Generated
icon: mdi:tools
show_in_sidebar: true
require_admin: true
lovelace-hidden:
mode: yaml
title: hidden
show_in_sidebar: false
filename: hidden.yaml
部分改为yaml
lovelace:
mode: storage
# Add yaml dashboards
dashboards:
lovelace-yaml:
mode: yaml
title: YAML
icon: mdi:script
show_in_sidebar: true
filename: dashboards.yaml
最后抄一个大佬的配置
homeassistant:
name: Home
latitude: !secret homeassistant_latitude
longitude: !secret homeassistant_longitude
elevation: !secret homeassistant_elevation
unit_system: metric
time_zone: Asia/Shanghai
packages: !include_dir_named packages/
allowlist_external_dirs:
['/config/']
whitelist_external_dirs:
- /config
media_dirs:
local: /media
rest: !include rest.yaml
template: !include template.yaml
frontend:
themes: !include_dir_merge_named themes
default_config:
energy:
history:
ios:
mobile_app:
media_source:
sun:
system_health:
http:
use_x_forwarded_for: true
trusted_proxies:
- 172.0.0.0/8
- 192.168.2.0/24
lovelace:
mode: yaml
resources:
# mushroom hacs
- url: /hacsfiles/chineseholiday_card/ch_calendar-card.js
type: module
- url: /hacsfiles/lovelace-colorfulclouds-weather-card/colorfulclouds-weather-card.js
type: module
- url: /hacsfiles/lovelace-layout-card/layout-card.js
type: module
- url: /hacsfiles/lovelace-mushroom/mushroom.js
type: module
- url: /hacsfiles/lovelace-rpi-monitor-card/rpi-monitor-card.js
type: module
- url: /hacsfiles/stack-in-card/stack-in-card.js
type: module
- url: /hacsfiles/vertical-stack-in-card/vertical-stack-in-card.js
type: module
# tablet hacs
- url: /hacsfiles/apexcharts-card/apexcharts-card.js
type: module
- url: /hacsfiles/bar-card/bar-card.js
type: module
- url: /hacsfiles/button-card/button-card.js
type: module
- url: /hacsfiles/custom-icons/custom-icons.js
type: module
- url: /hacsfiles/flipdown-timer-card/flipdown-timer-card.js
type: module
- url: /hacsfiles/lovelace-card-mod/card-mod.js
type: module
- url: /hacsfiles/lovelace-card-tools/card-tools.js
type: module
- url: /hacsfiles/lovelace-hui-element/hui-element.js
type: module
- url: /hacsfiles/mini-graph-card/mini-graph-card-bundle.js
type: module
- url: /hacsfiles/mini-media-player/mini-media-player-bundle.js
type: module
- url: /hacsfiles/PlexMeetsHomeAssistant/plex-meets-homeassistant.js
type: module
- url: /hacsfiles/secondaryinfo-entity-row/secondaryinfo-entity-row.js
type: module
- url: /hacsfiles/simple-weather-card/simple-weather-card-bundle.js
type: module
- url: /hacsfiles/swipe-card/swipe-card.js
type: module
- url: /hacsfiles/vacuum-card/vacuum-card.js
type: module
- url: /hacsfiles/weather-card/weather-card.js
type: module
- url: '/local/ui/js/curtain-card.js'
type: module
dashboards:
lovelace-phone:
mode: yaml
title: 手机
icon: hass:cellphone
show_in_sidebar: true
filename: dashboards/phone/mushroom.yaml
lovelace-tablet:
mode: yaml
title: 平板
icon: hass:tablet
show_in_sidebar: true
filename: dashboards/tablet/ui-tablet.yaml
logger:
default: warning
filters:
pyhap.characteristic:
- "SecuritySystemCurrentState: value=0 is an invalid value."
- "SecuritySystemTargetState: value=0 is an invalid value."
- "TargetHeatingCoolingState: value=0 is an invalid value."
logs:
homeassistant.components.command_line: fatal
homeassistant.components.command_line.sensor: error
homeassistant.components.homekit.type_media_players: error
homeassistant.components.media_player: error
homeassistant.components.rest.sensor: error
homeassistant.components.websocket_api: fatal
homeassistant.helpers.entity: error
homeassistant.helpers.event: fatal
homeassistant.helpers.service: error
alarm_control_panel:
- platform: manual
name: Home Alarm
code: !secret alarm_code
arming_time: 30
delay_time: 20
trigger_time: 4
disarmed:
trigger_time: 0
armed_home:
arming_time: 0
delay_time: 0
recorder:
#需要保存的天数
purge_keep_days: 30
#db_url: mysql://账户:密码@ip地址:端口/数据库名字
# db_url: !secret mariadb_url
#排除日志
exclude:
entities:
- media_player.yun_yin_le_homepod_mini
- media_player.yun_yin_le_mpd
timer:
laundry:
duration: "00:01:00"
tts:
- platform: edge_tts
language: zh-CN # 默认语言或声音 zh_CN(zh-CN-XiaoxiaoNeural)
- platform: baidu
app_id: !secret baidutts_id
api_key: !secret baidutts_api_key
secret_key: !secret baidutts_secret_key
根据配置建立相应文件夹,放入文件即可。
热门推荐
霞浦玉潭樱花谷:春日浪漫打卡地
文化新观察丨龙年吉祥!探寻博物馆里的“中国龙”
京都必打卡!清水寺&八坂神社一日游攻略
《万叶集》:日本和歌之美
立春要“躲春”?这些人群要注意,科学解读传统习俗
“立春要躲春,不能床上躺”,明日立春,该怎么“躲春”?
胃酸过多吃什么益生菌好得快呢
春节团圆:一场跨越千里的心理补偿
完美炸猪排的终极秘籍,你get到了吗?
炸大猪排必选梅花肉!
婆罗摩笈多与花拉子密:一元二次方程研究的双璧
自由落体运动:用一元二次方程解谜
一元二次方程新解法大揭秘:告别试错,直接求根
中考数学秒杀:一元二次方程解题技巧大揭秘!
从"德云一哥"到"综艺混子":岳云鹏的转型之路
从"德云一哥"到"综艺混子":39岁岳云鹏的转型之路
《西游记》中的赤尻马猴:与无支祁有何不同?
提高跑步速度需要训练哪些肌肉群?5组动作助你提速
混世四猴中,孙悟空究竟是不是灵明石猴?原著已多处暗示
《黑神话:悟空》究竟讲了个什么故事?你把西游记倒过来读试试
摇滚乐的起源与历史:从40年代到今天
力量+有氧训练,为何体重不降反升?
北京协和医院专家解析:一日内体重波动的真相
揭秘体重之谜:为什么下午比上午轻?
喜羊羊与灰太狼:新角色大揭秘!
马赛马拉自驾游:狂野非洲的必打卡地
肯尼亚和坦桑尼亚:非洲草原上的环保守护者
生化危机6全技能效果详解:从反击到体术的全面攻略
洗衣机空气洗是什么意思?洁净新体验的科技革新
从年度科技热词领略“创新中国”