home-assistant-best-practices
Best practices for Home Assistant automations, helpers, scripts, and device controls. TRIGGER THIS SKILL WHEN: - Creating or editing HA automations, scripts, or scenes - Choosing between template sensors and built-in helpers - Writing or restructuring triggers, conditions, or automation modes - Setting up Zigbee button/remote automations (ZHA or Zigbee2MQTT) - Renaming entities or migrating device_id references to entity_id SYMPTOMS THAT TRIGGER THIS SKILL: - Agent uses Jinja2 templates where native conditions, triggers, or helpers exist - Agent uses device_id instead of entity_id in triggers/actions - Agent modifies entity IDs or config objects without checking all consumers - Agent chooses wrong automation mode (e.g., single for motion lights)
NPX Install
npx skill4agent add homeassistant-ai/skills home-assistant-best-practicesTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Home Assistant Best Practices
Decision Workflow
0. Gate: modifying existing config?
references/safe-refactoring.md1. Check for native condition/trigger
references/automation-patterns.md- →
{{ states('x') | float > 25 }}condition withnumeric_stateabove: 25 - →
{{ is_state('x', 'on') and is_state('y', 'on') }}with state conditionscondition: and - →
{{ now().hour >= 9 }}withcondition: timeafter: "09:00:00" - →
wait_template: "{{ is_state(...) }}"with state trigger (caveat: different behavior when state is already true — seewait_for_trigger)references/safe-refactoring.md#trigger-restructuring
2. Check for built-in helper
references/helper-selection.md- Sum/average multiple sensors → integration
min_max - Binary any-on/all-on logic → helper
group - Rate of change → integration
derivative - Cross threshold detection → integration
threshold - Consumption tracking → helper
utility_meter
3. Select correct automation mode
singlereferences/automation-patterns.md#automation-modes| Scenario | Mode |
|---|---|
| Motion light with timeout | |
| Sequential processing (door locks) | |
| Independent per-entity actions | |
| One-shot notifications | |
4. Use entity_id over device_id
device_idreferences/device-control.md5. For Zigbee buttons/remotes
- ZHA: Use trigger with
event(persistent)device_ieee - Z2M: Use trigger (autodiscovered) or
devicetriggermqtt
references/device-control.md#zigbee-buttonremote-patternsCritical Anti-Patterns
| Anti-pattern | Use instead | Why | Reference |
|---|---|---|---|
| | Validated at load, not runtime | |
| | Event-driven, not polling; waits for change (see | |
| | device_id breaks on re-add | |
| | Re-triggers must reset the timer | |
| Template sensor for sum/mean | | Declarative, handles unavailable states | |
| Template binary sensor with threshold | | Built-in hysteresis support | |
| Renaming entity IDs without impact analysis | Follow | Renames break dashboards, scripts, and scenes silently | |
Reference Files
| File | When to read | Key sections |
|---|---|---|
| Renaming entities, replacing helpers, restructuring automations, or any modification to existing config | |
| Writing triggers, conditions, waits, or choosing automation modes | |
| Deciding whether to use a built-in helper vs template sensor | |
| Confirming templates ARE appropriate for a use case | |
| Writing service calls, Zigbee button automations, or using target: | |
| Need compound examples combining multiple best practices | — |