Skip to article frontmatterSkip to article content
Documentation

Template engine

Because some like to make Home Assistant even harder for themselves πŸ˜…

Home Assistant has a powerful template engine that allows you to create complex automations and logic. The template engine is based on the Jinja2 template engine which is enriched with some Home Assistant-specific extensions.

Templates can be used in many places in Home Assistant, such as in automations, scripts, and scenes, and can even be used to create custom entities.

Spook extends the template engine of Home Assistant Core with even more functionality, making it even more powerful. Most of these make it easier to perform common tasks, while others provide completely new functionality.

New template functionsΒΆ

FlattenΒΆ

Flatten a lists of lists.

{{ flatten(["a", ["b", ["c"]]]) }}
{{ flatten(["a", ["b", ["c"]]], levels=1) }}

documentation πŸ“š

MD5ΒΆ

Calculate the MD5 hash of a given value.

{{ md5("hash me") }}

documentation πŸ“š

SHA1ΒΆ

Calculate the SHA1 hash of a given value.

{{ sha1("hash me") }}

documentation πŸ“š

SHA256ΒΆ

Calculate the SHA256 hash of a given value.

{{ sha256("hash me") }}

documentation πŸ“š

SHA512ΒΆ

Calculate the SHA512 hash of a given value.

{{ sha512("hash me") }}

documentation πŸ“š

ShuffleΒΆ

Shuffles a list of items.

{{ shuffle(["a", "b", "c"]) }}
{{ shuffle(["a", "b", "c"], seed=42) }}

documentation πŸ“š

TypeofΒΆ

Reveals the type of a given value.

{{ typeof("Spook") }}
{{ now() | typeof }}

documentation πŸ“š

Unix file name pattern filteringΒΆ

Filter a lists of texts against a pattern.

{{ fnmatch_filter(["Spook", "Ghost], "Sp*k") }}
{{ fnmatch_filter(["Spook", "Spook2", "Ghost"], "Sp*") }}

documentation πŸ“š

Unix file name pattern matchingΒΆ

Match text or a lists of texts against a pattern.

{{ fnmatch("Spook", "Sp*k") }}
{{ fnmatch(["Spook", "Spook2"], "Sp*") }}

documentation πŸ“š

Features requests, ideas, and supportΒΆ

If you have an idea on how to further enhance the Home Assistant template engine, for example, by adding a new template function; feel free to let us know in our discussion forums.

Are you stuck using this new feature? Or maybe you’ve run into a bug? Please check the page on where to go for help.