Is there a way to determine what integration an entity belongs to?

I am trying to get a list of specific entities and it would be helpful to output the related integration associated with it. I can’t find any documentation on if this info is surfaced to the templating engine or not. Anyone have any ideas?

Thanks!

Ryan

If you just want to know what integrations are associated with which entities that info is already listed in the entities section of the configuration menu.

If you need it to output that info to a sensor to display in lovelace then I’m not sure how you would do that.

If you’re trying to do this with a template, as far as I know, it’s not possible. An entity’s integration would need to be one of its attributes so that the template could access it (using the state_attr() function).

It’s for this very reason that I have manually added a custom attribute, called integration, to each entity. For more information, refer to this post:

For context, this is so I can get a list of unavailable entities, which I have, but I thought it would be nice to see the integration next to the entity because some are actually “offline” while others are because I’ve moved them from Smart Life to ESPHome. When doing large refactorings of my setup, it would be helpful to focus on those of a specific integration. While wishing, would be nice to be able to get the device ID and name assosciated with an entity too.

So, I really need to get the info that is in Home Assistant - this is not long term retention or anything like that where adding it as a custom attribute would be worth the time involved.

Thanks for the replies!

Ryan

No can do. Add “integration” as a custom attribute or forget about it.

This works for most integrations. Some (eg esphome) will give you the ??.

{% set ent = "sensor.mosquitto_broker_cpu_percent" %}
{%- set integ = device_attr(ent, 'identifiers')|list %}
Integration: {{ integ[0][0] if (integ|length) > 0 else '??' }}
1 Like

Here is “Something” to “work” on

{% set devices = states | map(attribute='entity_id') | map('device_id') | unique | reject('eq',None) | list %}
{%- set ns = namespace(integrations = []) %}
{%- for device in devices if device_attr(device, 'identifiers') %}
  {%- set ids = device_attr(device, 'identifiers') | list | first %}
  {%- if ids and ids | length == 2 %}
    {%- set integration, something_unique = ids %}
    {%- if integration not in ns.integrations %}
      {%- set ns.integrations = ns.integrations + [ integration ] %}
    {%- endif %}
  {%- endif %}
{%- endfor %}
{% for integration in ns.integrations %}
  {{integration}}:  {{integration_entities(integration)|list }}
{% endfor %}

Found it somewhere in here, don’t remember where or Who is to “credit”

But you might “find” a way to “re-compose” or iterate with another Template :wink:

PS: run it ones and store it in a “File” Use file-integration or something to iterate the “File”

OHH !, 4 years OLD Topic … i better “watch out” or open my eyes :laughing:

2 Likes

That looks it came from here (found it by searching for ‘something_unique’ :slight_smile: )

How to enumerate entities belonging to an integration?

I now use a Macro that employs a more up-to-date method that was provided by template master petro

Notice: A device may “belong” (be associated with) to more than one integration - this macro returns the name of the first found integration in the list of linked integrations

{# --------------------------------------------------- #}
{# Find the integration of a device or entity #}
{# --------------------------------------------------- #}
{%- macro get_integration(device_or_entity_id) -%}
    {{-
    [device_or_entity_id] 
    | map('device_attr', 'identifiers') 
    | reject('none') 
    | map('list') 
    | reject('eq', []) 
    | map('first') 
    | map('first') 
    | first
    -}}
{%- endmacro -%}
1 Like

Im not familiar with macro’s, nor how to use them :man_shrugging: :blush:

Yep , my CP came from same “source” Petro … i just added “list” and copied the result, as i didn’t want such template running/listening