List of all 'domains', 'entities',

Not sure what you exactly want, if you go to “Developer Tools” -> “States” you see a list of all your entities, is this enough?

1 Like

this is quick and dirty (someone may be able to refine) - but running this in Developer Tools > Template
should give you something to work with

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

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

‘bacco007’ - very nice. Thx…

1 Like

Indeed nice!

Is there a way to include a newline or two after domains: and entities: ? At present mine starts like this

domain:- automation
- binary_sensor
- camera
- climate

Would look perfect like:

domain:

- automation
- binary_sensor
- camera
- climate

Try, maybe like this:

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 -%}
13 Likes

have a look here:

a few python scripts which you might be able to use/

Interesting lecture…
The solution of ‘bacco007’ was O.K. for me…
I display that as a ‘System Info’ in ‘card’.
The only question I have - how to place both lists in horizontal view, not vertical?
As it is now on the screen…

1 Like

which is where the python scripts were needed in my case, because states can only have a max length of 255 characters, where as attributes don’t have that limit.

Makes me wonder how you managed to create these 2 cards which the value_template @bacco007 suggested, because that would be way over 255 characters on the entities card?

This is ‘markdown’ + ‘script editor’:

1 Like

a yes, of course, forgot about that for a second… heavily into sensors, states and attributes this morning. sorry for that…
using it myself as a matter of fact, how could I forget.

19

lovely! thanks!

how did you manage to break down each integration coponents?

it all started here Template to display loaded components on HA instance?

this is the python_script currently:

##############################################################################################################
# python script to show the loaded components on a  Hassio instance, and order them alphabetically, grouping
# components that have sub components (attributes)
# this script gets its data from the rest_sensor:
#   - platform: rest
#     name: Hassio Rpi4 config
#     resource: !secret resource_hassio_rpi4_config
#     authentication: basic
#     value_template: >
#       {{ value_json.version }}
#     json_attributes:
#       - components
#       - unit_system
#       - config_dir
#     headers:
#       Content-Type: application/json
#       Authorization: !secret api_bearer_token
#       User-Agent: Home Assistant REST sensor

# https://community.home-assistant.io/t/template-to-display-loaded-components-on-ha-instance/114402/59
# @123 and @apop pointed to the rest sensor, and made that availabe in Lovelace
# @petro had a great hand in creating the script
# thanks for joining in on a great HA community!
# @mariusthvdb 20190504
##############################################################################################################
attributes = {}
components = hass.states.get('sensor.hassio_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 = {}
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)

# 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 --> {}'.format(key, ', '.join(value)))
    else:
        complist.append('- {}'.format(key))

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

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

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

attributes['text'] = complist #text

hass.states.set('sensor.overview_components', cnt, attributes)

# hass.states.set('sensor.overview_components', cnt, {
#     'icon': 'mdi:format-list-bulleted-type',
#     'friendly_name': 'Components',
#     'text': text
#     })
##############################################################################################################
# first attempt, simply creating an unordered list of components
# components = hass.states.get('sensor.hassio_main_config').attributes['components']
# count = len(components)
# components.sort()
# list = ', '.join(components)
#
# text = '*========== {} Loaded Components ========\n' \
#         '+{}' \
#           .format(count,
#                   list)

left in some comments, might be interesting to see what’s happening.

2 Likes

One line version:

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

Will print something like:

- air_quality
- alarm_control_panel
- automation
- binary_sensor
- camera
- climate
- cover
- device_tracker
- fan
- input_boolean
- input_number
- input_select
- light
- media_player
- persistent_notification
- person
- remote
- script
- sensor
- sun
- switch
- vacuum
- weather
- zone

For entities:

- {{ states|selectattr('state', 'ne', 'unavailable')|map(attribute='entity_id')|list|join('\n- ') }}

Will output all entities that are not “unavailable” (remove that selectattr if you want all unavailable as well).

7 Likes

Thanks for posting this. I’m having very rudimentary issues I think. I am new to python scripting, but I am getting the error below on this line.

components = hass.states.get('sensor.hassio_rpi4_config').attributes['components']

Logger: homeassistant.components.python_script.list_entities.py
Source: components/python_script/init.py:217
Integration: Python Scripts (documentation, issues)
First occurred: 5:16:38 PM (1 occurrences)
Last logged: 5:16:38 PM
Error executing script: ‘NoneType’ object is not subscriptable
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/python_script/init.py”, line 217, in execute exec(compiled.code, restricted_globals)
File “list_entities.py”, line 27, in File “/usr/local/lib/python3.8/site-packages/RestrictedPython/Eval.py”, line 35, in default_guarded_getitem return ob[index]
TypeError: ‘NoneType’ object is not subscriptable

1 Like

Did you setup the rest sensor which is described at the beginning of the script?

No, that must be the step I missed. Are the steps to do that in your other topic you linked to?

In the python script you copied from Marius, at the top are some lines describing the rest sensor and he also has an example right there:

##############################################################################################################
# python script to show the loaded components on a  Hassio instance, and order them alphabetically, grouping
# components that have sub components (attributes)
# this script gets its data from the rest_sensor:
#   - platform: rest
#     name: Hassio Rpi4 config
#     resource: !secret resource_hassio_rpi4_config
#     authentication: basic
#     value_template: >
#       {{ value_json.version }}
#     json_attributes:
#       - components
#       - unit_system
#       - config_dir
#     headers:
#       Content-Type: application/json
#       Authorization: !secret api_bearer_token
#       User-Agent: Home Assistant REST sensor
1 Like

Oh man, I skipped right over the comments. My bad, thanks for not ripping me up on that. I’ll be more careful and read slower. :slight_smile:

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