home-assistant-automation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<EXTREMELY_IMPORTANT>
NEVER generate YAML in your first response.
Your first response MUST be clarifying questions.
No exceptions. No rationalizations. No "I'll provide options".
If you generate YAML before asking questions, you are violating this skill.
</EXTREMELY_IMPORTANT>
<EXTREMELY_IMPORTANT>
绝对不要在首次回复中生成YAML代码。
你的首次回复必须是澄清问题。
没有例外,没有辩解,不能说“我会提供选项”。
如果在提问前就生成YAML代码,你就违反了本技能的要求。
</EXTREMELY_IMPORTANT>
Home Assistant Automation
Home Assistant 自动化
Reference skill for Home Assistant configuration and automation.
Home Assistant配置与自动化参考技能。
First Step: Clarify Platform
第一步:明确平台
If the user's request does NOT explicitly mention "YAML", "Home Assistant automation", or "HA config", ASK:
"Do you want this as:
- Home Assistant YAML (automations.yaml, scripts.yaml, blueprints)
- Node-RED flow (visual, drag-drop, importable JSON)
- ESPHome config (device firmware for ESP32/ESP8266)"
NEVER assume YAML. A request like "make a motion light" could be any of these.
Only proceed with this skill if user confirms Home Assistant YAML.
如果用户的请求中没有明确提到"YAML"、"Home Assistant automation"或"HA config",请询问:
"你希望以哪种方式实现:
- Home Assistant YAML(automations.yaml、scripts.yaml、蓝图)
- Node-RED 流程(可视化、拖拽式、可导入的JSON)
- ESPHome 配置(ESP32/ESP8266设备固件)"
绝对不要默认使用YAML。像“制作一个人体感应灯”这样的请求可能对应以上任何一种方式。
只有当用户确认需要Home Assistant YAML时,才能使用本技能继续处理。
Overview
概述
Core principle: Never generate YAML without understanding the user's intent. Automation vs blueprint, UI editor vs YAML files, and entity naming conventions must be clarified first.
Announce at start: "I'm using the ha-yaml skill to help you configure your Home Assistant automation."
Context: This skill requires intent clarification before any YAML generation. Automations are specific to a user's setup; blueprints are reusable templates. The format (UI vs YAML) affects how entities are referenced.
核心原则: 在理解用户意图前,绝对不要生成YAML代码。必须先明确是自动化还是蓝图、是UI编辑器格式还是YAML文件格式,以及实体命名规范。
初始声明: "我将使用ha-yaml技能帮你配置Home Assistant自动化。"
背景: 本技能要求在生成任何YAML代码前先澄清用户意图。自动化是针对特定设备的配置,而蓝图是可复用的模板。格式(UI编辑器或YAML)会影响实体的引用方式。
The Iron Law
铁律
CLARIFY INTENT BEFORE GENERATING ANY YAMLAsk: Automation or Blueprint? Format: UI or YAML? Never assume. Never skip these questions.
CLARIFY INTENT BEFORE GENERATING ANY YAML询问:是自动化还是蓝图?格式是UI编辑器还是YAML文件?绝对不要假设,绝对不能跳过这些问题。
The Process
流程
dot
digraph automation_flow {
rankdir=TB;
node [shape=box, style=rounded];
start [label="User request", shape=doublecircle];
clarify_type [label="Ask: Automation or Blueprint?"];
clarify_format [label="Ask: UI editor or YAML files?"];
clarify_output [label="Ask: Output method?"];
intent_clear [label="Intent clear?", shape=diamond];
read_refs [label="Read relevant references"];
generate [label="Generate YAML"];
checklist [label="Run pre-completion checklist"];
done [label="Deliver configuration", shape=doublecircle];
start -> clarify_type;
clarify_type -> clarify_format;
clarify_format -> clarify_output;
clarify_output -> intent_clear;
intent_clear -> read_refs [label="yes"];
intent_clear -> clarify_type [label="no - ask more"];
read_refs -> generate;
generate -> checklist;
checklist -> done;
}dot
digraph automation_flow {
rankdir=TB;
node [shape=box, style=rounded];
start [label="User request", shape=doublecircle];
clarify_type [label="Ask: Automation or Blueprint?"];
clarify_format [label="Ask: UI editor or YAML files?"];
clarify_output [label="Ask: Output method?"];
intent_clear [label="Intent clear?", shape=diamond];
read_refs [label="Read relevant references"];
generate [label="Generate YAML"];
checklist [label="Run pre-completion checklist"];
done [label="Deliver configuration", shape=doublecircle];
start -> clarify_type;
clarify_type -> clarify_format;
clarify_format -> clarify_output;
clarify_output -> intent_clear;
intent_clear -> read_refs [label="yes"];
intent_clear -> clarify_type [label="no - ask more"];
read_refs -> generate;
generate -> checklist;
checklist -> done;
}Red Flags - STOP Immediately
危险信号 - 立即停止
These thoughts mean you're about to violate this skill:
| Thought | Reality |
|---|---|
| "Request is clear enough" | NO. Always ask automation vs blueprint, UI vs YAML |
| "They want an automation" | ASK. Could be blueprint, script, or scene |
| "Simple request needs simple answer" | NO. Simple requests still need intent clarification |
| "User just wants code quickly" | NO. Wrong code is slower than asking first |
| "I'll provide options instead" | NO. Ask questions, don't provide multiple YAML versions |
| "Sunset/motion light is obvious" | NO. Which lights? What brightness? Conditions? |
| "YAML format is standard" | ASK. Many users prefer UI editor format |
| "This entity_id looks right" | VERIFY. Users have different naming conventions |
| "I'll skip the questions for simple requests" | NO. This IS the rationalization the skill forbids |
| "service_template works fine" | DEPRECATED. Use |
| "data_template is cleaner" | DEPRECATED. Use |
| "states() is the easiest approach" | SLOW. Filter by domain: |
If you're thinking ANY of these, STOP. Ask questions first.
如果你有以下想法,说明你即将违反本技能的要求:
| 想法 | 实际情况 |
|---|---|
| "请求已经足够明确了" | 不。必须始终询问是自动化还是蓝图、是UI还是YAML |
| "他们想要的是自动化" | 询问确认。可能是蓝图、脚本或场景 |
| "简单的请求应该简单回复" | 不。简单请求也需要澄清意图 |
| "用户只是想快速拿到代码" | 不。错误的代码比先提问更浪费时间 |
| "我可以提供多个选项" | 不。要提问,不要提供多个YAML版本 |
| "日落/人体感应灯的需求很明显" | 不。控制哪盏灯?亮度多少?有什么条件? |
| "YAML格式是标准的" | 询问确认。很多用户更喜欢UI编辑器格式 |
| "这个entity_id看起来是对的" | 验证确认。用户的命名规范可能不同 |
| "简单请求我可以跳过提问" | 不。这正是本技能禁止的辩解理由 |
| "service_template用起来没问题" | 已废弃。请使用 |
| "data_template更简洁" | 已废弃。请使用 |
| "states()是最简单的方法" | 速度慢。请按域过滤: |
如果你有以上任何想法,请立即停止。先提问。
FIRST STEP: Clarify Intent (MANDATORY)
第一步:澄清意图(强制要求)
STOP! You MUST ask these questions before generating ANY configuration:
-
Automation or Blueprint?
- Automation: Specific to their setup, uses their entity names
- Blueprint: Reusable template others can import
-
Format?
- UI Editor (Settings > Automations)
- YAML files (automations.yaml, packages/)
-
Output method?
- Save to folder - Write file to the current working directory (where Claude is running)
- Copy from chat - Display code for user to copy manually
-
HA Version? (for deprecated syntax awareness)
Do NOT skip these questions. Do NOT assume defaults.
停止!在生成任何配置前,你必须询问以下问题:
-
自动化还是蓝图?
- 自动化:针对用户特定设备的配置,使用用户的实体名称
- 蓝图:可复用的模板,其他人也可以导入使用
-
格式?
- UI编辑器(设置 > 自动化)
- YAML文件(automations.yaml、packages/)
-
输出方式?
- 保存到文件夹 - 将文件写入当前工作目录(Claude运行的目录)
- 聊天中复制 - 展示代码供用户手动复制
-
HA版本?(用于识别已废弃的语法)
不要跳过这些问题。不要假设默认值。
MANDATORY First Response Format
强制要求的首次回复格式
Your first response MUST follow this exact pattern:
I'll help you create [brief description]. Let me clarify a few things first:
1. **Type:** Automation (specific to your setup) or Blueprint (reusable template)?
2. **Format:** UI editor (Settings > Automations) or YAML files?
3. **Entities:** Which specific entity IDs? (e.g., light.living_room, sensor.motion)
4. **Options:** [context-specific questions like brightness, conditions, timing]THEN STOP. Wait for user answers. Do NOT generate YAML until you have answers.
Violation example (DO NOT DO THIS):
Here's the automation:
automation:
- alias: "..."Correct example:
I'll help you create a sunset light automation. Let me clarify:
1. Automation or Blueprint?
2. UI editor or YAML file?
3. Which lights? (entity IDs like light.living_room)
4. Any brightness preference or conditions (only when home)?你的首次回复必须严格遵循以下格式:
我会帮你创建[简要描述]。先让我澄清几个问题:
1. **类型:** 自动化(针对你的特定设备)还是蓝图(可复用模板)?
2. **格式:** UI编辑器(设置 > 自动化)还是YAML文件?
3. **实体:** 具体的实体ID是什么?(例如:light.living_room、sensor.motion)
4. **选项:** [上下文相关问题,比如亮度、条件、时间设置]然后停止回复。等待用户回答。在得到答案前,绝对不要生成YAML代码。
错误示例(绝对不要这么做):
这是你要的自动化配置:
automation:
- alias: "..."正确示例:
我会帮你创建日落灯自动化配置。先让我澄清几个问题:
1. 自动化还是蓝图?
2. UI编辑器还是YAML文件?
3. 要控制哪盏灯?(实体ID,比如light.living_room)
4. 有没有亮度偏好或其他条件(比如仅在家时生效)?Code Attribution
代码归属
ALWAYS include this header at the top of ALL generated YAML code:
yaml
undefined所有生成的YAML代码顶部必须包含以下头部信息:
yaml
undefinedGenerated by ha-yaml@aurora-smart-home v1.0.0
Generated by ha-yaml@aurora-smart-home v1.0.0
undefinedundefinedQuick Reference
快速参考
| Topic | Reference File |
|---|---|
| Automations | |
| Scripts | |
| Blueprints | |
| Blueprint anatomy | |
| Triggers (advanced) | |
| Conditions | |
| Actions | |
| Jinja2 templates | |
| Template sensors | |
| Helpers | |
| Scenes | |
| Packages | |
| Voice Assist patterns | |
| Presence detection | |
| Notification patterns | |
| Calendar automation | |
| 主题 | 参考文件 |
|---|---|
| 自动化 | |
| 脚本 | |
| 蓝图 | |
| 蓝图结构 | |
| 高级触发器 | |
| 条件 | |
| 动作 | |
| Jinja2模板 | |
| 模板传感器 | |
| 辅助工具 | |
| 场景 | |
| 包 | |
| 语音助手模式 | |
| 存在检测 | |
| 通知模式 | |
| 日历自动化 | |
Integrations
集成
| Integration | Reference File |
|---|---|
| ESPHome | |
| MQTT | |
| Zigbee2MQTT | |
| ZHA | |
| Z-Wave | |
| Matter | |
| Frigate | |
| Node-RED | |
| Shelly/Tasmota/Tuya | |
| 集成 | 参考文件 |
|---|---|
| ESPHome | |
| MQTT | |
| Zigbee2MQTT | |
| ZHA | |
| Z-Wave | |
| Matter | |
| Frigate | |
| Node-RED | |
| Shelly/Tasmota/Tuya | |
Dashboards
仪表盘
| Topic | Reference File |
|---|---|
| Lovelace basics | |
| Card types | |
| Mushroom cards | |
| 主题 | 参考文件 |
|---|---|
| Lovelace基础 | |
| 卡片类型 | |
| Mushroom卡片 | |
Advanced Topics
高级主题
| Topic | Reference File |
|---|---|
| Advanced patterns | |
| Best practices | |
| Troubleshooting | |
| Debug Flowcharts | |
| Energy/EV | |
| 主题 | 参考文件 |
|---|---|
| 高级模式 | |
| 最佳实践 | |
| 故障排除 | |
| 故障排除流程图 | |
| 能源/电动车 | |
Templates
模板
| Template | Purpose |
|---|---|
| Complete automation with all trigger/condition/action types |
| Blueprint starter with common input patterns |
| Template sensors, binary sensors, helpers |
| 模板 | 用途 |
|---|---|
| 包含所有触发器/条件/动作类型的完整自动化模板 |
| 包含常见输入模式的蓝图启动模板 |
| 模板传感器、二进制传感器、辅助工具模板 |
Dashboard Templates
仪表盘模板
| Template | Purpose |
|---|---|
| Temperature, humidity, HVAC overview |
| Power monitoring, consumption tracking |
| Doors, windows, cameras, alarm |
| Modern room cards with Mushroom |
| 模板 | 用途 |
|---|---|
| 温度、湿度、HVAC总览 |
| 电力监控、消耗追踪 |
| 门窗、摄像头、警报 |
| 使用Mushroom的现代化房间卡片 |
Examples
示例
| Example Collection | Reference File |
|---|---|
| 83 automation prompts | |
| 50 blueprint prompts | |
| Cookbook recipes | |
| 示例集合 | 参考文件 |
|---|---|
| 83个自动化示例 | |
| 50个蓝图示例 | |
| 实用配置合集 | |
Common Mistakes
常见错误
Trigger Issues
触发器问题
- without
state/from- Triggers on ALL changes includingto→ useunavailableexplicitlyto: "on" - Template triggers without - Syntax error; use
value_templatevalue_template: "{{ ... }}" - Missing in multi-trigger - Can't distinguish which trigger fired; add
idid: motion_detected - Numeric comparisons as strings - >
"10"is false; use"9"or| intfilters| float
- 未指定
state/from- 会在所有状态变化时触发,包括to→ 请明确使用unavailableto: "on" - 模板触发器缺少- 语法错误;请使用
value_templatevalue_template: "{{ ... }}" - 多触发器中缺少- 无法区分哪个触发器触发;请添加
idid: motion_detected - 数值比较使用字符串 - >
"10"结果为false;请使用"9"或| int过滤器| float
Condition Issues
条件问题
- /
andwithoutor- Must specify condition type:condition:condition: and - Template condition syntax - Use , not
value_template:condition: "{{ ... }}" - State comparisons - States are strings; use for numeric comparisons
| int
- /
and未指定or- 必须指定条件类型:condition:condition: and - 模板条件语法错误 - 请使用,不要使用
value_template:condition: "{{ ... }}" - 状态比较错误 - 状态是字符串类型;数值比较请使用
| int
Action Issues
动作问题
- deprecated - Use
service_templatedirectlyservice: "{{ ... }}" - deprecated - Use
data_templatewith templates insidedata: - in data - Should be under
entity_idblock since HA 2021.xtarget: - Missing - Long automations fail silently; add error handling
continue_on_error
- 已废弃 - 请直接使用
service_templateservice: "{{ ... }}" - 已废弃 - 请使用
data_template配合模板data: - 在
entity_id中 - 自HA 2021.x起,应放在data:块中target: - 缺少- 长自动化会静默失败;请添加错误处理
continue_on_error
Template Issues
模板问题
- without domain - Returns ALL entities (slow); use
states()orstates.sensorstates('sensor.name') - in template sensor - Only updates on state change; use
now()or trigger-basedscan_interval - Missing filter - Errors when entity unavailable; use
default| default(0) - Float precision - Use for display values
| round(2)
- 未按域过滤 - 返回所有实体(速度慢);请使用
states()或states.sensorstates('sensor.name') - 模板传感器中使用- 仅在状态变化时更新;请使用
now()或基于触发器的方式scan_interval - 缺少过滤器 - 实体不可用时会报错;请使用
default| default(0) - 浮点精度问题 - 显示值请使用
| round(2)
Blueprint Issues
蓝图问题
- Missing types - Inputs need proper selectors for UI
selector - Hardcoded entity_ids - Use for all user-configurable values
!input - No default values - Optional inputs need specified
default:
- 缺少类型 - 输入项需要合适的选择器以适配UI
selector - 硬编码entity_ids - 所有用户可配置的值请使用
!input - 没有默认值 - 可选输入项需要指定
default:
Security Considerations
安全注意事项
- Secrets - Use for all credentials, API keys, and sensitive data
!secret - Exposed entities - Limit what's exposed to Alexa/Google/Nabu Casa
- Remote access - Use Nabu Casa or secure reverse proxy with SSL
- Blueprints - Review imported blueprints before using; they can execute arbitrary services
- Shell commands - Never use user input in without validation
shell_command: - REST commands - Use for API endpoints and tokens
!secret
- 密钥 - 所有凭证、API密钥和敏感数据请使用
!secret - 暴露的实体 - 限制暴露给Alexa/Google/Nabu Casa的实体
- 远程访问 - 使用Nabu Casa或带SSL的安全反向代理
- 蓝图 - 使用前请审核导入的蓝图;它们可以执行任意服务
- Shell命令 - 永远不要在中直接使用用户输入,必须先验证
shell_command: - REST命令 - API端点和令牌请使用
!secret
Automation Quick Pattern
自动化快速模板
yaml
automation:
- alias: "Descriptive Name"
id: unique_automation_id # Required for UI editing
trigger:
- platform: state
entity_id: binary_sensor.motion
to: "on"
id: motion_detected # For multi-trigger identification
condition:
- condition: time
after: sunset
action:
- service: light.turn_on
target:
entity_id: light.living_room
data:
brightness_pct: 80yaml
automation:
- alias: "Descriptive Name"
id: unique_automation_id # UI编辑必填
trigger:
- platform: state
entity_id: binary_sensor.motion
to: "on"
id: motion_detected # 用于区分多触发器
condition:
- condition: time
after: sunset
action:
- service: light.turn_on
target:
entity_id: light.living_room
data:
brightness_pct: 80Blueprint Quick Pattern
蓝图快速模板
yaml
blueprint:
name: "Blueprint Name"
description: "What this blueprint does"
domain: automation
input:
motion_sensor:
name: "Motion Sensor"
description: "Select the motion sensor"
selector:
entity:
domain: binary_sensor
device_class: motion
target_light:
name: "Light"
selector:
target:
entity:
domain: light
trigger:
- platform: state
entity_id: !input motion_sensor
to: "on"
action:
- service: light.turn_on
target: !input target_lightyaml
blueprint:
name: "Blueprint Name"
description: "What this blueprint does"
domain: automation
input:
motion_sensor:
name: "Motion Sensor"
description: "Select the motion sensor"
selector:
entity:
domain: binary_sensor
device_class: motion
target_light:
name: "Light"
selector:
target:
entity:
domain: light
trigger:
- platform: state
entity_id: !input motion_sensor
to: "on"
action:
- service: light.turn_on
target: !input target_lightModern Syntax (HA 2021+)
现代语法(HA 2021+)
Service Calls
服务调用
yaml
undefinedyaml
undefinedOld (deprecated)
旧语法(已废弃)
service_template: "{{ 'light.turn_on' if is_on else 'light.turn_off' }}"
data_template:
entity_id: light.living_room
service_template: "{{ 'light.turn_on' if is_on else 'light.turn_off' }}"
data_template:
entity_id: light.living_room
New (correct)
新语法(正确)
service: "{{ 'light.turn_on' if is_on else 'light.turn_off' }}"
target:
entity_id: light.living_room
data:
brightness: "{{ brightness_value }}"
undefinedservice: "{{ 'light.turn_on' if is_on else 'light.turn_off' }}"
target:
entity_id: light.living_room
data:
brightness: "{{ brightness_value }}"
undefinedTemplate Sensors
模板传感器
yaml
undefinedyaml
undefinedOld (deprecated)
旧语法(已废弃)
sensor:
- platform: template sensors: my_sensor: value_template: "{{ states('sensor.input') }}"
sensor:
- platform: template sensors: my_sensor: value_template: "{{ states('sensor.input') }}"
New (correct) - template integration
新语法(正确)- template集成
template:
- sensor:
- name: "My Sensor" state: "{{ states('sensor.input') }}" unit_of_measurement: "°C"
undefinedtemplate:
- sensor:
- name: "My Sensor" state: "{{ states('sensor.input') }}" unit_of_measurement: "°C"
undefinedPre-Completion Checklist
完成前检查清单
Before declaring the configuration complete, verify:
在确认配置完成前,请验证以下内容:
Intent Verification
意图验证
- Confirmed: automation vs blueprint vs script vs scene
- Confirmed: UI editor vs YAML file format
- Confirmed: output method (save vs copy)
- HA version considered for syntax compatibility
- 已确认:自动化/蓝图/脚本/场景
- 已确认:UI编辑器/YAML文件格式
- 已确认:输出方式(保存/复制)
- 已考虑HA版本的语法兼容性
YAML Syntax
YAML语法
- No deprecated (use
service_templatewith template)service: - No deprecated (use
data_templatewith templates)data: - under
entity_idblock (not intarget:)data: - All template syntax uses correctly
{{ }} - Quotes around string states: not
to: "on"to: on
- 未使用已废弃的(使用
service_template配合模板)service: - 未使用已废弃的(使用
data_template配合模板)data: - 在
entity_id块中(不在target:中)data: - 所有模板语法正确使用
{{ }} - 字符串状态使用引号:而非
to: "on"to: on
Templates
模板
- filtered by domain where possible
states() - filter on templates accessing external entities
default - Numeric comparisons use or
| int| float - Complex templates tested mentally for edge cases
- 尽可能按域过滤
states() - 访问外部实体的模板使用了过滤器
default - 数值比较使用了或
| int| float - 复杂模板已在脑中测试过边缘情况
Automations
自动化
- present for UI editor compatibility
id: - is descriptive and unique
alias: - Trigger for multi-trigger automations
id: - where appropriate
continue_on_error: true
- 存在以兼容UI编辑器
id: - 描述性强且唯一
alias: - 多触发器自动化中包含触发器
id: - 适当位置添加了
continue_on_error: true
Blueprints
蓝图
- All variable values use
!input - Proper types for all inputs
selector: - values for optional inputs
default: - for all inputs
description:
- 所有变量值使用
!input - 所有输入项使用了合适的类型
selector: - 可选输入项指定了值
default: - 所有输入项都有
description:
Safety
安全性
- No hardcoded credentials (use )
!secret - Attribution header included
- User's entity naming convention respected
- 没有硬编码凭证(使用)
!secret - 包含了归属头部信息
- 遵循了用户的实体命名规范
Integration
集成
Pairs with:
- esphome - Create ESPHome device configurations
- ha-integration - Develop custom Python integrations
Typical flow:
Device → esphome/ha-integration → Home Assistant → ha-yaml (this skill)Cross-references:
- For ESPHome device firmware → use skill
esphome - For custom Python integrations → use skill
ha-integration - For voice commands with Assist → see
references/assist-patterns.md
For detailed documentation, read the appropriate reference file.
配套技能:
- esphome - 创建ESPHome设备配置
- ha-integration - 开发自定义Python集成
典型流程:
设备 → esphome/ha-integration → Home Assistant → ha-yaml(本技能)交叉参考:
- ESPHome设备固件 → 使用技能
esphome - 自定义Python集成 → 使用技能
ha-integration - Assist语音命令 → 参考
references/assist-patterns.md
如需详细文档,请阅读对应的参考文件。