Home Assistant · Templates
Template Sensors in Home Assistant: The Modern Way
Template entities are how Home Assistant turns the data you already have into the sensor you actually wanted: an average of two room temperatures, a count of open doors, a cost estimate from a power reading. They are also the part of a configuration most likely to break silently in 2026, because the format most older tutorials teach no longer exists. The legacy platform syntax was deprecated in Home Assistant 2025.12 and removed in 2026.6, so on a current install it does not load at all. This guide teaches only the modern format, explains the difference between state-based and trigger-based templates, and covers the availability behavior that surprises almost everyone the first time.
Published Nov 23, 2026
The legacy format is gone, not deprecated
The old way of defining a template sensor put a platform: template entry under a platform key such as sensor:, with field names like value_template and availability_template. Home Assistant deprecated that format in the 2025.12 release, and each affected entity raised a Repair issue containing ready-to-paste modern YAML. The removal landed in 2026.6 after the six-month deprecation window. On Home Assistant 2026.11, a configuration that still uses platform: template simply does not create those entities. The current documentation states the position plainly: the older format is not supported anymore.
If you are migrating an older setup, the Repair issue for each entity is the fastest path, because it contains the converted YAML for that specific sensor. A community migration helper also exists for larger configurations. Either way, treat every tutorial, forum post and example you find that still shows platform: template as historical material. The examples may explain the idea well, but the syntax will not run.
The modern template block
Everything now lives under a single top-level template: key. Each list item groups entities by platform, and one block can mix platforms — a sensor and a binary sensor that belong together can sit side by side:
template:
- sensor:
- name: "Average temperature"
unique_id: average_temperature_main
unit_of_measurement: "°C"
state: >
{% set bedroom = states('sensor.bedroom_temperature') | float(0) %}
{% set kitchen = states('sensor.kitchen_temperature') | float(0) %}
{{ ((bedroom + kitchen) / 2) | round(1) }}
The field renames are the part to memorize when converting old examples: value_template became state:, and availability_template became availability:. Two options deserve to be in every template you write. unique_id: gives the entity a stable identity so it can be renamed and customized from the interface. default_entity_id: sets the entity ID you want at creation, which is more reliable than hoping the name produces the ID you expect. Guard your math as well: filters such as float(0) supply a fallback when a source sensor is unavailable, so one dead sensor produces a degraded number instead of a template error.
The Template integration is much broader than sensors. It supports twenty entity types: alarm control panel, binary sensor, button, climate, cover, device tracker, event, fan, image, light, lock, media player, number, select, sensor, switch, update, vacuum, water heater and weather. The same block structure and the same rules in this guide apply to all of them.
State-based templates: the default
A state-based template entity re-renders automatically whenever any entity referenced in its template changes. That makes it the right choice for derived values: averages, sums, unit conversions, cost calculations, and status sensors such as “any door open”. You write the expression, and Home Assistant keeps the result current without any automation.
The cost of that convenience is that the template renders often — every time any referenced entity updates. For ordinary household sensors that is irrelevant, but a template that scans every entity in the system on every state change anywhere can become a real load. Keep state-based templates scoped to the entities they actually need, and reach for the trigger-based form when a value only needs to change on a schedule or on a specific event.
Trigger-based templates: update only when told
Add a triggers: section and the entity changes character completely. A trigger-based template entity updates only when one of its triggers fires. The triggers use the same syntax as automation triggers — state, time pattern, webhook, event and MQTT triggers among them — and the block can also carry conditions:, an actions: section that can call services and use response data before the state renders, and trigger_variables: that are rendered once when the configuration loads.
Two properties define this form, and both are easy to get wrong. First, a trigger-based entity does not update when the entities named inside its state template change, unless you also add a trigger that matches those changes. Referencing a sensor in the expression is not a subscription. Second, the state and attributes of trigger-based entities are restored across restarts, with three exceptions: button, image and update entities do not restore. That persistence is what makes trigger-based templates the right tool for webhook-fed sensors, daily counters, and values that must update on a schedule rather than on every source change. One warning from the documentation deserves repeating: a trigger that fires on the template entity itself, or on something calculated from it, can loop and make Home Assistant unresponsive.
Trigger-based template entities are defined in YAML only. That limitation leads directly to the next section.
Template helpers in the interface
Home Assistant can create template entities without YAML: Settings, then Devices and services, then Helpers, then Create helper, then Template. The interface is a good place to build a first template sensor, and helpers you create there stay editable from the Helpers list afterwards.
Know the boundary before you rely on it. Interface-created template helpers are state-based only, and they expose a more limited subset of the options the YAML form supports. Trigger-based entities, the actions and conditions sections, and the full option set are YAML-only. A sensible workflow is to start in the interface for a simple derived sensor, and move to YAML the moment you need triggers, careful availability handling, or several related entities defined together in one block. YAML template entities can be reloaded from Developer Tools without a full restart, which makes iterating on them quick.
Availability: the rule that reads backwards
Any template entity can carry an availability: template. The entity counts as available when the template renders to true, “1”, “true”, “yes”, “on”, or a non-zero number, with letter case ignored. If no availability template is configured, the entity is always available.
Here is the counterintuitive part, stated exactly as the documentation defines it: a template that fails to render also counts as available. An error in your availability template does not take the entity offline — it does the opposite. That design means a broken availability expression hides the very problem it was meant to surface, so test availability templates deliberately by disabling the source sensor and watching what the entity does.
The modern idiom is to guard against stale sources rather than against errors. An expression built on the has_value test — checking that the source sensor currently holds a usable value — lets a derived sensor show as unavailable when its source dies, instead of displaying a confident-looking zero computed from nothing. Pair that with the float(0) style guards in the state template, and decide consciously which failure you prefer for each sensor: a fallback number, or an unavailable state your automations can react to.
A working checklist
Define template entities under the single template: key, never with the removed platform syntax. Give every entity a unique_id and, where the ID matters, a default_entity_id. Use state-based templates for derived values and trigger-based templates for scheduled, webhook-fed or event-fed values — and remember that only the trigger form needs YAML. Add an availability template when a source can go stale, and test it by breaking the source on purpose. Finally, when an old example will not load, check its format before you debug its logic: in 2026, the syntax is the most common fault.
Official documentation and references
- Home Assistant Template integration — the modern block, all twenty entity types, availability rules and trigger-based entities
- Home Assistant templating documentation — the Jinja functions and filters used inside state templates
- Home Assistant sensor platform — device classes, units and state classes for template sensors
Frequently asked questions
Does the old platform: template format still work?
No. It was deprecated in Home Assistant 2025.12, with a Repair issue offering converted YAML for each entity, and it was removed in 2026.6. On Home Assistant 2026.11 those entities do not load. Convert everything to the modern top-level template block, where value_template becomes state and availability_template becomes availability.
What is the difference between state-based and trigger-based template entities?
A state-based entity re-renders whenever any entity referenced in its template changes, which suits derived values such as averages and sums. A trigger-based entity updates only when one of its defined triggers fires, and its state is restored across restarts — except for button, image and update entities. Referencing a sensor inside a trigger-based template does not subscribe to that sensor; you must add a matching trigger.
Can I create trigger-based template entities in the interface?
No. Template helpers created under Settings, Devices and services, Helpers are state-based only, and they expose a more limited subset of options than YAML. Trigger-based entities, conditions and the actions section are YAML-only.
What happens when an availability template fails to render?
The entity counts as available. Availability is true when the template renders to true, “1”, “true”, “yes”, “on” or a non-zero number, and a render failure is treated as available as well. That is why availability templates should be tested by disabling the source sensor and observing the result.
How many kinds of template entity are there?
Twenty: alarm control panel, binary sensor, button, climate, cover, device tracker, event, fan, image, light, lock, media player, number, select, sensor, switch, update, vacuum, water heater and weather. All of them are defined in the same template block structure.
Do I need to restart Home Assistant for every template change?
No. YAML template entities can be reloaded from Developer Tools using the YAML reload controls, so most edits take effect without a full restart. A restart is still the fallback when a reload reports a configuration problem you need to read in the log.

