Need help with selectattr/rejectattr filters

I have the following YAML code that gives me a list of all entities that can be updated:

{% set entities = states|selectattr('domain','in','update') %}
{% set updates = entities|map(attribute='entity_id')|list|sort %}

{{ updates }}

How can I use selectattr or rejectattr filters to get only the entities that have an update available and their state is β€˜on’?

I am really having trouble using the Jinja2 documentation and applying it to Home Assistant, so I was hoping that maybe someone here just knows how to do it.

{% set entities = states|selectattr('domain','in','update')|selectattr('state','eq','on') %}
{% set updates = entities|map(attribute='entity_id')|list|sort %}

{{ updates }}
1 Like

Instead of taking all state objects and filtering to the update domain why not just start with the update domain directly?

{% set entities = states.update|selectattr('state','eq','on') %}
1 Like

Opps. Yeah I meant to change that too. Thanks. Must be time for bed.

2 Likes

Great. Thank you!