I’m not an advocate of using an entity’s name to store metadata. In other words, I don’t recommend creating an entity name packed with its characteristics.
sensor.manufacturer_model_identifier_color_size_location_bla_bla_etc
When the time comes to select entities based on their characteristics, the resulting template can become quite messy.
What I suggest is to add metadata as custom attributes to an entity. Simple add them to customize.yaml
or via Configuration > Customizations.
For example:
sensor.kitchen_remote_battery:
integration: hue
type: 'CR2450'
sensor.bedroom_remote_battery:
integration: hue
type: 'CR2450'
For my purposes, I want to know a battery sensor’s integration and the type of battery it uses so I created two custom attributes: integration
and type
. They will appear as additional attributes when viewing the entity’s attributes.
Here’s a template to select all sensors with a specific battery type (much simpler than trying to parse it out of the entity’s name):
{{ states.sensor | selectattr('attributes.type', 'eq', 'CR2450')
| list | join(', ') }}
If I have many battery sensors and only want the Hue sensors that use CR2450 batteries:
{{ states.sensor | selectattr('attributes.integration', 'eq', 'hue')
| selectattr('attributes.type', 'eq', 'CR2450')
| list | join(', ') }}