Selectattr Problem

Hello everyone,

i have this code

{%set Lijst = states 
                         |selectattr('domain', '==', 'media_player') 
                         |selectattr('entity_id', 'search',Plaats|lower) 
                         |selectattr('entity_id', 'search', 'sonos')  
                         |map(attribute='entity_id')  
                         |list
                         %} 
                         {{Lijst}}

that gives this result

['media_player.living_sonos', 'media_player.living_sonos_2']

But I would only have the media players with sonos in them, not the_2,_3,_4, etc.

Is this possible? if so, how?

Thanks in advance

{%set Lijst = states.media_player 
|map(attribute='entity_id')
|select('search',Plaats|lower) 
|select('search', 'sonos') 
|reject('search', '\d')  
|list
%} 
{{Lijst}}

Thanks for your response.

This works

Can you explain it to me a bit?

The search test used in select and reject filters uses Python regular expressions. The expression \d will match any digit, since this is in a reject filter, any entity ID that contains a digit is rejected from the final output.

Thank You :+1: