Lazy Man's Entity Count - Something Screwy

Okay so there has been a number of people complaining about how their pages don’t load given the number of entities they have. Mine load fine by the way :crazy_face:
So I thought I’d count mine; so I played in the templating tool : -

automations:              {{ states.automation | count}}
binary_sensors:           {{ states.binary_sensor | count }}
climates:                 {{ states.climate | count }}
device_trackers:          {{ states.device_tracker | count }}
groups:                   {{ states.group | count}}
input_booleans:           {{ states.input_boolean | count }}
input_datetimes:          {{ states.input_datetime | count }}
input_numbers:            {{ states.input_number | count }}
input_selects:            {{ states.input_select | count }}
lights:                   {{ states.light | count }}
media_players:            {{ states.media_player | count }}
persistent_notifications: {{ states.persistent_notification | count }}
persons:                  {{ states.person | count }}
scripts:                  {{ states.script | count }}
sensors:                  {{ states.sensor | count }}
suns:                     {{ states.sun | count }}
switches:                 {{ states.switch | count }}
weathers:                 {{ states.weather | count }}
zones:                    {{ states.zone | count }}
zwaves:                   {{ states.zwave | count }}

{% set ns = namespace(num = 0) %}
{%- set unique_domains = states | map(attribute='domain') | list | unique | list -%}
{%- for dom in unique_domains -%}
  {% set domnme = 'states.' ~ dom %}
  {%- set domnum = domnme | count %}
  {%- set ns.num = ns.num + domnum %}
  {{ dom ~ 's: ' ~ domnum }}
{%- endfor -%}
{{ '\n'~'\n  ' ~ 'Total: ' ~ ns.num }}

Except this is the results I got : -

As what remains of my hair is an endangered species, I thought I’d ask any of the brain trust “what stupid assumption have I made ?
Thanks for ANY input :beers:

I know I could do a quick fudge, like : -

{% set ns = namespace(num = 0) %}
{%- for state in states -%}
  {%- set ns.num = ns.num + 1 %}
{%- endfor -%}
{{ '\n'~'\n  ' ~ 'Total: ' ~ ns.num }}

Which gives me : 918
But that’s not the point

Well I get the exact same numbers for your for loop so I’d guess we’re counting not the list of [say] automations but a list of maybe attributes to the automation domain or something like this?
I don’t understand your for loop so I won’t even venture to tell you what you need to change, but hopefully the above comment steers you in the right direction. That’s a pretty cool formula (when it’ll work)

By the way I’m currently on 193 automations. No idea if it’s a good or bad thing though :rofl:

Yep I agree, they are generally meaningless numbers at the end of the day but I do like to track how my HA is growing as my OCD kicks into a different gear over time :rofl:
Thanks

BTW : -

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

Just gives you a list of the domains on your instance

I have only 714 :sob: :rofl:

now I get it and I believe the count you get is the count of chars in the string ‘states.[domain name]:wink:

1 Like

I’m pretty sure @Mariusthvdb has the most :rofl:

Yeah Marius collects sensors as a hobby. :rofl:

I’m pretty sure @lolouk44 is correct (well spotted :+1: )

But how should I pass the states.[domain] as a ‘group’ ? Rather than as a text string to have its length calculated ?

{%- for domain in states | map(attribute='domain') | unique %}
{{ domain }}: {{ states[domain] | count }}
{%- endfor %}

Edit: adding dashes

Edit 2: Also seems like you’re trying to add them all up… but you don’t need to do that, just

{{ states | count }}
3 Likes

@petro to the rescue :clap: :slight_smile:

1 Like

haha, Ive grown…

(note the scroll bug prevents the zones being visible)
(note2, the numbers don’t add up completely:

Thank You Petro :+1:

Just to pretty it up the modified original “would” have been : -

{% set ns = namespace(num = 0) %}
{%- for domain in states | map(attribute='domain') | unique %}
{%- set numb = states[domain] | count %}
{%- set ns.num = ns.num + numb %}
{{ domain ~ 's : ' ~ numb }}
{%- endfor %}
{{- '\n'~'\n  ' ~ 'Total: ' ~ ns.num }}

Except Petro simplified a lot more than that, so it all could be replaced by : -

{%- for domain in states | map(attribute='domain') | unique %}
{{ domain ~ 's : ' ~ states[domain] | count }}
{%- endfor %}

{{ '  Total: ' ~ states | count }}

Nigh on a direct copy of Petro’s code - Thanks Again ! :beer:

1 Like

But how many of yours are missing because they are in AppDaemon ?
Do you get a count of AD entities even ? :man_shrugging:

Anyway I’d be happy to have just 1 (or lower) of everything as long as I had everything working “just as I want it” (come back to me in 10 years
BTW Teras has been doing this at least 10 years and he still says he hasn’t finished 8-0 :scream_cat:

I only have 500 or so entities. But all my appdaemon apps make single entities with tons of attributes. I think I have 3 regular automations.

Okay, so I have to ask, why 3 ?
Why not just get rid of all of them and put them in AD ?
Or are they just tooooo simple to bother ?

(See @Burningstone you are not alone ! )

way to simple to bother, it’s a reminder at 10 am on wednesday. I just don’t feel like making an app for it.

I don’t have a single entity that lives only in AppDaemon and not in HA. And anyway I would prefer to also have less entities in HA, more entities → more entities that can malfunction → more time for maintenance → less time for AppDaemon :rofl:

Will we ever be done? What will we do with our lives when our home automation is done ?:scream:

I have an app for that :rofl:
But I use it for a lot of different reminders for household tasks with actionable notifications etc.

I’m just too lazy to generalize it. And at the end of the day, i’d end up with the same configuration as the automation. So I said eff it.