Templates select attributes

I am trying to make a template, where I rejectattributes that have friendly_name with Battery+, since I have two sets of Battery names, one just Battery and another with Battery+

´´´Dør Alrum Battery 99.5 %
Dør Alrum Battery+ 99.5 %
Dør Entre Battery 98.5 %
Dør Entre Battery+ 98.5 %´´´

´´´{% set entities = states
| selectattr(‘attributes.device_class’, ‘defined’)
| selectattr(‘attributes.state_class’, ‘defined’)
| selectattr(‘attributes.device_class’, ‘eq’, ‘battery’)
| rejectattr(‘attributes.friendly_name’, ‘search’, ‘Battery+’)
| selectattr(‘state’, ‘is_number’)
| sort(attribute=‘name’) | list -%}
{% for e in entities -%}
{{ e.name}} {{ e.state }} %
{% endfor %}´´´

HOwever, when the rejectattr(‘attributes.friendly_name’, ‘search’, ‘Battery+’), it removes all friendly_name with Battery (those with and without the + (plus) sign)

Any idea what I am doing wrong or is the + sign seen as Battery and more?

Marinus

The + symbol has special meaning for search. If want to match a literal + symbol you must escape its meaning by adding a backslash in front of it.

rejectattr('attributes.friendly_name', 'search', 'Battery\+')

Regular Expression (Regex) Tutorial.

Hi Taras,

thanks for your ongoing help, I appriciate it
Marinus

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which indicates to others that the topic has been solved. This helps other users find answers to similar questions.