Questions/help: chip cards at top of mobile dashboard - doors open count not working properly

good evening, all, I am semi new to HA (started in mid November 24’), I finally got around to making dashboards, working on my mobile dashboard right now and stumped a bit.

I am using chip cards at the very top of the Mobile Dashboard, call them ‘at a glance’, meaning I have one setup so far and working to simply show the number of lights on. the second chip card I am working on is to show the number of doors open, which is 21 right now :frowning: . I use templates for both of these so far, and have text pasted into my configuration.yaml. The problem is my door contacts are binary sensor entity’s so when I setup the template it also shows in the door open count, active presence sensors, temperature motion sensors, etc (since they are all binary sensors as well), which is why mobile dashboard shows 21 open doors right :frowning: . I see from the text I paste, I am able to right in to exclude binary sensors, but since I need to exclude like 15+ at least, that is too messy. There has to be a a smarter way, but I do not know it yet.

please help and I am semi understanding HA since I have been using for around 5 months/

below is the exact text I am pasting into my configuration.yaml for templates of lights and doors (lights is working fine). Also, attached is a screenshot of the top of my mobile dashboard showing my current chip cards.

thanks in advance!

template:
  - sensor:
    - name: "lights on"
      unique_id: lights_on
      icon: mdi:lightbulb-on
      state: "{{ states.light |selectattr('state','eq','on') | rejectattr('entity_id', 'search', 'light.ENTITY_YOU_DO_NOT_WANTED_COUNTED') | rejectattr('entity_id', 'search', 'light.ENTITY_YOU_DO_NOT_WANTED_COUNTED') | map(attribute='entity_id') | list | length}}"
  - sensor:
    - name: "doors open"
      unique_id: doors_open
      icon: mdi:mdi:door-open
      state: "{{ states.binary_sensor |selectattr('state','eq','on') | rejectattr('entity_id', 'search', 'binary_sensor.driveway_camera_motion', 'binary_sensor.charlotte_s_bedroom_human_presence_sensor_aqara_presence') | rejectattr('entity_id', 'search', 'binary_sensor.driveway_camera_motion', 'binary_sensor.charlotte_s_bedroom_human_presence_sensor_aqara_presence') | map(attribute='entity_id') | list | length}}"

Typo, remove one “mdi:”.

So, you have some amount of “binary_sensor” entities for these contacts.
Do these entities have some particular naming convention?
Particular device_class?

Example for finding sensors with some name & device_class (all binary sensors → reduce to device_class → reduce to “on” → reduce to some naming):

{{ states.binary_sensor |
selectattr('attributes.device_class', 'defined') |
selectattr('attributes.device_class', 'eq', 'connectivity') |
selectattr('state','eq','on') |
selectattr('entity_id', 'search', 'binary_sensor.some_mask') |
map(attribute='entity_id') | list }}

And after completion of testing in “Dev tools → Template” add "| count" at the end of the code.

thank you very very much for responding,
1- thanks I will fix that typo!
2- I have like 30 binary_sensors entity’s in my HA instance but I just want the open door count to show my 3 exterior doors (which have the same last word the end (front door / back door / side door).
3- I am not sure how to determine the device class, do not think I have do that before :frowning:
4- attached are two screenshots from HA devices, one is the 3 exterior door contacts and the other screenshot is an example of ecobee motion sensor that is ending up in my open door count :frowning:


Go to Dev tools → State & type this pattern: “binary_sensor*door”, let’s see what entities are there, then we’ll see their names & device_classes (if defined):

thanks, lldar, here is the list it returned. please see photo, thank you!!

OK, test this template in Dev tools → Template:

{{ states.binary_sensor |
selectattr('attributes.device_class', 'defined') |
selectattr('attributes.device_class', 'eq', 'door') |
selectattr('state','eq','on') |
selectattr('entity_id', 'search', '_eve_door') |
map(attribute='entity_id') | list }}

hi lldar, this is what it looks like.

Remove this line for testing:

selectattr('state','eq','on') |

because all doors could be “off”.

ok lldar, all doors were close, here is results with that line removed. And I tested another with the line still there and my back door open. (2 screenshots attached) thank you!!!


Good, now you can create your sensor))

1 Like

WE DID IT!!! IT WORKED!!! YOU ARE AMAZING, and I am thankful for the time you spent with me, lldar!!! see below!!!

1 Like