How can I find a list of all used ‘domains’, ‘entities’,… in ‘hass.io’ ?
I would like to exclude some from ‘database’…
Not sure what you exactly want, if you go to “Developer Tools” -> “States” you see a list of all your entities, is this enough?
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 -%}
‘bacco007’ - very nice. Thx…
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 -%}
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…
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?
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.
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.
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).
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
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
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.