I would like to make the case for adding the ability to use group entities as a “list of entities”, rather than an entity itself in Home Asistant triggers and conditions (or anywhere else where a list of entities can be provided, really).
For example, instead of writing the following:
trigger:
- platform: state
entity_id:
- binary_sensor.sensor1
- binary_sensor.sensor2
- binary_sensor.sensor3
to: ~
I could create a group group.binary_sensors
and just use that group. Pseudo code warning:
trigger:
- platform: state
entity_id:
expand: group.binary_sensors
to: ~
I am using the expand dictionary key here as an example. For one to distinguish this desired behavior from the behavior of using the group itself as one of the entities in the list and two since the expand
function provides similar functionality inside of templates.
The benefit of using a group is that I can more easily add and remove entities from this group and manage them centrally if I depend on that same set of sensors in multiple locations (e.g. for multiple automations, scripts or templates). It also allows me to logically structure my entities. Instead of a somewhat unspecified and unlabeled list of entities, I can have a group who’s name makes it obvious how the sensors in that group are related to each other.
One drawback I can see is that it would require the trigger for the automation to be recreated every time the group members change. Not sure if this is already something that is easily doable within the Home Assistant automation infrastructure.
Please also note the difference of this compared to using the group itself as the entity_id
. In case this isn’t obvious, the group will be ‘on’ if any of the sensors are ‘on’ and ‘off’ only when all of the sensors are ‘off’. Using a group as a “list of entities” instead, the automation would trigger whenever any of the sensors within the group changes state, compared as to when the group as a whole changes state.
Future ways to expand on this – no pun intended – could be the option to provide a list of group entities to the expand dictionary key, too. Or combine groups with non-grouped entities:
trigger:
- platform: state
entity_id:
expand:
- group.binary_sensors
- group.some_more_binary_sensors
entities:
- binary_sensor.an_additional_sensor
to: ~
It might also be worth considering changing how entities for conditions and triggers are provided in general, similarly how this was changed relatively recently for service calls with the target
dictionary key. Maybe instead of “amending” the entity_id
key a new key should be added that provides the new functionality:
trigger:
- platform: state
observe:
group:
- group.binary_sensors
- group.some_more_binary_sensors
entity_id:
- binary_sensor.an_additional_sensor
to: ~
I used “observe” here over “target” since I don’t feel “target” is a good semantic match for triggers.