Template to filter certain update entities (ignoring ones with not met requirements)

I’d like to filter all update entities from HACS integration which do NOT contain something like <ha-alert alert-type='warning'>Requires Home Assistant.

What I have so far:

  {{ integration_entities('hacs')
      | select('match', 'update')
      | select('is_state','on')
      | selectattr('release_summary','defined')
      | selectattr('release_summary','ne','<ha-alert alert-type=\'warning\'>Requires Home Assistant')
      | list
      | length
  }}

This gives 0 at /developer-tools/template, without length I get [].


Because of annoying

one still needs to use | selectattr('release_summary','defined') before accessing the attribute, otherwise the dev tools section gives

How can I check this template now? Will it work?

Same is sooooo easy using custom:auto-entities with

                    filter:
                      include:
                        - domain: update
                          integration: hacs
                          state: 'on'
                          not:
                            attributes:
                              release_summary: <ha-alert alert-type='warning'>Requires Home Assistant *

According to the Studio Code Server “Generate Template” function, the | selectattr('release_summary','ne','<ha-alert alert-type=\'warning\'>Requires Home Assistant') is not respected.

Is this template part wrong?

The result of integration_entities('hacs') is an array of entity_id strings. While “select” supports this, I don’t believe “selectattr” does. Therefore you need to first use “expand”.

Then the HA attributes are under an attribute called “attributes”. Confusing, but it means you need “attributes.release_summary” instead of just “release_summary”.

And you’re “ne” match will not match anything, because it’s going to compare the whole string, not just the first part - so better to use “match” instead with “rejectattr” (assuming I following what you’re wanting to achieve).

{{
  integration_entities('hacs') 
    | select('match', 'update')
    | select('is_state','on')
    | expand
    | selectattr('attributes.release_summary','defined')
    | rejectattr('attributes.release_summary','match', 'Requires Home Assistant')
    | map(attribute='entity_id')
    | list
}}

1 Like

Oh wow! I’ll give that a try immediately to see if it works. Many thanks in advance :slight_smile:

Update: Gave it a try. Basically works great. It’s just the rejectattr part which needs a bit of tweaking (adding * wildcard to match all strings containing that search string, usually it’s a lot more text around that). In the end I used this:

{{
  integration_entities('hacs') 
    | select('match', 'update')
    | select('is_state','on')
    | expand
    | selectattr('attributes.release_summary','defined')
    | rejectattr('attributes.release_summary','match', '.*Requires Home Assistant.*')
    | map(attribute='entity_id')
    | list
    | length
}}

With this template I now get the number of available updates from HACS integration (experimental features enabled), which are actually installed (no HA dependency issues).

@michaelblight I’ll therefore of course mark your post as (ultimate) solution - thanks a lot!


Would you mind taking a look at this too maybe? It seems like you’re a pretty skilled Jinja template pro :wink: …and this one is causing me headache for quite some time: