Template functions

Home Assistant extends the Jinja2 template engine with many custom functions, filters, and tests. Each one has its own page with detailed descriptions, parameters, and practical examples.

New to templates? Start with the templating documentation to learn the basics.

Areas

These template functions let you work with the areas you've set up in Home Assistant. Look up which entities or devices belong to an area, get area names and IDs, and build automations that operate on entire rooms at once.

Collections

These template functions help you work with collections of data: lists, sets, dictionaries, and JSON. Use them to combine, filter, sort, and reshape data from your entities, API responses, and incoming messages.

Comparison

These template tests let you compare values in your templates. Use them inside if conditions and filters to check equality, order, or membership.

Date & Time

These template functions help you work with dates, times, and durations. Use them to get the current time, format timestamps for display, calculate how long ago something happened, or convert between different time representations.

Devices

These template functions let you work with devices in Home Assistant. Look up device names, IDs, attributes, and find which entities belong to a device.

Encoding

These template functions encode, decode, and hash data. Use them to turn bytes into readable text, generate checksums, or prepare data for APIs that expect a specific encoding.

Entities

These template functions let you work with entities in Home Assistant. Get entity names, check visibility, and look up which integration or config entry an entity belongs to.

Floors

These template functions let you work with floors in Home Assistant. Look up floor names and IDs, find which areas belong to a floor, and get all entities across an entire floor.

Functional

These template functions help with control flow, conditional logic, and general utility operations. They let you make decisions, transform values, and work with data in flexible ways.

Labels

These template functions let you work with labels in Home Assistant. Labels are tags you can assign to entities, devices, and areas to organize them. Use these functions to look up labels, find items with specific labels, and build automations that act on labeled groups of items.

Math

These template functions provide mathematical operations for your templates. From basic arithmetic helpers to trigonometry, statistics, and value constraining, they let you perform calculations on sensor data, averages across rooms, and more.

Regex

These template functions let you search, match, and transform text with regular expressions. Use them when you need to extract specific parts of a string, validate formats, or replace patterns in sensor values.

Repairs

These template functions let you read the repair issues Home Assistant has flagged. Use them to build dashboards or notifications that surface problems needing your attention.

States

These template functions let you access and check the states of your entities. They are the foundation of most template logic in Home Assistant, letting you read sensor values, check if devices are on or off, and react to changes in your smart home.

Strings

These template functions help you format, transform, and shape text. Use them to build friendly messages, clean up sensor values, or prepare text for dashboards and notifications.

Type Conversion

These template functions convert values between text, numbers, and other types, and let you check what type a value currently is. Use them whenever you need to turn sensor states into numbers for math, or verify the shape of data before acting on it.