Code for Single exclusion works fine. I tried multiple loop methods but cannot get the code to do multiple exclusions no matter how I split the list or if I make the list separate lines (preferred - easier to read and not fat finger) or comma delimited… sometimes it just ignores the exclusions, other times it excludes everything (output empty list)…
Post the code, excluding entities depends on the code in question and the selectors that are used in the blueprints. I mentioned this to you in another thread and you glossed over the response. If you want help with it, I can help you but I need that information.
if entities are a list, and that blueprint is what you’re going off of, all you need is:
{% for switch in states.switch | rejectattr('entity_id', 'in', exclude_entities) %}
for each for loop that you do.
If exclude_entities is a list or a string, you need to account for that ahead of time with:
{% set exclude_entities = exclude_entities if exclude_entities is list else [exclude_entities] %}
or
{% set exclude_entities = [exclude_entities] if exclude_entities is string else exclude_entities %}
{% set exclude_patterns = exclude_strings.split('\n') | map('trim') | reject('eq', '') | list if exclude_strings is defined and exclude_strings != "" else [] %}
But it will be hard to use. Change it to this instead:
{% set exclude_regex = exclude_strings.split('\n') | map('trim') | reject('eq', '') | list | join('|') if exclude_strings is defined else 'abcdefghijklmnopqrstuvwxyz' %}
Then add this to each loop
{% for binary_sensor in states.binary_sensor | rejectattr('entity_id', 'search', exclude_regex)
It will reject things contained in your entity_id’s, if it’s not provided it will default to reject the literal string abcdefghijklmnopqrstuvwxyz which is really unlikely to exist in any entity_id.
correction (I had my other test version still in there)… your version is not running at all, just Logs an error…
Logger: homeassistant.components.automation.offline_devices_report
Source: components/automation/__init__.py:663
integration: Automation (documentation, issues)
First occurred: 7:22:37 AM (9 occurrences)
Last logged: 1:39:05 PM
Error rendering variables: TemplateRuntimeError: No test named 'string_template_match' found.
Error rendering variables: TypeError: 'in <string>' requires string as left operand, not LoggingUndefined
Error rendering variables: PatternError: nothing to repeat at position 0
I’ll try restarting HA completely… I’ve heavily mod’d a few blueprints without any issues. When I’ve tried to have multi-string (more than one) excludes or even single label excludes in any of them it always fails. I’ve seen others posting they were never able to get labels working.
This is what is frustrating… dead simple if I used VB, JS… but these templates are a nightmare for this stuff.
ok, fair, I had no clue you were talking about something else. ‘Raw Log’ shows this…
e[31m2025-05-09 13:13:26.586 ERROR (MainThread) [homeassistant.components.automation.offline_devices_report] Error rendering variables: PatternError: nothing to repeat at position 0e[0m
And can you show the automation configuration in yaml. Or download the trace and post the JSON here. I don’t see how an error like that could even be produced if it wasn’t running the automation.
Well, I loaded your blueprint. You’re mixing tabs and spaces, you need to choose one or the other not both. So replace all tabs with 4 spaces.
It also looks like you left a bunch of left over code in there that’s also causing exceptions left and right. I’m getting the following errors:
2025-05-09 16:20:00.335 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'exclude_patterns' is undefined when rendering '{% set exclude_entities = exclude_entities if exclude_entities is list else [exclude_entities] %} {% set exclude_regex = exclude_strings.split('\n') | map('trim') | reject('eq', '') | list | join('|') if exclude_strings is defined else 'abcdefghijklmnopqrstuvwxyz' %} {% set result = namespace(offline_devices=[]) %} {% for sensor in states.sensor | rejectattr('entity_id', 'search', exclude_regex) | selectattr('attributes.device_class', 'defined') | selectattr('attributes.device_class', '==', 'battery') %}
and
2025-05-09 16:20:00.338 ERROR (MainThread) [homeassistant.components.automation.offline_devices_report_v15_petro] Error rendering variables: TypeError: 'in <string>' requires string as left operand, not LoggingUndefined