Select entities in automation based on Regex

Hi folks,

I have many Shelly devices in my home (about 50, more to come)
I want to add a button which triggers an automation which reboots all Shelly devices.

Every Shelly device has a Reboot button in Home Assistant. I need to select all entities which end in _reboot and press those.

I do not want to put all of them in by hand. I would need to maintain that automation and is likely to forget to put one in / out of the list if the setup changes.

An entity ID could look like this: button.bar_sihl_kronleuchter_reboot

I want to select all entities which start with “button.” and end in “_reboot”.

Any ideas how to achieve that? Maybe a custom python script? I have no clue how to do that with just YAML.

Thanks for any help!

Best regards
Alex

Configure your button to run the following Script (there’s no need for an Automation):

reboot_shelly_devices:
  sequence:
    - service: button.press
      target:
        entity_id: >
          {{ states.button
             | selectattr('object_id', 'search', '_reboot$')
             | map(attribute= 'entity_id') | list }}