Options for entities belonging to device to inherit labels

While setting labels to my HA instance I started thinking this.
In many cases entities belonging to device would be tagged with same labels as device it self. Yet there doesn’t seem to be option to have entities inherit labels.

This would simplify using labels.

I agree. I tried to build template sensors using 2 different approaches:

  1. Tagging the devices: I have multiple door/window sensors and tagged them. Now I’m trying to set up a template sensor counting the number of open sensors. With a template, I can get the number of devices:
label_devices('Sicherheitsalarm')
| expand
| list 
}}

However, I cannot filter this list of devices to get their entities with device_class = “door”. I tried | selectattr('device_class', '==', 'door') but since the devices do not have attributes the filter does not work…

  1. Tagging the entities: Here I tagged the entities directly. I am counting battery entities that are below 50% power:
{{ 
label_entities('Batterieueberwachung')
| selectattr('state', '!=', 'unavailable')
| selectattr('state', '!=', 'unkown')
| map('states') 
| map('int', default=101) 
| select('<',50) 
| list 
| count 
}}

→ This works fine.

However; I’d prefer to just tag the devices instead of the entities for better visibility. I usually work with the “devices” view in HA, if you tag only the entities, you have no visibility here which are counted and which are not.

I’ve found that using a combination of temapltes and the “Spook” integration the following will easily popupalte the entities. I can understand why inheritance is not standard, this allows for chices at a level down the hierarchy.

service: homeassistant.add_label_to_entity
data:
  label_id:
    - back_yard
  entity_id: "{{ device_entities('8cab62f7b356bb5ff8a90e0881213c12') }}"

You could then write various loops to make coverage broader.