I found this template sensor in the GitHub Home Assistant configuration package of someone I know to be a competent user. It appears to be a template that weights 2 presence entities and produces a result based on that weighting.
{% set weight_values = {
'sensor.xxxx_xxxx_xxxx_presence': 0.8,
'sensor.xxxx_xxxx_xxxx_presence': 1.0
} %}
{% set presence = {} %}
{% for entity_id, weight in weight_values.items() %}
{% if states(entity_id) not in presence %}
{% set presence = presence | merge({(states(entity_id)): weight}) %}
{% else %}
{% set presence = presence | merge({(states(entity_id)): presence[states(entity_id)] + weight}) %}
{% endif %}
{% endfor %}
{% if presence|length > 0 %}
{% set highest_presence = presence|max %}
{% for room, value in presence.items() %}
{% if value == highest_presence %}
{{ room }}
{% endif %}
{% endfor %}
{% else %}
unknown
{% endif %}
but when I enter it into the template editor I get a
TemplateRuntimeError: no filter named 'merge' found.
I checked the stock list of Jinja2 filters and sure enough there is no merge
filter listed.
What’s going on here and why would someone use a filter that is not known?