Create Blueprint template for monitoring a certain class of devices

Inspired by SmartThings and many other pre-built automation solutions, usually a certain class of devices will be automatically integrated to an default automation that will trigger when the sensor is true without user manually adding it to the automation.
For example, any gas/smoke/carbon_monoxide sensor added to the hub triggering will result in a voice announcement with the device name and location stated before the alarm being sound in 15 seconds.
It also applies to moisture and battery sensors, which will trigger notifications and voice announcement.

I’m trying to achieve the same by using the following template in the blueprint:

{{ states.binary_sensor | selectattr('attributes.device_class', '==', 'moisture') | map(attribute = 'entity_id') | list | length }}

However the caveat is it will only trigger upon the first moisture sensor, it seems this is a known limitation:

I wonder if there are any other workaround than creating template sensors counting the number of sensors being triggered?

This would also benefit the case where some other templates, for example detecting the number of switches being turned on, otherwise the trigger will only run when the first switch is turned on.

Thanks for your help.

I don’t know enough templating to fix or change this template. You should change the topic to move this over to the people who know templates to see it better. This isn’t a blueprint problem, you would have the same problem with an automation.

However, I generally get around template limitations by triggering more generally, cast a wider net so to speak, and then use conditions to eliminate what I don’t want to trigger on. The trigger widely and let the conditions sort them out method. Then limitet templates are not a thing.

That may or may not help you. I think a clever template on what is returned in a trigger would get you where you want to be.