Wildcard operators for groups

I would love to have this feature. I even thought it would work, because it’s available inside the “HomeKit” integration. You can use very easy but powerful filters there:

  - filter:
      include_domains:
        - alarm_control_panel
        - light
        - media_player
      include_entity_globs:
        - binary_sensor.*_occupancy
      include_entities:
        - binary_sensor.living_room_motion

This would make life so much easier.

1 Like

A feature like this is almost mandatory if the devs are going to keep refusing to support something like tagging/annotating devices and entities, because we’re forced to encode tags in the entity ID’s, like if I want to tag all of the contact sensors which are and are not controlling access from the outside:

  • sensor.door_front_perimeter
  • sensor.door_back_porch_perimeter
  • sensor.door_laundry
  • sensor.door_grarage_perimeter

Then it would be really helpful to be able to specify entity_id’s such as:
entity: sensor.*perimeter*
should leave the laundry door (which is internal to the house) out of the group.

Any update on the topic?

Is there a way to do this in 2023? Surprised to see this isn’t possible already.

My workaround is to have an automation that is triggered on HA startup and it runs scripts which create groups for me. Here’s an example of a script that creates a group called group.perimeter_doors with all the door and garage door contact sensors for my house. To be honest this is a bit of a silly example because there’s only 5 and I don’t expect to add or remove any ever, so this should probably just be a manually created group. But I wanted to try it so :man_shrugging:

alias: Perimeter Door Sensor Group Creation
sequence:
  - service: group.set
    data_template:
      object_id: perimeter_doors
      entities: |
        {{ states.binary_sensor
          | selectattr('attributes.device_class', 'defined')
          | selectattr('attributes.device_class','in',['door','garage_door'])
          | selectattr('entity_id','contains','_door_contact')
          | rejectattr('entity_id','contains','tesla')
          | map(attribute='entity_id')
          | join(',') }}
mode: restart
icon: mdi:home-lock

This could all be an automation rather than an automation that call this script, but, again :man_shrugging:

I voted for this FR because it would make this much more simple. But this workaround does work.

Hi,
this works for me but where is the group? I cannot edit it in the Gui as it says is has no unique ID. It is not in the groups.yaml. I cannot delete it. Any idea?

You have to modify the group through service calls, listed in the docs

You can delete it with a service call, or just restart HA and it will be gone (provided you don’t have an automation that re-creates it).

The group perstists even after a reboot. I can only get rid of it by restoring a backup from before.
I read through the article but cannot figure out how to add a unique idea. Can you eventually give a helping hand? I would really love to use this but having a group which I cannot delete or modify scares me a bit. I don´t like that idea.

The group won’t persist after a restart. If you are seeing after a restart, it is because it is cached in your web browser or on your phone’s app. You have to clear your cache. Or open an incognito window and log into your instance. If you don’t want to restart, you can call the service group.remove with the object_id of the group (which is what you used to create it, and the part after “group.” in the entity_id)

You can’t add a unique_id for a group created by a service because it doesn’t exist in YAML. Any changes to this group have to be done through service calls.

You can test out all the service calls by going to “Developer Tools → Services” and selecting any of the group services that start with “group.

Okay, thank you very much. I will give it another try this weekend.