ha-button-cards
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWorks with Lovelace YAML dashboards and custom button-card integration.
适用于Lovelace YAML仪表盘和自定义button-card集成。
Home Assistant Button Cards
Home Assistant按钮卡片
Create interactive buttons for controlling devices, calling services, and navigating between views in Home Assistant dashboards.
为Home Assistant仪表盘创建可交互按钮,用于控制设备、调用服务和在不同视图间导航。
Overview
概述
This skill covers:
- Native Button Card: Simple entity controls with actions
- Custom Button Card (HACS): Advanced templating, state-based styling, multiple actions
- Action Types: tap, hold, double-tap behaviors
- Service Calls: Execute Home Assistant services
- Navigation: Move between dashboard views
- State-Based Styling: Dynamic colors and icons
本技能涵盖:
- 原生按钮卡片:带操作功能的简单实体控制
- 自定义按钮卡片(HACS):高级模板、基于状态的样式、多种操作
- 操作类型:点击、长按、双击行为
- 服务调用:执行Home Assistant服务
- 导航:在仪表盘视图间切换
- 基于状态的样式:动态颜色和图标
When to Use This Skill
适用场景
Use this skill when you need to:
- Create interactive buttons for toggling lights, switches, or climate controls
- Add service call buttons to execute automations or scripts
- Configure tap, hold, and double-tap actions for different behaviors
- Build navigation buttons to move between dashboard views
- Implement state-based styling with dynamic colors and icons
- Use custom button-card (HACS) for advanced templating and conditional logic
Do NOT use when:
- You only need to display sensor values without interaction (use entity card instead)
- Building complex multi-entity cards (use entities card or custom layouts)
在以下场景中使用本技能:
- 创建用于切换灯光、开关或温控设备的可交互按钮
- 添加服务调用按钮以执行自动化或脚本
- 配置点击、长按和双击操作以实现不同行为
- 构建导航按钮以在仪表盘视图间切换
- 实现带动态颜色和图标的基于状态样式
- 使用自定义button-card(HACS)实现高级模板和条件逻辑
请勿在以下场景使用:
- 仅需显示传感器数值而无需交互(请使用实体卡片)
- 构建复杂的多实体卡片(请使用实体列表卡片或自定义布局)
Quick Start
快速开始
Basic Toggle Button
基础切换按钮
yaml
type: button
entity: light.living_room
name: Living Room
show_state: true
icon: mdi:lightbulb
tap_action:
action: toggle
hold_action:
action: more-infoyaml
type: button
entity: light.living_room
name: Living Room
show_state: true
icon: mdi:lightbulb
tap_action:
action: toggle
hold_action:
action: more-infoService Call Button
服务调用按钮
yaml
type: button
name: Turn Off All Lights
icon: mdi:lightbulb-off
show_state: false
tap_action:
action: perform-action
perform_action: light.turn_off
data:
entity_id: allyaml
type: button
name: Turn Off All Lights
icon: mdi:lightbulb-off
show_state: false
tap_action:
action: perform-action
perform_action: light.turn_off
data:
entity_id: allNavigation Button
导航按钮
yaml
type: button
name: Bedroom
icon: mdi:bed
tap_action:
action: navigate
navigation_path: /lovelace/bedroomyaml
type: button
name: Bedroom
icon: mdi:bed
tap_action:
action: navigate
navigation_path: /lovelace/bedroomAction Types
操作类型
Home Assistant cards support three action types:
| Action | Trigger | Use Case |
|---|---|---|
| Single tap/click | Primary action (toggle, navigate, service call) |
| Press and hold 0.5s+ | Secondary action (more-info, different service) |
| Two quick taps | Tertiary action (navigate, custom service) |
Home Assistant卡片支持三种操作类型:
| 操作 | 触发方式 | 使用场景 |
|---|---|---|
| 单次点击 | 主要操作(切换、导航、服务调用) |
| 长按0.5秒以上 | 次要操作(查看详情、其他服务调用) |
| 快速双击 | tertiary操作(导航、自定义服务) |
Available Actions
可用操作
| Action | Description | Example Use |
|---|---|---|
| Do nothing | Disable interaction |
| Toggle entity on/off | Lights, switches |
| Show entity details dialog | View sensor history |
| Go to another view/dashboard | Room navigation |
| Open external URL | Documentation, web apps |
| Execute HA service | Scripts, automations, scenes |
| Trigger voice assistant | Voice commands |
| 操作 | 描述 | 示例场景 |
|---|---|---|
| 无操作 | 禁用交互 |
| 切换实体开关状态 | 灯光、开关 |
| 显示实体详情对话框 | 查看传感器历史数据 |
| 跳转到其他视图/仪表盘 | 房间导航 |
| 打开外部链接 | 文档、网页应用 |
| 执行Home Assistant服务 | 脚本、自动化、场景 |
| 触发语音助手 | 语音命令 |
Instructions
使用说明
Using Native Button Card
使用原生按钮卡片
The native button card provides basic entity control with action support.
原生按钮卡片提供带操作支持的基础实体控制功能。
Entity Toggle Button
实体切换按钮
yaml
type: button
entity: light.bedroom
name: Bedroom Light
icon: mdi:ceiling-light
show_name: true
show_icon: true
show_state: true
tap_action:
action: toggle
hold_action:
action: more-info
double_tap_action:
action: noneyaml
type: button
entity: light.bedroom
name: Bedroom Light
icon: mdi:ceiling-light
show_name: true
show_icon: true
show_state: true
tap_action:
action: toggle
hold_action:
action: more-info
double_tap_action:
action: noneClimate Control Button
温控设备控制按钮
yaml
type: button
entity: climate.living_room
name: AC
icon: mdi:air-conditioner
show_state: true
tap_action:
action: toggle
hold_action:
action: more-infoyaml
type: button
entity: climate.living_room
name: AC
icon: mdi:air-conditioner
show_state: true
tap_action:
action: toggle
hold_action:
action: more-infoScene Activation Button
场景激活按钮
yaml
type: button
name: Movie Mode
icon: mdi:movie
tap_action:
action: perform-action
perform_action: scene.turn_on
target:
entity_id: scene.movie_modeyaml
type: button
name: Movie Mode
icon: mdi:movie
tap_action:
action: perform-action
perform_action: scene.turn_on
target:
entity_id: scene.movie_modeScript Execution Button
脚本执行按钮
yaml
type: button
name: Good Night
icon: mdi:sleep
tap_action:
action: perform-action
perform_action: script.good_night
hold_action:
action: noneyaml
type: button
name: Good Night
icon: mdi:sleep
tap_action:
action: perform-action
perform_action: script.good_night
hold_action:
action: noneExternal URL Button
外部链接按钮
yaml
type: button
name: Router Admin
icon: mdi:router-wireless
tap_action:
action: url
url_path: http://192.168.1.1yaml
type: button
name: Router Admin
icon: mdi:router-wireless
tap_action:
action: url
url_path: http://192.168.1.1Assist/Voice Button
语音助手按钮
yaml
type: button
name: Voice Assistant
icon: mdi:microphone
tap_action:
action: assistyaml
type: button
name: Voice Assistant
icon: mdi:microphone
tap_action:
action: assistService Calls
服务调用示例
Turn Off All Lights
关闭所有灯光
yaml
type: button
name: All Lights Off
icon: mdi:lightbulb-off
tap_action:
action: perform-action
perform_action: light.turn_off
data:
entity_id: allyaml
type: button
name: All Lights Off
icon: mdi:lightbulb-off
tap_action:
action: perform-action
perform_action: light.turn_off
data:
entity_id: allSet Climate Temperature
设置温控温度
yaml
type: button
name: Set Temp 22°C
icon: mdi:thermostat
tap_action:
action: perform-action
perform_action: climate.set_temperature
target:
entity_id: climate.living_room
data:
temperature: 22yaml
type: button
name: Set Temp 22°C
icon: mdi:thermostat
tap_action:
action: perform-action
perform_action: climate.set_temperature
target:
entity_id: climate.living_room
data:
temperature: 22Turn On Light with Brightness
调亮灯光
yaml
type: button
name: Dim Lights
icon: mdi:lightbulb-on-50
tap_action:
action: perform-action
perform_action: light.turn_on
target:
entity_id: light.living_room_dimmer
data:
brightness: 150yaml
type: button
name: Dim Lights
icon: mdi:lightbulb-on-50
tap_action:
action: perform-action
perform_action: light.turn_on
target:
entity_id: light.living_room_dimmer
data:
brightness: 150Run Automation
触发自动化
yaml
type: button
name: Trigger Automation
icon: mdi:home-automation
tap_action:
action: perform-action
perform_action: automation.trigger
target:
entity_id: automation.motion_lightsyaml
type: button
name: Trigger Automation
icon: mdi:home-automation
tap_action:
action: perform-action
perform_action: automation.trigger
target:
entity_id: automation.motion_lightsNavigation Patterns
导航模式
Simple Navigation
简单导航
yaml
type: button
name: Go to Bedroom
icon: mdi:bed
tap_action:
action: navigate
navigation_path: /lovelace/bedroomyaml
type: button
name: Go to Bedroom
icon: mdi:bed
tap_action:
action: navigate
navigation_path: /lovelace/bedroomRoom Navigation Grid
房间导航网格
yaml
type: grid
columns: 2
cards:
- type: button
name: Living Room
icon: mdi:sofa
tap_action:
action: navigate
navigation_path: /lovelace/living-room
- type: button
name: Bedroom
icon: mdi:bed
tap_action:
action: navigate
navigation_path: /lovelace/bedroom
- type: button
name: Kitchen
icon: mdi:fridge
tap_action:
action: navigate
navigation_path: /lovelace/kitchen
- type: button
name: Outdoors
icon: mdi:tree
tap_action:
action: navigate
navigation_path: /lovelace/outdoorsyaml
type: grid
columns: 2
cards:
- type: button
name: Living Room
icon: mdi:sofa
tap_action:
action: navigate
navigation_path: /lovelace/living-room
- type: button
name: Bedroom
icon: mdi:bed
tap_action:
action: navigate
navigation_path: /lovelace/bedroom
- type: button
name: Kitchen
icon: mdi:fridge
tap_action:
action: navigate
navigation_path: /lovelace/kitchen
- type: button
name: Outdoors
icon: mdi:tree
tap_action:
action: navigate
navigation_path: /lovelace/outdoorsBack to Home Button
返回主页按钮
yaml
type: button
name: Home
icon: mdi:home
tap_action:
action: navigate
navigation_path: /lovelace/homeyaml
type: button
name: Home
icon: mdi:home
tap_action:
action: navigate
navigation_path: /lovelace/homeCustom Button Card (HACS)
自定义Button Card(HACS)
Installation: HACS → Frontend → Search "button-card"
The custom button-card provides extensive templating, state-based styling, and advanced action configurations. For complete template examples and advanced patterns, see references/custom-button-card-templates.md.
安装方法:HACS → 前端 → 搜索“button-card”
自定义button-card提供丰富的模板功能、基于状态的样式和高级操作配置。完整的模板示例和高级模式请参考references/custom-button-card-templates.md。
Basic Custom Button
基础自定义按钮
yaml
type: custom:button-card
entity: light.bedroom
name: Bedroom Light
show_state: true
icon: mdi:ceiling-light
tap_action:
action: toggle
hold_action:
action: more-infoyaml
type: custom:button-card
entity: light.bedroom
name: Bedroom Light
show_state: true
icon: mdi:ceiling-light
tap_action:
action: toggle
hold_action:
action: more-infoState-Based Styling
基于状态的样式
yaml
type: custom:button-card
entity: light.bedroom
name: Bedroom Light
show_state: true
icon: mdi:ceiling-light
color: auto
state:
- value: "on"
color: rgb(255, 200, 100) # Warm white when on
icon: mdi:ceiling-light-on
- value: "off"
color: rgb(100, 100, 100) # Gray when off
icon: mdi:ceiling-light-off
tap_action:
action: toggleSee references/custom-button-card-templates.md for advanced examples including temperature thresholds, multiple service calls, and icon-specific tap actions.
yaml
type: custom:button-card
entity: light.bedroom
name: Bedroom Light
show_state: true
icon: mdi:ceiling-light
color: auto
state:
- value: "on"
color: rgb(255, 200, 100) # 开启时为暖白色
icon: mdi:ceiling-light-on
- value: "off"
color: rgb(100, 100, 100) # 关闭时为灰色
icon: mdi:ceiling-light-off
tap_action:
action: toggle更多高级示例(包括温度阈值、多服务调用、图标专属点击操作等)请参考references/custom-button-card-templates.md。
Troubleshooting
故障排除
Button Not Responding
按钮无响应
- Check entity exists in HA (Developer Tools → States)
- Verify service name is correct (not
perform-actionin newer HA)call-service - Check browser console for errors (F12)
- 检查实体是否存在于Home Assistant中(开发者工具 → 状态)
- 确认服务名称正确(新版本Home Assistant中使用而非
perform-action)call-service - 查看浏览器控制台错误(F12)
Service Call Fails
服务调用失败
- Test service in Developer Tools → Services first
- Verify entity_id or target format
- Check service data syntax (YAML indentation)
- 先在开发者工具 → 服务中测试服务
- 确认entity_id或target格式正确
- 检查服务数据语法(YAML缩进)
Navigation Not Working
导航功能失效
- Ensure view path is defined (e.g., )
path: bedroom - Use full navigation path:
/lovelace/bedroom - Check for typos in navigation_path
- 确保视图路径已定义(例如)
path: bedroom - 使用完整导航路径:
/lovelace/bedroom - 检查navigation_path是否有拼写错误
Custom Button Card Not Loading
自定义Button Card无法加载
- Verify HACS installation (Frontend category)
- Clear browser cache (Ctrl+Shift+R)
- Check Lovelace resources (Settings → Dashboards → Resources)
- 确认已通过HACS安装(前端分类)
- 清除浏览器缓存(Ctrl+Shift+R)
- 检查Lovelace资源设置(设置 → 仪表盘 → 资源)
References
参考资料
For advanced configurations, see:
- references/action-reference.md - Complete action type documentation
- references/service-calls.md - Common service call patterns
- references/custom-button-card-templates.md - Reusable button templates
高级配置请参考:
- references/action-reference.md - 完整操作类型文档
- references/service-calls.md - 常见服务调用模式
- references/custom-button-card-templates.md - 可复用按钮模板