How to get a single list of entity_id's containing '_battery' OR '_battery_level`

Is there a way to reduce this monster pipeline to only select sensor.*_battery OR sensor.*_battery_level without a slew of reject’s?

{{ states.sensor
    | map(attribute='entity_id') 
    | select('search', '.*_battery*')
    | reject('match', '.*low_battery*')
    | reject('match', '.*battery_manuf*')
    | reject('match', '.*battery_charge*')
    | reject('match', '.*battery_consumption*')
    | reject('match', '.*battery_state*')
    | reject('match', '.*battery_health*')
    | reject('match', '.*battery_temperature*')
    | reject('match', '.*battery_voltage*')
    | list }}

:slightly_smiling_face:

{{ states.sensor
    | map(attribute='entity_id') 
    | select('search', '_battery$|_battery_level$')
    | list }}

The match and search tests employ a regex pattern so you have the full power of regex to define the search criteria.

2 Likes