Hi everyone,
I created a jinja macro in custom_templates folder. When i test the jinja part in the developer tools I get the right response. When i the use the function i get weird responses.
I call the function two times.
The function gives false back, but I get the result off true.
Why is this so?
Can someone help me?
{% macro LichterInBereichAn(area_name) %}
{% set ns = namespace(lights=[], groups=[]) %}
{% for area in floor_areas(area_name) %}
{% set entities = area_entities(area) | select('match', 'light.') | list %}
{% for entity in entities %}
{% if state_attr(entity, 'entity_id') is not none %}
{% if entity not in ns.groups %}
{% set ns.groups = ns.groups + [entity] %}
{% endif %}
{% else %}
{% set ns.is_in_group = false %}
{% for group in ns.groups %}
{% if entity in state_attr(group, 'entity_id') %}
{% set ns.is_in_group = true %}
{% endif %}
{% endfor %}
{% if not ns.is_in_group and entity not in ns.lights %}
{% set ns.lights = ns.lights + [entity] %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% set used_entities = ns.groups + ns.lights %}
{% set on_lights = used_entities | select('is_state', 'on') | list %}
{{on_lights | count > 0}}
{% endmacro %}