Multiple filters using selectattr

Hi,
how can filter two word in the domain-entity name ?
I mean f.i all domain-entities with the string “battery” OR “power” in the name (excluding the entitities in rejectattr filter…).
This code works good, but I can not add “power” in the filtering list.

{% set ns = namespace(namelist=[]) %}
{% set sensor_list = states 
|selectattr("entity_id", "search", "battery")  **OR "power"**
|rejectattr("entity_id", "search", "group*")
|rejectattr("entity_id", "search", ".*amassimo")
|list %}
{% for sensor in sensor_list %}
  {% if sensor.state | int < 90 | int %}
    {% set ns.namelist = [sensor.name+'('+sensor.state+')']  + ns.namelist %}
  {% endif %}
{%endfor%}
{{ns.namelist | join('\n') }}

Thanks all

1 Like

The search filter accepts a regular expression (regex).

| selectattr("entity_id", "search", "(battery|power)")
                                     ^^^^^^^^^^^^^^^
                                     this part here
                                   is a regex pattern
                                       not Jinja2
8 Likes

Oh yeah Taras…sorry for dummy-question.
I tried all… but “|”
Thanks!

1 Like