However, I only want to include entities ending in battery_level, how could I filter out any entities that have text after that? e.g. sensor.living_room_smoke_detector_battery_level_zwave
How might I go about that? Thanks!
Should you ever want to search for entities whose names contain battery_level and not just at the end of their name, you can use the recently introduced search and match functions.
I like the idea of the new tests, but I’m struggling with the syntax for actually using them. I thought that they’d be in the argument to a select() filter, but I can’t work out what it would look like. Have you been able to make either work?
Nevermind, figured it out after reviewing this thread.
In my humble opinion, the text in the documentation isn’t really enough to put it to use. I ended up with something like this:
Sorry, I wasn’t clear. I have used it the way you have as a Jinja2 test. I have not used it the way it is shown in the documentation. However, that way also works (but might not be the most common usage).
hello every, i would link to ask if there is a way to simplify the code below, most of the code have the same code, but i cannot figure it out. @circa1665@Troon@rccoleman
{% set ns = namespace(below=[]) %}
{% for s in states.light %}
{% if 'kitchen' in s.entity_id and not s.entity_id.endswith('indicator_led') %}
{% set ns.below = ns.below + [s.entity_id] %}
{%- endif %}
{% endfor %}
{% for s in states.switch %}
{% if 'kitchen' in s.entity_id %}
{% set ns.below = ns.below + [s.entity_id] %}
{%- endif %}
{% endfor %}
{% for s in states.fan %}
{% if 'kitchen' in s.entity_id %}
{% set ns.below = ns.below + [s.entity_id] %}
{%- endif %}
{% endfor %}
{{ ns.below | reject('in', ['switch.horace_pc'] ) |join(', ') }}
Please don’t tag everyone in the thread. The second and third are easy and could use exactly the same syntax from here. The first could use something like this:
hello, what if i wanna do something like “(“kitchen”,“bedroom”)” ??? selectattr or rejectattr the stringA & stringB & stringC included in the entity name? thanks a lot