FYI: New Jinja tests coming soon. 'search' and 'match'

Very handy additions to one’s templating toolkit:

2 Likes

yes, followed the development of that, looking forward to this kind of functionality:

{{ states.sensor | select_attr('device_class', 'eq', 'battery') | select_attr('state', 'match', '^[0-9]$') | list | join(', ') }}

or combine that with the expand(group) function. really nice!

The ability to use a regex pattern is what makes it especially flexible. For example, this will match all state values from 0 to 49.

select_attr('state', 'match', '^[0-4]?[0-9]$')

That’s awesome! I was just venting about the lack of exactly that in Discord last week - it’s a big gap if you want to avoid a loop.

Rather than start a new topic, here’s another useful upcoming addition to Home Assistant.

It allows you to create a binary_sensor that behaves as a ‘momentary boolean’ or ‘pulse’. The use-cases for this behavior are narrow but it’s one more tool for solving challenging problems.