How to use custom tests in Jinja template?

You have encountered the primary problem of using the entity’s name to store metadata: it’s messy to select entities by common metadata. Currently, there’s no easy way to select sub-strings from an entity’s name.

What I suggest is that you use custom attributes. I explained how to use them in this post:

For example, if you create a custom attribute called ‘type’ and assign it a value like ‘schedule’ then you can easily select all entities having this attribute and value using this template:

{{ states.switch | selectattr('attributes.type', 'eq', 'schedule')
   | map(attribute='entity_id') | list }}