Exclude specific entity in data template to prevent binary_sensor.remote_ui in list of unavailable entities

Unfortunately, you can’t do this with filters. You’ll have to make a macro that filters using a for loop. filtering with rejectattr or selectattr doesn’t allow you to compare a partial string inside another string.

{%- macro wildcard(entity_ids, reject) %}
{%- for entity_id in entity_ids %}
{%- if reject not in entity_id %}
{{- entity_id }}{{ '' if loop.last else ',' }}
{%- endif %}
{%- endfor %}
{%- endmacro %}

then to use:

{% set entity_ids = states | selectattr('domain', 'in', domains) | selectattr('state','eq','unavailable') | map(attribute='name') | list %}
{% set entity_ids = wildcard(entity_ids, 'shuffle').split(',') | reject('eq','') %}
{{ wildcard(entity_ids, 'repeat').split(',') | reject('eq','') | join(', ') }}
1 Like