i like to create a card that show me the count of open windows or doors.
Searching show me a big number card, but only for sensors, the door/window sensors are switches in HA. So does anybody of you done such a card, or can give me some tips to create one by myself.
First of call, might be a stupid question, but why did you define door/window sensors as switches in HA and not binary_sensors?
otherwise I’d either create a filter card to display only entities that are open (e.g. on) or I’d create a template sensor that counts the number of open windows.
that would require a for loop, check the template editor, there’s already a great example for this
If you specifically want to count the number, you need to make a template sensor to do that, then display the template sensor in lovelace. Lovelace is a UI, it’s not going to do much logic other than show/hide.
Here’s a template that counts lights that are on:
sensor:
- platform:template
sensors:
count_lights:
value_template: >
{% set searchthisgroup = 'group.all_lights' %}
{% set findstates = [ 'on', 'open' ] %}
{{ states | selectattr('entity_id', 'in', state_attr(searchthisgroup,'entity_id')) | selectattr('state','in',findstate) | list | length }}
so if you want to use this for doors and windows, make a group of doors and windows. Then just modify the searchthisgroup variable. This will only update when the group updates. If you want it to update live, then you need to use this code:
This code needs to be managed a little more because you need to add the entity_id’s into the template. This will update every time an entity in the entities list updates. So it will be live.