State template functions
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.
Home Assistant extends the Jinja2 template engine with many custom functions, filters, and tests. Each function on this page has its own page with detailed descriptions, parameters, and practical examples.
New to templates? Start with the templating documentation to learn the basics.
-
Find entity
closestFinds the entity closest to a given location, home, or another entity. -
Calculate
distanceCalculates the distance in kilometers between two points or from home. -
Expand groups into entities
expandExpands groups and zones into a sorted list of individual entity state objects. -
Check if entity has a value
has_valueTests if an entity exists and has a valid state (not unavailable or unknown). -
Test entity state
is_stateTests if an entity is in a specific state. -
Test state attribute
is_state_attrTests if a specific attribute of an entity has a given value. -
Get state attribute
state_attrReturns the value of a specific attribute from an entity's state. -
Get translated attribute value
state_attr_translatedReturns the translated value of a specific attribute from an entity's state. -
Get translated state
state_translatedReturns the translated state value of an entity in your configured language. -
Get entity state
statesReturns the state value of an entity, or lets you iterate over all entity states.