关于 ha-entities
面向 Home Assistant 用户和 Agent 的实体参考技能,介绍域、自定义、模板、组、属性与状态访问;不侧重自动化规则。
主要功能
- 01实体域与 ID 结构
- 02实体自定义
- 03模板传感器
- 04组与设备类别
- 05状态和属性访问
适用场景
- 01识别合适的实体域
- 02自定义实体名称和图标
- 03创建模板传感器
- 04在模板中读取实体状态
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ laurigates/ claude-plugins --skill ha-entities安装后在 Claude Code 中输入/ha-entities确认已加载。
附带文件REFERENCE.md
详细介绍
Home Assistant 实体
何时使用此技能
| 在以下情况下使用此技能…… | 在以下情况下改用 ha-automations…… |
|---|---|
| 了解实体域 | 创建自动化规则 |
| 自定义实体 | 处理触发器/操作 |
| 创建模板传感器 | 编写自动化条件 |
| 设置组 | 处理脚本/场景 |
| 处理设备类别 | 处理事件 |
实体 ID 结构
domain.object_id
示例:
light.living_room_ceilingsensor.outdoor_temperaturebinary_sensor.front_door_contactswitch.garden_irrigation
常见域
| 域 | 描述 | 示例 |
|---|---|---|
light | 照明控制 | light.kitchen |
switch | 开/关开关 | switch.outlet |
sensor | 数值传感器 | sensor.temperature |
binary_sensor | 开/关传感器 | binary_sensor.motion |
climate | HVAC 控制 | climate.thermostat |
cover | 百叶窗、车库门 | cover.garage |
lock | 门锁 | lock.front_door |
media_player | 媒体设备 | media_player.tv |
camera | 摄像头画面 | camera.front_yard |
vacuum | 扫地机器人 | vacuum.roomba |
fan | 风扇控制 | fan.bedroom |
alarm_control_panel | 报警系统 | alarm_control_panel.home |
person | 人员追踪 | person.john |
device_tracker | 设备位置 | device_tracker.phone |
weather | 天气信息 | weather.home |
input_boolean | 虚拟开关 | input_boolean.guest_mode |
input_number | 虚拟数字 | input_number.target_temp |
input_select | 虚拟下拉菜单 | input_select.house_mode |
input_text | 虚拟文本 | input_text.message |
input_datetime | 虚拟日期/时间 | input_datetime.alarm |
input_button | 虚拟按钮 | input_button.reset |
automation | 自动化 | automation.motion_light |
script | 脚本 | script.morning_routine |
scene | 场景 | scene.movie_night |
group | 实体组 | group.all_lights |
timer | 倒计时器 | timer.laundry |
counter | 计数器 | counter.guests |
zone | 地理区域 | zone.home |
sun | 太阳位置 | sun.sun |
完整的设备类别表(二进制传感器和传感器)请参阅 REFERENCE.md。
实体自定义
customize.yaml
# Single entity
light.living_room:
friendly_name: "Living Room Light"
icon: mdi:ceiling-light
# Binary sensor
binary_sensor.front_door:
friendly_name: "Front Door"
device_class: door
# Sensor
sensor.outdoor_temperature:
friendly_name: "Outdoor Temperature"
device_class: temperature
unit_of_measurement: "°C"
Glob 自定义
customize_glob:
"light.*_ceiling":
icon: mdi:ceiling-light
"sensor.*_temperature":
device_class: temperature
unit_of_measurement: "°C"
"binary_sensor.*_motion":
device_class: motion
模板传感器
template:
- sensor:
# Simple state
- name: "Average Temperature"
unit_of_measurement: "°C"
device_class: temperature
state: >-
{{ ((states('sensor.living_room_temp') | float +
states('sensor.bedroom_temp') | float +
states('sensor.kitchen_temp') | float) / 3) | round(1) }}
# With attributes
- name: "Power Usage"
unit_of_measurement: "W"
device_class: power
state: "{{ states('sensor.energy_meter_power') }}"
attributes:
cost_per_hour: >-
{{ (states('sensor.energy_meter_power') | float * 0.15 / 1000) | round(2) }}
# Availability
- name: "Solar Power"
unit_of_measurement: "W"
device_class: power
state: "{{ states('sensor.inverter_power') }}"
availability: "{{ states('sensor.inverter_power') != 'unavailable' }}"
有关模板二进制传感器、开关、按钮、数字、组、实用计量器、计数器和计时器,请参阅 REFERENCE.md。
状态属性
常见属性
| 域 | 常见属性 |
|---|---|
light | brightness、color_temp、rgb_color、hs_color、effect |
climate | temperature、current_temperature、hvac_action、preset_mode |
media_player | volume_level、media_title、media_artist、source |
cover | current_position、current_tilt_position |
weather | temperature、humidity、pressure、wind_speed、forecast |
person | source、latitude、longitude、gps_accuracy |
sun | elevation、azimuth、next_rising、next_setting |
访问属性
# In templates
{{ state_attr('light.living_room', 'brightness') }}
{{ state_attr('climate.thermostat', 'current_temperature') }}
{{ state_attr('sun.sun', 'elevation') }}
# In conditions
condition:
- condition: numeric_state
entity_id: light.living_room
attribute: brightness
above: 100
快速参考
状态函数
| 函数 | 描述 | 示例 |
|---|---|---|
states('entity') | 获取状态 | states('sensor.temp') |
state_attr('entity', 'attr') | 获取属性 | state_attr('light.x', 'brightness') |
is_state('entity', 'value') | 检查状态 | is_state('light.x', 'on') |
is_state_attr('entity', 'attr', 'val') | 检查属性 | is_state_attr('climate.x', 'hvac_action', 'heating') |
states.domain | 域中的所有实体 | states.light |
expand('group.x') | 展开组成员 | expand('group.all_lights') |
Agentic Optimizations
| Context | Command |
|---|---|
| Find entity usage | grep -r "entity_id:" config/ --include="*.yaml" |
| List customizations | grep -rA2 "^[a-z_]*\\..*:" config/customize.yaml |
| Find template sensors | grep -rB2 "platform: template" config/ --include="*.yaml" |
| Find groups | grep -rA5 "^group:" config/ --include="*.yaml" |
| List domains used | grep -roh "[a-z_]*\\." config/ --include="*.yaml" | sort -u |
评论
支持 Markdown