Skip to main content
Template functions use Home Assistant’s Jinja2 templating to return dynamic values. They’re ideal for retrieving entity states, attributes, or generating formatted responses.

Configuration

string
required
Jinja2 template that returns the function result

Examples

Get Current Weather

This simple example demonstrates template syntax:
Weather Template
This is a simplified example from the OpenAI documentation.

Get Entity Attributes

Access state and attributes of one or multiple entities.
Get Attributes
This function returns attributes in CSV format, making it easy for the AI to parse and understand multiple entities at once.

Template Features

Use Cases

Entity Queries

Retrieve current states and attributes of entities

Calculations

Perform math operations on sensor values

Formatting

Format data for natural language responses

Filtering

Filter entities by state, area, or attributes

Best Practices

1

Keep templates simple

Use template functions for simple data retrieval. For complex logic, consider composite functions.
2

Handle missing values

Always use default values and safe filters:
3

Format for readability

Return human-readable text that the AI can use in responses:

Next Steps

Script Functions

Execute service sequences

Composite Functions

Combine templates with other functions

Template Documentation

Home Assistant templating guide