Tip
As an alternative to using the entity’s name to store characteristics, consider storing them as custom attributes. It makes selecting entities, with common characteristics, very easy.
For example, I have created a custom attribute called type
for two Hue Dimmer Switches and assigned the value CR2450
. This is easily done using the UI (Configuration > Customizations) or by editing customize.yaml
(see Customizing Entities).
customize.yaml
sensor.hue_dimmer_switch_battery:
type: 'CR2450'
sensor.hue_dimmer_switch_battery_2:
type: 'CR2450'
After executing Reload Location & Customizations, the new, custom attribute appears as the last item in the entity’s attributes:
Now if I wish to select all sensors whose type
is CR2450
(or CR2032
) I can use this template:
{{ states.sensor
| selectattr('attributes.type', 'in', ['CR2450', 'CR2032'])
| map(attribute='entity_id') | list | join(',') }}
If we were to apply this technique to your example, it would look something like this:
- alias: Create Pool group
trigger:
platform: homeassistant
event: start
action:
service: group.set
data:
object_id: pool_sensors
entities: >-
{{ states.sensor
| selectattr('attributes.type', 'in', ['pool', 'pond'])
| map(attribute='entity_id') | list | join(',') }}
The advantage of this technique is that it lets you specify as many characteristics as you wish while keeping the entity’s name short and tidy.
Note
I used the word type
for the custom attribute’s name but it could be anything as long as it isn’t an existing attribute’s name.