Group Help

I am upgrading HA and all my automations.
In 2022.4 the method of creating GROUPS was changed to use the UI.
I have created a few GROUPS in the UI, but am unsure how to use them.
For instance. I have an automation that tells me if a door is open at a certain time.
I created a GROUP called DOORS in the UI and entered all my door binary sensors.

I am unsure on what I need to do to rewrite the automation.

Here is what I had used.

    condition: template
    value_template: >
      {{ states | selectattr('entity_id', 'in', state_attr('group.5123_door_sensors_contact','entity_id')) | selectattr('state','in',['on','open']) | list | length >= 1 }}

What do I use in place of


Thank you

With a twist: The UI doesn’t create group entities. Those are still created exclusively via YAML and now referred to as “legacy groups”.

The UI creates lets you create a binary_sensor that’s a group of other binary_sensors. It can also do this for other domains as well such as |cover, lock, fan`, etc.

So what you should be looking for is a new binary_sensor entity having whatever entity_id you assigned to it.

FWIW, there’s no obligation to switch from using group entities to the new method … unless you what to manage it exclusively via the UI.

Thank you for the explanation of this. The page on GROUPS is not quite clear to ME as to the process.
But you explained it well.

Might you then be able to tell me how the binary_sensor is used in an automation.
Again thank you so much.

Essentially the same way as you had used a group entity.

    condition: template
    value_template: >
      {{ expand(state_attr('binary_sensor.whatever_you_called_it', 'entity_id'))
        | selectattr('state', 'in', ['on','open'])
        | list | length >= 1 }}

BTW, a binary_sensor’s nominal states are on and off. It’s never open so this line doesn’t need to bother checking for open.

        | selectattr('state', 'in', ['on','open'])

Here’s another way to compose the Template Condition:

    condition: template
    value_template: >
      {{ state_attr('binary_sensor.whatever_you_called_it', 'entity_id')
        | map('states') | select('eq', 'on') | list | length >= 1 }}
1 Like