From the documentation Building Templates:
Templating in Home Assistant is powered by the Jinja2 templating engine.
So this {{ }}
and this {% %}
have special meaning in Jinja2.
In a nutshell, this:
{% %}
is used for expressions or logic whereas this:
{{ }}
is used for rendering a result.
Here’s a very simple example:
{% set x = 'cat' %}
The {{ x }} is in the house.
The result of these two lines is:
The cat is in the house.
Here’s another example:
{% set x = 10 %}
{% set y = 20 %}
{% if x == y %}
{{ x }} is the same as {{ y }}
{% else %}
{{ x }} is not the same as {{ y }}
{% endif %}
The result of all of this is:
10 is not the same as 20
One more (a very contrived example):
{% if states('switch.kitchen') == 'on' %}
{% set x = 'bright' %}
{% else %}
{% set x = 'dark' %}
{% endif %}
The kitchen is {{ x }}.
If the current state of switch.kitchen
is off
then the result would be:
The kitchen is dark.
Here’s the same example in inline format:
{% set x = 'bright' if states('switch.kitchen') == 'on' else 'dark' %}
The kitchen is {{ x }}.
If we apply everything we’ve learned so far, we get this:
The kitchen is {{'bright' if states('switch.kitchen') == 'on' else 'dark'}}.