关于 ha-automations
ha-automations 是面向 Home Assistant 自动化配置的技能,帮助编写触发器、条件、动作及脚本和场景。它还涵盖蓝图、自动化运行模式和常见规则示例。
主要功能
- 01编写自动化触发器、条件和动作
- 02配置脚本与场景
- 03使用自动化蓝图
- 04选择自动化运行模式
适用场景
- 01根据设备状态变化触发操作
- 02按时间或条件控制设备
- 03编写延迟、等待和分支动作
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ laurigates/ claude-plugins --skill ha-automations安装后在 Claude Code 中输入/ha-automations确认已加载。
附带文件REFERENCE.md
详细介绍
Home Assistant 自动化
何时使用此技能
| 在以下情况下使用此技能…… | 在以下情况下改用 ha-configuration…… |
|---|---|
| 创建自动化规则 | 编辑 configuration.yaml |
| 编写触发器/条件/操作 | 设置集成 |
| 使用脚本和场景 | 管理机密 |
| 使用蓝图 | 组织包 |
| 设置设备触发器 | 常规 YAML 配置 |
自动化结构
automation:
- id: "unique_automation_id"
alias: "Descriptive Name"
description: "What this automation does"
mode: single # single, restart, queued, parallel
trigger:
- platform: state
entity_id: binary_sensor.motion
to: "on"
condition:
- condition: time
after: "08:00:00"
before: "22:00:00"
action:
- service: light.turn_on
target:
entity_id: light.living_room
触发器类型
状态触发器
trigger:
# Basic state change
- platform: state
entity_id: binary_sensor.door
to: "on"
from: "off"
# With duration
- platform: state
entity_id: binary_sensor.motion
to: "off"
for:
minutes: 5
# Attribute change
- platform: state
entity_id: climate.thermostat
attribute: current_temperature
时间触发器
trigger:
# Specific time
- platform: time
at: "07:00:00"
# Input datetime
- platform: time
at: input_datetime.alarm_time
# Time pattern (every hour)
- platform: time_pattern
hours: "*"
minutes: 0
seconds: 0
# Every 15 minutes
- platform: time_pattern
minutes: "/15"
其他触发器类型(数值状态、日照、设备、事件、webhook、模板、区域)请参阅 REFERENCE.md。
条件类型
状态条件
condition:
# Single entity
- condition: state
entity_id: binary_sensor.door
state: "off"
# Multiple states allowed
- condition: state
entity_id: alarm_control_panel.home
state:
- armed_home
- armed_away
# Check for duration
- condition: state
entity_id: binary_sensor.motion
state: "off"
for:
minutes: 10
时间条件
condition:
# Time range
- condition: time
after: "08:00:00"
before: "22:00:00"
# Weekdays only
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
# Combined
- condition: time
after: "09:00:00"
before: "17:00:00"
weekday:
- mon
- tue
- wed
- thu
- fri
其他条件类型(数值状态、日照、模板、区域、逻辑、简写)请参阅 REFERENCE.md。
操作类型
服务调用
action:
# Basic service call
- service: light.turn_on
target:
entity_id: light.living_room
data:
brightness_pct: 80
color_temp: 350
# Multiple targets
- service: light.turn_off
target:
entity_id:
- light.bedroom
- light.bathroom
area_id: upstairs
延迟和等待
action:
- service: light.turn_on
target:
entity_id: light.living_room
# Fixed delay
- delay:
seconds: 30
# Wait for trigger
- wait_for_trigger:
- platform: state
entity_id: binary_sensor.motion
to: "off"
timeout:
minutes: 5
continue_on_timeout: true
# Wait for template
- wait_template: "{{ is_state('light.bedroom', 'off') }}"
timeout: "00:05:00"
If/Then/Else(现代写法)
action:
- if:
- condition: state
entity_id: binary_sensor.motion
state: "on"
then:
- service: light.turn_on
target:
entity_id: light.hallway
else:
- service: light.turn_off
target:
entity_id: light.hallway
有关高级操作模式(choose、repeat、变量、并行执行)、脚本、场景和常见自动化模式,请参阅 REFERENCE.md。
自动化模式
| 模式 | 行为 |
|---|---|
single | 运行期间忽略新的触发器 |
restart | 停止当前运行,然后启动新的运行 |
queued | 最多将 max 次运行加入队列 |
parallel | 最多并行运行 max 次 |
automation:
- alias: "Motion Light"
mode: restart
max: 10 # For queued/parallel
max_exceeded: silent # silent, warning, error
Agent 优化
| 上下文 | 命令 |
|---|---|
| 查找自动化 | grep -r "alias:" config/automations.yaml |
| 查找触发器 | grep -r "platform: state" config/ --include="*.yaml" |
| 列出脚本 | grep -r "^ [a-z_]*:" config/scripts.yaml |
| 查找场景 | grep -r "^ - name:" config/scenes.yaml |
| 检查自动化 ID | grep -r "^ - id:" config/automations.yaml |
评论
支持 Markdown