Skip to content

v1.5.0: Jinja2-style template filters

Choose a tag to compare

@sxdjt sxdjt released this 10 Mar 06:32

What's New in v1.5.0

Added

  • Jinja2-style template filters for text_template: The text_template field now supports
    a filter pipeline using {{ variable | filter }} syntax, compatible with common Jinja2 filters

Variables:

  • state - entity state (respects decimals config)
  • name - entity friendly name
  • attributes.<attr> - any entity attribute (e.g. attributes.unit_of_measurement)

Filters:

  • upper - convert to uppercase
  • lower - convert to lowercase
  • title - title case
  • round(n) - round to n decimal places
  • int - convert to integer
  • float - convert to float
  • replace('a', 'b') - string replacement
  • truncate(n) - truncate to n characters
  • default('value') - fallback if value is empty

Examples:

text_template: "Charging:\n {{ state | upper }}"
text_template: "{{ state | round(1) }} {{ attributes.unit_of_measurement }}"
text_template: "{{ state | replace('_', ' ') | title }}"
text_template: "{{ state | upper | truncate(8) }}"

Filters can be chained. Fully backward compatible with existing {{ state }} and {{ name }} templates.

See the README for full documentation.