How to use a dynamic list in automations or scripts (like auto-entities)

I’ve been trying to create automations and scripts that are more dynamic for the past couple of weeks so that if I add a new temperature sensor for example in my system in an area, the automations related to the sensors in that area are also fired.

I have really hard time finding how to do that. In lovelace I fell in love with auto-entities that helps you create cards based on domains or different variables. How can you do that in automations and scripts though?
Say I want to create a script or automation that stops all scripts, without having to add new scripts that I create into a group or into that script/automation. I’ve tried many different ways so far (including calling events instead of templating or groups) but none seem to be working in scripts or automations.

There’s no “one size fits all” answer because the solution depends on the application. Post the YAML of whatever you currently want to become dynamic.