I am trying to make cards that say a tally of total doors open or total lights on.
After some searching, I came up with this
Lights On
{{ states.light|selectattr("state", "equalto", "on")|list|length }}
Doors Unlocked
{{ states.lock|selectattr("state", "equalto", "unlocked")|list|length }}
Doors Open
{{ states.cover|selectattr("state", "equalto", "open")|list|length }}
People Home
{{ states.person|selectattr("state", "equalto", "home")|list|length }}
This allowed me to create cards that displayed the total number of lights on or doors open. They would update instantly in real-time.
This was great except none of the numbers were accurate to the real world because it would pick up duplicate sensors or light rooms and groups. In some cases, a single bulb could increment the number by 5.
I needed a way to filter out some of my groups or entities to make the totals accurate.
I created groups with the lights I wanted to count and created a sensor with this.
{{ states | selectattr('entity_id','in',state_attr('group.room_lights_on','entity_id'))| selectattr('state','equalto','on') |list|length }}
This now fixes my accuracy issue and now shows the correct number of lights on. However; it does not update very quickly at all. In the template editor, it updates, but on a card, even a page refresh doesn’t seem to trigger a number change sometimes.
It seems like using a group slows down the polling. I could use some help figuring out how I can filter out or create a whitelist of entities so that I can get real-time totals numbers that are accurate.
Thanks