动作

某些卡片支持点击动作。这些动作定义了当您点击或按住卡片中的对象时会发生什么。

以下卡片支持启用动作:

点击动作

当点击卡片上的对象时执行的动作。

tap_action:
  action: toggle

Configuration Variables

tap_action map (Optional)

点击时执行的动作。

action string Required

执行的动作(more-infotoggleperform-actionnavigateurlassistnone

Default:

toggle(如果提供的实体无法切换,某些卡片会将默认值覆盖为more-info

navigation_path string (Optional, default: none)

action定义为navigate时导航到的路径(例如,/lovelace/0/

navigation_replace boolean (Optional, default: none)

action定义为navigate时,是否用新URL替换历史记录中的当前页面

url_path string (Optional, default: none)

action定义为url时导航到的路径(例如,https://www.home-assistant.io

perform_action string (Optional, default: none)

action定义为perform-action时执行的动作(例如,media_player.media_play_pause

data string (Optional, default: none)

action定义为perform-action时包含的动作数据(例如,brightness: 100

target string (Optional, default: none)

action定义为perform-action时使用的动作目标(例如,entity_id: media_player.bedroom

confirmation boolean | map (Optional, default: false)

显示确认对话框以确认动作。请参阅下面的confirmation对象

pipeline_id string (Optional, default: last_used)

action定义为assist时使用的助理管道。可以是last_usedpreferred或管道ID。

start_listening boolean (Optional, default: none)

如果支持,在打开助理对话框并将action定义为assist时监听语音命令

entity string (Optional, default: none)

action定义为more-info时覆盖默认显示的实体

按住动作

当点击卡片上的对象,按住至少半秒钟然后释放时执行的动作。动作只会触发一次,而不是在按住期间连续触发。

hold_action:
  action: toggle

Configuration Variables

hold_action map (Optional)

点击并按住时执行的动作

action string Required, default: more-info

执行的动作(more-infotoggleperform-actionnavigateurlassistnone

navigation_path string (Optional, default: none)

action定义为navigate时导航到的路径(例如,/lovelace/0/

navigation_replace boolean (Optional, default: none)

action定义为navigate时,是否用新URL替换历史记录中的当前页面

url_path string (Optional, default: none)

action定义为url时导航到的路径(例如,https://www.home-assistant.io

perform_action string (Optional, default: none)

action定义为perform-action时执行的动作(例如,media_player.media_play_pause

data string (Optional, default: none)

action定义为perform-action时包含的动作数据(例如,brightness: 100

target string (Optional, default: none)

action定义为perform-action时使用的动作目标(例如,entity_id: media_player.bedroom

confirmation boolean | map (Optional, default: false)

显示确认对话框以确认动作。请参阅下面的confirmation对象

pipeline_id string (Optional, default: none)

action定义为assist时使用的助理管道ID

start_listening boolean (Optional, default: none)

如果支持,在打开助理对话框并将action定义为assist时监听语音命令

entity string (Optional, default: none)

action定义为more-info时覆盖默认显示的实体

双击动作

当双击卡片上的对象时执行的动作。

double_tap_action:
  action: toggle

Configuration Variables

double_tap_action map (Optional)

双击时执行的动作

action string Required, default: more-info

执行的动作(more-infotoggleperform-actionnavigateurlassistnone

navigation_path string (Optional, default: none)

action定义为navigate时导航到的路径(例如,/lovelace/0/

navigation_replace boolean (Optional, default: none)

action定义为navigate时,是否用新URL替换历史记录中的当前页面

url_path string (Optional, default: none)

action定义为url时导航到的路径(例如,https://www.home-assistant.io

perform_action string (Optional, default: none)

action定义为perform-action时执行的动作(例如,media_player.media_play_pause

data string (Optional, default: none)

action定义为perform-action时包含的动作数据(例如,brightness: 100

target string (Optional, default: none)

action定义为perform-action时使用的动作目标(例如,entity_id: media_player.bedroom

confirmation boolean | map (Optional, default: false)

显示确认对话框以确认动作。请参阅下面的confirmation对象

pipeline_id string (Optional, default: none)

action定义为assist时使用的助理管道ID

start_listening boolean (Optional, default: none)

如果支持,在打开助理对话框并将action定义为assist时监听语音命令

entity string (Optional, default: none)

action定义为more-info时覆盖默认显示的实体

确认选项

如果将确认定义为对象而不是布尔值,您可以添加更多自定义和配置。

double_tap_action:
  action: perform-action
  confirmation:
    text: 您确定要重启吗?
  perform_action: script.restart
hold_action:
  action: perform-action
  confirmation: true
  perform_action: script.do_other_thing

Configuration Variables

text string (Optional)

在确认对话框中显示的文本。

exemptions list (Optional)

包含exemption对象的列表。请参阅下文

免除选项

Configuration Variables

user string Required

不会显示确认对话框的用户ID。

double_tap_action:
  action: perform-action
  confirmation:
    text: 您确定要重启吗?
    exemptions:
      - user: x9405b8c64ee49bb88c42000e0a9dfa8
      - user: 88bcfbdc39155d16c3b2d09cbf8b0367
  perform_action: script.restart

示例

在实体按钮卡片上实现点击动作:

type: button
tap_action:
  action: toggle
hold_action:
  action: more-info

限制

无法为动作使用模板。但调用脚本是一个不错的替代方案。