实体卡片
实体卡片是最常见的卡片类型。它将项目分组到列表中。它可以用于显示实体的状态或属性,也可以包含按钮、网页链接等。
要将实体卡片添加到你的用户界面:
-
在屏幕右上角,选择编辑 按钮。
- 如果这是你第一次编辑仪表板,编辑仪表板对话框会出现。
- 通过编辑仪表板,你将接管这个仪表板的控制权。
- 这意味着当新的仪表板元素可用时,它将不再自动更新。
- 一旦你接管控制权,你将无法让这个特定的仪表板恢复自动更新。但是,你可以创建一个新的默认仪表板。
- 要继续,在对话框中,选择三点 菜单,然后选择接管控制。
- 如果这是你第一次编辑仪表板,编辑仪表板对话框会出现。
-
添加卡片并自定义操作和功能 到你的仪表板。
YAML 配置
当你使用 YAML 模式或只是在 UI 中的代码编辑器中更喜欢使用 YAML 时,以下 YAML 选项可用。
配置变量
type 字符串 必填
entities
entities 列表 必填
实体 ID 列表或 entity
对象或特殊行对象(见下文)。
title 字符串 (可选)
卡片标题。
icon 字符串 (可选)
显示在标题左侧的图标。
show_header_toggle 布尔值 (可选,默认值: true)
用于开启/关闭所有实体的按钮。
theme 字符串 (可选)
使用任何已加载的主题覆盖此卡片的主题。有关主题的更多信息,请参阅 前端文档。
state_color 布尔值 (可选,默认值: false)
设置为 true
以在实体激活时使图标着色。
header 映射 (可选)
要渲染的头部小部件。请参阅 头部文档。
footer 映射 (可选)
要渲染的底部小部件。请参阅 底部文档。
实体选项
如果你将实体定义为对象而不是字符串(通过在实体 ID 前添加 entity:
),你可以添加更多自定义和配置。
配置变量
entity 字符串 必填
实体 ID。
type 字符串 (可选)
设置自定义卡片类型:custom:my-custom-card
。它也可以用于强制具有默认特殊行格式的实体渲染为简单状态。你可以通过设置 type: simple-entity
来实现。例如,这可以用于将带有可编辑控件的助手替换为只读值。
name 字符串 (可选)
重写友好名称。
icon 字符串 (可选)
重写实体图片。
secondary_info 字符串 (可选)
显示额外信息。值:entity-id
、last-changed
、last-updated
、last-triggered
(仅适用于自动化和脚本)、position
或 tilt-position
(仅适用于支持的遮挡物)、brightness
(仅适用于灯光)。
format 字符串 (可选)
状态应如何格式化。目前仅用于时间戳传感器。有效值为:relative
、total
、date
、time
和 datetime
。
action_name 字符串 (可选)
按钮标签(仅适用于 script
和 scene
行)。
state_color 布尔值 (可选,默认值: false)
设置为 true
以在实体激活时使图标着色。
tap_action 映射 (可选)
行点击时执行的操作。请参阅 操作文档。
double_tap_action 映射 (可选)
行双击时执行的操作。请参阅 操作文档。
confirmation 映射 (可选)
对于在行中显示按钮元素的实体(例如按钮、锁、脚本),此选项将向按钮按下添加确认对话框。有关配置选项,请参阅 确认选项。
Special row elements
Rather than only displaying an entity's state as a text output, the entities card supports multiple special rows for buttons, attributes, web links, dividers and sections, etc.
Attribute
Configuration Variables
type 字符串 必填
attribute
entity 字符串 必填
实体 ID。
attribute 字符串 必填
要从实体显示的属性。
prefix 字符串 (可选)
实体状态前的文本。
suffix 字符串 (可选)
实体状态后的文本。
name 字符串 (可选)
重写友好实体名称。
icon 字符串 (可选)
要使用的图标。默认为实体的图标。
format 字符串 (可选)
属性值应如何格式化。目前仅支持时间戳属性。有效值为:relative
、total
、date
、time
和 datetime
。
Button
带有(可选)图标、标签和行末单个文本按钮的行,可以触发定义的操作。
Configuration Variables
type 字符串 必填
buttons
entity 字符串 (可选)
实体 ID。需要提供 entity
或 name
(或两者)。
name 字符串 (可选)
行标签。需要提供 entity
或 name
(或两者)。
默认值:如果指定了 entity
,则为其友好名称。
icon 字符串 (可选)
显示在主标签左侧的图标。
action_name 字符串 (可选,默认值: Run
)
按钮标签。
tap_action 映射 必填
按钮点击时执行的操作。请参阅 操作文档。
hold_action 映射 (可选)
按钮点击并按住时执行的操作。请参阅 操作文档。
double_tap_action 映射 (可选)
按钮双击时执行的操作。请参阅 操作文档。
Buttons
在单行中并排显示的多个按钮。请参阅下面的示例。
Configuration Variables
type 字符串 必填
button
entities 列表 必填
要显示的实体列表。每个条目可以是实体 ID 或映射。
entity 字符串 必填
实体 ID。
icon 字符串 (可选)
覆盖实体图标。
image 字符串 (可选)
覆盖实体图像。
name 字符串 (可选,默认值: 实体名称)
覆盖友好实体名称。
show_name 布尔值 (可选,默认值: false)
如果为 false,则不显示按钮名称。
show_icon 布尔值 (可选,默认值: true)
如果为 false,则不显示图标。
tap_action 映射 必填
按钮点击时执行的操作。请参阅 操作文档。
hold_action 映射 (可选)
按钮点击并按住时执行的操作。请参阅 操作文档。
double_tap_action 映射 (可选)
按钮双击时执行的操作。请参阅 操作文档。
Cast
用于启动 Home Assistant Cast 的特殊行。
Configuration Variables
type 字符串 必填
cast
dashboard 字符串 (可选)
需要显示的视图所在仪表板的路径。
view 字符串 必填
需要显示的视图的路径。
name 字符串 (可选,默认值: Home Assistant Cast)
在行中显示的名称。
icon 字符串 (可选)
要使用的图标。
默认值:hass:televisio
。
hide_if_unavailable 布尔值 (可选,默认值: false)
如果浏览器中不可用投射功能,则隐藏此行。
Conditional
基于实体状态显示的特殊行。
Configuration Variables
type 字符串 必填
conditional
conditions 列表 必填
要检查的条件列表。请参阅 可用条件。
row 映射 必填
如果所有条件都匹配,则显示的行。可以是本页面描述的各种支持的行。
Divider
Configuration Variables
type 字符串 必填
divider
style 映射 (可选)
使用 CSS 设置元素样式。
默认值:height: 1px, background-color: var(–divider-color)
Section
Weblink
Configuration Variables
type 字符串 必填
weblink
url 字符串 必填
网站 URL(或内部 URL,例如 /hassio/dashboard
或 /panel_custom_name
)。
name 字符串 (可选,默认值: URL 路径)
链接标签。
icon 字符串 (可选,默认值: mdi:link
)
要显示的图标(例如 mdi:home
)。
new_tab 布尔值 (可选,默认值: false)
在新标签页中打开链接。如果链接是外部 URL 或下载链接,这将自动为 true。如果内部 URL 应该在新标签页中打开,请使用此项。
download 布尔值 (可选,默认值: false)
链接是否为下载?
Examples
Entity rows
type: entities
title: Entities card sample
show_header_toggle: true
header:
image: "https://www.home-assistant.io/images/dashboards/header-footer/balloons-header.png"
type: picture
entities:
- entity: alarm_control_panel.alarm
name: Alarm Panel
- device_tracker.demo_paulus
- switch.decorative_lights
- group.all_lights
- group.all_locks
Buttons row
分隔线上方是常规实体行,下方是 buttons
类型的行。请注意,常规实体行会自动显示实体名称,而对于按钮,你必须明确指定标签/名称。
按钮行的截图。
type: entities
entities:
- entity: light.office_ceiling
- entity: light.dining_ceiling
- type: divider
- type: buttons
entities:
- entity: light.office_ceiling
name: Office Ceiling
- entity: light.dining_ceiling
name: Dining Ceiling
Other special rows
其他特殊行的截图。
type: entities
title: Entities card sample
entities:
- type: button
icon: mdi:power
name: Bed light transition
action_name: Toggle light
tap_action:
action: perform-action
perform_action: light.toggle
data:
entity_id: light.bed_light
transition: 10
- type: divider
- type: attribute
entity: sun.sun
attribute: elevation
name: Sun elevation
prefix: "~"
suffix: Units
- type: conditional
conditions:
- entity: sun.sun
state: above_horizon
row:
entity: sun.sun
type: attribute
attribute: azimuth
icon: mdi:angle-acute
name: Sun azimuth
- type: section
label: Section example
- type: weblink
name: Home Assistant
url: https://www.home-assistant.io/
icon: mdi:home-assistant
- type: button
name: Power cycle LibreELEC
icon: mdi:power-cycle
tap_action:
action: perform-action
confirmation:
text: Are you sure you want to restart?
perform_action: script.libreelec_power_cycle