List of all 'domains', 'entities',

This is a great way to display all entities!

Could somebody please help me with my attempt to list all entities and their corresponding friendly_names? Apparently, my alexa does not turn on bed room any longer (it reports that the device is not responding), and I assume this is due to multiple entities with the same name.


{%- for state in states -%}
- {{state.entity_id + state.name + "\n"}}
{%- endfor -%}

This will display all my entities and their set names. How can I display only those entities that have the same name (in my case, Schlafzimmer)?

UPDATE: I came up with this block below. Is this the right way, or is there a better/more sinsible method to achieve the same thing?


{%- for state in states -%}
  {% if state.name == "Schlafzimmer" %}
  - {{(state.entity_id + " => " + state.name + "\n")}}
  {% endif %}
{%- endfor -%}
1 Like

so because I recently noticed the Z-waveJS integration is displayed under many Domains, I would love to develop on this script, to list these multiple subdomains with their respective domains. Eg I now have

binary_sensor.zwave_js
climate.zwave_js
cover.zwave_js
fan.zwave_js
light.zwave_js
lock.zwave_js
number.zwave_js
sensor.zwave_js
switch.zwave_js
and finally zwave_js,

and I would love to have a template or python script creating an output like

zwave_js:

  • binary_sensor
  • climate
  • cover
  • fan
  • light
  • lock
  • number
  • sensor
  • switch

for all subdomains belonging to other domains.

This must be an easy reversal in the scripts logic, but all my thoughts on it lead to nothing… please have a look with me how to create that?
Thanks!

update

progress but nothing ripe for production just yet:

attributes = {}
components = hass.states.get('sensor.ha_rpi4_config').attributes['components']
cnt = len(components)
components.sort()

# Make a dictionary of all main domains, add each sub domain to the main domain list.
compdict = {}
subdict = {}
for component in components:
    if component.count('.') == 0 and component not in compdict:
        compdict[component] = []
    if component.count('.') == 1:
        domain, subdomain = component.split('.')
#        compdict[domain].append(subdomain)
        compdict.setdefault(domain, []).append(subdomain)
        if len(subdomain) > 1:
            subdict.setdefault(subdomain, []).append(domain)
# Make the dictionary into a flat list of strings.

complist = []

for key, value in compdict.items():
    if value:
        value.sort()
        # Adding a domain & series of sub domains
        complist.append('- {}: \n for: {}'.format(key, ', '.join(value)))
#     else:
#         complist.append('- {}'.format(key))

sublist = []
cntsub = 0
for key, value in subdict.items():
    if value:
        value.sort()
        # Adding a subdomain & series of domains
        sublist.append('- {}: \n for: {}'.format(key, ', '.join(value)))
        cntsub = cntsub + 1
    else:
        sublist.append('- {}'.format(key))

# join each component with a carriage return
complist = '\n'.join(complist)
sublist = '\n'.join(sublist)

#text = '{} Loaded Components:\n' \
#       '{}'.format(cnt, complist)

#subtext = '{} Multiple subdomains:\n' \
#       '{}'.format(cntsub, sublist)

attributes['friendly_name'] = 'Components'
attributes['icon'] = 'mdi:format-list-bulleted-type'
attributes['Components'] = cnt
attributes['---------------'] = '--------'

attributes['text'] = complist #text

attributes['Subdomains'] = cntsub
attributes[**************'] = '--------'
attributes['subtext'] = sublist
hass.states.set('sensor.overview_components', cnt, attributes)

results in a listing like:

- xbox: 
 for: binary_sensor, media_player, remote, sensor
- zwave_js: 
 for: binary_sensor, climate, cover, fan, light, lock, number, sensor, switch
- buienradar: 
 for: camera, sensor, weather

but it has 2 major flaws just yet, in that it also lists the single subdomain entries. I thought I prevented that with

if len(subdomain) > 1:
            subdict.setdefault(subdomain, []).append(domain)

but apparently it doesn’t :wink:

Secondly, I would love to sort() the subdomains alphabetically. Right now, the list of domains (for: binary_sensor, media_player, remote, sensor) is sorted correctly, but the main listing isnt.

Hello everyone,
I was wondering, could the code posted here be modified in a way to only show entities that are part of a certain integration?
Reason behind this is I would like to use this code to maybe tell Recorder what to record. And I basically do not care about any system information and only want to record all the devices that I installed via Tasmota and Shelly integrations.

domains:
 
{%- set unique_domains = states | map(attribute='domain') |list | unique | list -%}
{%- for domain in unique_domains -%}
{{"\n"}}- {{domain}}
{%- endfor -%}
{{"\n"}}

entities:
 
{%- for state in states -%}
{{"\n"}}- {{state.entity_id}}
{%- endfor -%}
2 Likes

There is an integration_entities() function, for example:

{{expand(integration_entities('hue'))|selectattr('domain', 'eq', 'light')|map(attribute='entity_id')|list|join('\n- ') }}

Would get you all the lights in the hue integration

1 Like

Hi, using the code of @dariusz as follows:

{% for d in states | groupby('domain') %}
  {% if loop.first %} Domains: {{loop.length}}
  {% endif %} - {{ d[0] }} ({{ states[d[0]] | count }})
      - {{ states[d[0]] |map(attribute='entity_id')| list|join('\n      - ') }}
{% endfor %}

resulting in displayed in a ‘mark-down’ card:

Domains: 25
   - automation (11)
      - automation.001a_garage_2_auto_lights_on
      - ...

   - binary_sensor (49)
      - binary_sensor.bbq_flood_light_shelly1pm_06_overheating
      - ...

   - button (35)
      - button.bbq_flood_light_shelly1pm_06_ota_update
      - ...

   - camera (2)
      - camera.cam_stairwell_01_gf_ff_high
      - camera.cam_stairwell_02_ff_rf_high

   - climate (18)
      - climate.ff_bedroom_1_ac
      - climate.ff_bedroom_2_ac
      - ...

   - cover (43)
      - cover.ff_bathroom_1_window_1
      - ...

   - device_tracker (73)
      - device_tracker.ana_s_mobile
      - ...

   - group (66)
      - group.b1_covers
      - ...

   - input_boolean (8)
      - input_boolean.basement
      - ...

   - input_number (21)
      - input_number.diesel_tank_adc_offset
      - ...

   - input_select (1)
      - input_select.mode

   - light (180)
      - light.bathroom_1_light
      - light.bathroom_1_mirror
      - ...

   - media_player (11)
      - media_player.all_speakers
      - ...

   - number (6)
      - number.cam_stairwell_01_gf_ff_microphone_level
      - ...

   - persistent_notification (1)
      - persistent_notification.config_entry_discovery

   - person (5)
      - ...

   - remote (1)
      - remote.roku_yj002t616908

   - script (3)
      - script.call_hamza
      - script.call_the_guys
      - script.call_zaid

   - select (8)
      - select.cam_stairwell_01_gf_ff_infrared_mode
      - ...

   - sensor (285)
      - sensor.amman
      - sensor.ana_s_mobile_uptime
      - ...

   - sun (1)
      - sun.sun

   - switch (121)
      - switch.b1_guard_ufh_valve
      - switch.b1_ufh_pump
      - ...

   - update (9)
      - update.ha_scheduler_update
      - update.home_assistant_core_update
      - ....

   - weather (1)
      - weather.home

   - zone (1)
      - zone.home

I need help how I can make the display on a dashboard having:
a custom button with (name=domain name, value=number of entity_id(s)) and when pressed it displays the list of entities
Any advise is highly appreciated
RS

5 Likes

just so we’re understanding what you want: you try t create 25 buttons (for each domain) and the number of the entities in that domain? and then list only those entities in a popup?

seems a bit crowded tbh, and maybe you can have more compact solutions. like fold the listings in a fold-entity-row, or, simply scroll the list, like I do:

  - type: entities
    title: Domains and entities
    card_mod:
      class: class-header-margin
    entities:
      - type: custom:hui-element
        card_type: markdown
        card_mod:
          style: |
            ha-card.type-markdown {
              box-shadow: none;
              margin: 0px -16px -16px -16px;
              overflow-y: scroll;
              height: 450px;
            }
        content: >
          {% set x = ['unavailable','unknown'] %}
          {%- for d in states|groupby('domain') %}
          {% if loop.first %} ### Domains: {{loop.length}}{% endif %}
            **{{- d[0]}}:** *({{states[d[0]]
                                |rejectattr('state','in',x)
                                |list|count}})*
            {% for i in d[1] if i.state not in x -%}
            > {{i.name}}: *{{i.state}}*
            {% endfor %}
          {%- endfor -%}

2 Likes

Hi @Mariusthvdb
This is definitely better than mine and saved a lot of space :slight_smile: however, I noticed a difference in the count of buttons between my code and yours! :thinking:
Thanks anyway
RS

The count difference is due the extra filtering of unknowns and unavailable entities

Very nice, Thank you

Sorted list of domains and entity_ids:

{{ states | map(attribute='domain') | unique | sort | join('\n') }}

{{ states | map(attribute='entity_id') | sort | join('\n') }}
3 Likes

I get a Error trying to make a card from this

Configuration errors detected:
missed comma between flow collection entries (5:2)

2 |
3 | domain:
4 |
5 | {%- set unique_domains = states | …
------^
6 |
7 | {%- for domain in unique_domains -%}

You shouldn’t use that, it seems a little outdated on a first glance. What is it, that you want to achive? Where should this list show and how?

I think my problem is that I run a mix of Zigbee and Z-wave that I moved from Fibaro, and it has only been a few weeks into this. The idea of domains, etc., is new to me. Here is an excellent example:

I’m reading the code and saw it looking at the type of device movement related and found my test setup but not my Z-wave (I have 2 types) that I know are in the system, so it must be that the domain is wrong, right? So I added zwave_js because it was the only “domain” I found when looking in developer-tools/state, but no luck. I did find a way under helper to make a switch a “light,” and that helped. In fact, I don’t know why it is not possible for all kinds of devices.

To me, a more clear understanding of what is a domain might help me edit and adopt add
the missing parts, why I looking to list them

this is clearly just a 1-time setup thing but a current solution with USB powered MM-wave device hanging on the wall not nice

input:
motion_entity:
name: Motion sensor
selector:
entity:
domain:
- zwave_js
- binary_sensor
device_class:
- zwave_js
- motion
multiple: false
light_target:
name: Light
selector:
target:
entity:
- domain:
- light

zwave_js is the integration

it will create lights, switches, binary_sensors, sensors, etc… those are the domains.

Each domain it create may have a different look in the UI. That would be device class.

E.g. if you have garage door opener in zwave, that would be:

integration: zwave_js
domain: cover
device_class: garage_door

it will be a cover entity that will have open, close, stop controls, and the icon and state translations will be represented as a garage door.

if you also have window blinds coming from zwave, that would be:

integration: zwave_js
domain: cover
device_class: window

it will be a cover entity that will have open, close, stop controls, and the icon and state will be represented as a window.

2 Likes