Skip to content
Skills Library
Programming · Building & coding

ha-templates

/ha-templates

Writes and fixes Home Assistant Jinja templates and template entities: safe defaults, availability, trigger-based template sensors, the modern template: integration (legacy platform: template is removed). Use for "template sensor", "Jinja in Home Assistant", "template error".

Licence
MIT
Last repository change
26.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
2
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 26.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Writes and fixes Home Assistant Jinja templates and template entities: safe defaults, availability, trigger-based template sensors, the modern template: integration (legacy platform: template is removed). Use for "template sensor", "Jinja in Home Assistant", "template error".

Triggers from the description

template sensorJinja in Home Assistanttemplate error
Original author description

Writes and fixes Home Assistant Jinja templates and template entities: safe defaults, availability, trigger-based template sensors, the modern template: integration (legacy platform: template is removed). Use for "template sensor", "Jinja in Home Assistant", "template error".

How it works

  1. Rules
  2. Template entities
  3. Debug
Original SKILL.md headings · 49 lines, 346 words
SKILL.md preview
---
name: ha-templates
version: 1.0.0
description: 'Writes and fixes Home Assistant Jinja templates and template entities: safe defaults, availability, trigger-based template sensors, the modern template: integration (legacy platform: template is removed). Use for "template sensor", "Jinja in Home Assistant", "template error".'
metadata:
  category: home-automation
---

# HA Templates

Templates compute values from states with Jinja. Test every template against the live instance before saving (`POST /api/template` or Tools → Template, `skills/ha-live-instance`).

## Rules

1. **Safe accessors:** `states('sensor.x')`, `state_attr('climate.x', 'temperature')`, `is_state('lock.x', 'locked')`, `has_value('sensor.x')`. Never `states.sensor.x.state`: it errors when the entity is missing.
2. **States are strings.** Convert with a default: `states('sensor.power') | float(0)`, `| int(0)`; without a default the template fails on `unknown` or `unavailable`. `int` truncates; round on purpose (`| round(1)`).
3. **Handle missing data explicitly:** prefer an `availability:` template that makes the entity `unavailable` over silently reporting 0.
4. **Templates are the last resort.** Use a native trigger or condition, or a helper (threshold, min_max, derivative, utility_meter, statistics) when one fits; a UI helper is easier to maintain.
5. **Time:** `now()`, `today_at('07:30')`, `as_timestamp()`, `as_datetime()`; templates using `now()` re-render once a minute, not every second.

## Template entities

The legacy `platform: template` under `sensor:`/`binary_sensor:` was deprecated in 2025.12 and **removed in 2026.6**. Use the top-level `template:` integration (UI template helpers cover the simple cases):

```yaml
template:
  - sensor:
      - name: House power
        unique_id: house_power
        unit_of_measurement: W
        device_class: power
        state_class: measurement
        state: >
          {{ states('sensor.grid_power') | float(0) + states('sensor.solar_power') | float(0) }}
        availability: >
          {{ has_value('sensor.grid_power') and has_value('sensor.solar_power') }}
  - triggers:
      - trigger: time_pattern
        hours: "/1"
    sensor:
      - name: Outdoor temperature hourly
        unique_id: outdoor_temperature_hourly
        unit_of_measurement: "°C"
        state: "{{ states('sensor.outdoor_temperature') | float(0) }}"
```

- Always set `unique_id` (makes the entity editable in the UI).
- **Trigger-based** blocks (`triggers:`, optional `conditions:` and `actions:`) update only when their trigger fires, not when referenced states change, and they restore their state after a restart.
- `device_class`, `state_class` and `unit_of_measurement` decide whether long-term statistics and the energy dashboard can use the sensor.

## Debug

- Error "float got invalid input 'unavailable' … no default was specified": add a default or an `availability` template.
- Value never changes: a trigger-based template waits for its trigger; a state-based one only listens to entities it read in the last render.
- Logs show template errors with the entity ID; Tools → Template shows which entities a template listens to.
Files in this package (2)
  • SKILL.md 3 KB
  • agents/openai.yaml 1 KB

Versions

The database has no other skills named ha-templates.

Database snapshot: 13.11.2026 · package version bc3a4f6eb5e7 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 3 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100frappe-impl-jinja
    Use when building Jinja templates in Frappe: Print Formats, Email Templates, Notification templates, Portal Pages, and custom Jinja methods. Covers template creation workflows, child table handling, conditional sections, styling, multi-language support, and debugging. Prevents…
  • 100printing-templates
    Build print formats, email templates, and web page templates using Jinja. Generate PDFs and configure letter heads. Use when creating custom print layouts, email templates, or any Jinja-based rendering in Frappe.
  • 100frappe-syntax-jinja
    Use when writing Jinja templates for ERPNext/Frappe Print Formats, Email Templates, and Portal Pages. Covers template syntax, context variables, filters, macros, and v16 Chrome PDF rendering. Prevents common mistakes with doc context and child table iteration. Keywords: Jinja,…
  • 100coding-python
    When python, flask, or jinja are being written or edited. Use this skill any time you are writing, editing, refactoring, or reviewing Python (.py), Django-related, Flask routes/blueprints, or Jinja2 templates (.jinja or .html with Jinja). Trigger even if the user only mentions a…
  • 100homeassistant-config
    Write, fix and modernise Home Assistant YAML with current (2026) syntax — automations, scripts, scenes, template entities, blueprints, packages, configuration.yaml and dashboards. Use whenever the task touches Home Assistant config files (/config or /homeassistant,…
  • 100ha-entities
    Home Assistant entity and domain management. Use when working with entity IDs, device classes, template entities, groups, or domain-specific attribute customizations.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.