Wildcard entities card

I would love for there to be a card where you could specify a wildcard for the entities that get displayed. Or just have the ability to use wildcards in entity selection. For example, if I would like to have a single card with all of my motion sensors displayed on it:

- type: entities
  title: All Motion Sensors
  wildcard_entities: binary_sensor.*_motion_sensor

Or something like that. I have several use cases:

  • Easily make a list of all motion or door sensors as a security card. Could be combined with a filter to only show the ones that are active
  • Card with all automations listed, to be able to easily disable ones during guests/parties/maintenance
  • Card will all lights, combined with filter to only show the ones that are on

Stuff like that.

1 Like

Take a look at monster-card, may be what you’re after.

2 Likes

i use an entity card, but have a single sensor for
all doors
all motion
all locks

the locks sensor will show something like this:

Back Door, Front door & Utility Door Unlocked

Here is an example of the sensor.motion_summary:

- platform: template
       sensors:
         motion_summary:
           value_template: >
             {%-for state in states.binary_sensor
               if(state.attributes.device_class=="motion" and state.state=="on")-%}
                 {%-if loop.last-%}
                   {%-if loop.index > 0-%}
                     {%-for state in states.binary_sensor if(state.attributes.device_class=="motion" and state.state =="on")-%}
                       {{state.name}}{%-if not loop.last -%}{%-if(loop.index+1==loop.length)%} & {%else%}, {%endif-%}{%-else%} active{%endif-%}
                     {%-endfor-%}
                   {%-endif-%}
                 {%-endif-%}
               {%-else-%}
                 all clear
             {%-endfor-%}
           icon_template: >
             {%-for state in states.binary_sensor
               if(state.attributes.device_class=="motion" and state.state=="on")-%}
                 {%-if loop.last-%}
                   {%-if loop.index > 0-%}
                       mdi:run-fast
                   {%-endif-%}
                 {%-endif-%}
               {%-else-%}
                 mdi:check
             {%-endfor-%}
3 Likes

Great scott! That’s exactly what I was after! :sparkler:

Thank you, @JTPublic!

Anyone have the skills to tweak that code to summarize devices with either say attributes.device_class = battery or with attributes.battery_level and a value below 75? Trying to find an easy way to summarise all battery powered devices into one notification without going to the full on MQTT discovery battery_levels package thingy.

What am I missing
I have

  - platform: template
    sensors:
      motion_summary:
         value_template: >
          {%-for state in states.binary_sensor 
            if(state.attributes.device_class=="motion" and state.state=="on") -%}
          {%-if loop.last-%}
          {%-if loop.index > 0-%}
          {%-for state in states.binary_sensor if(state.attributes.device_class=="motion" and state.state =="on")-%}
          {{state.name}}{%-if not loop.last -%}{%-if(loop.index+1==loop.length)%} & {%else%}, {%endif-%}{%-else%} active{%endif-%}
          {%-endfor-%}
          {%-endif-%}
          {%-endif-%}
          {%-else-%}
            all clear
          {%-endfor-%}
         icon_template: >
          {%-for state in states.binary_sensor 
            if(state.attributes.device_class=="motion" and state.state=="on")-%}
          {%-if loop.last-%}
          {%-if loop.index > 0-%}
            mdi:alert
          {%-endif-%}
          {%-endif-%}
          {%-else-%}
          mdi:check
          {%-endfor-%}

all it show me is all clear
if put in the tempate thing


but in the front end I see all clear
image

which manual should i be reading
thanks

2 Likes

Your indentation is all messed up. I’m not an expert in Jinja, but I know in the YAML files, indentation matters. Look at the example a few posts above yours.

I know it’s been years but as a new HA user i came across this thread while searching for a good way to display low battery devices.

I’ve got it working now using the example above. Here are my 4 templates for doors, locks, motion and battery.

#### COMBINED MOTION/LOCK SENSORS #####################################################
#### Source: https://community.home-assistant.io/t/wildcard-entities-card/72969/3
#######################################################################################
- platform: template
  sensors:
    motion_summary:
      value_template: >
         {%-for state in states.binary_sensor
           if(state.attributes.device_class=="motion" and state.state=="on")-%}
             {%-if loop.last-%}
               {%-if loop.index > 0-%}
                 {%-for state in states.binary_sensor if(state.attributes.device_class=="motion" and state.state =="on")-%}
                   {{state.name}}{%-if not loop.last -%}{%-if(loop.index+1==loop.length)%} & {%else%}, {%endif-%}{%-else%} active{%endif-%}
                 {%-endfor-%}
               {%-endif-%}
             {%-endif-%}
           {%-else-%}
             No motion
         {%-endfor-%}
      icon_template: >
         {%-for state in states.binary_sensor
           if(state.attributes.device_class=="motion" and state.state=="on")-%}
             {%-if loop.last-%}
               {%-if loop.index > 0-%}
                   mdi:run-fast
               {%-endif-%}
             {%-endif-%}
           {%-else-%}
             mdi:motion-sensor-off
         {%-endfor-%}
    door_summary:
      value_template: >
         {%-for state in states.binary_sensor
           if(state.attributes.device_class=="opening" and state.state=="on")-%}
             {%-if loop.last-%}
               {%-if loop.index > 0-%}
                 {%-for state in states.binary_sensor if(state.attributes.device_class=="opening" and state.state =="on")-%}
                   {{state.name}}{%-if not loop.last -%}{%-if(loop.index+1==loop.length)%} & {%else%}, {%endif-%}{%-else%} open{%endif-%}
                 {%-endfor-%}
               {%-endif-%}
             {%-endif-%}
           {%-else-%}
             All closed
         {%-endfor-%}
      icon_template: >
         {%-for state in states.binary_sensor
           if(state.attributes.device_class=="opening" and state.state=="on")-%}
             {%-if loop.last-%}
               {%-if loop.index > 0-%}
                   mdi:door-open
               {%-endif-%}
             {%-endif-%}
           {%-else-%}
             mdi:door-closed-lock
         {%-endfor-%}
       lock_summary:
         friendly_name: Lock Summary
         value_template: >
           {%-for state in states.lock
             if state.state== "unlocked" -%}
               {%-if loop.last-%}
                 {%-if loop.index > 0-%}
                   {%-for state in states.lock if state.state == "unlocked" -%}
                     {{state.name | replace('Lock', '')}}{%-if not loop.last -%}{%-if(loop.index+1==loop.length)%} & {%else%}, {%endif-%}{%-else%} unlocked{%endif-%}
                   {%-endfor-%}
                 {%-endif-%}
               {%-endif-%}
             {%-else-%}
               All locked
           {%-endfor-%}
         icon_template: >
           {%-for state in states.lock
             if state.state == "unlocked" -%}
               {%-if loop.last-%}
                 {%-if loop.index > 0-%}
                     mdi:lock-alert-outline
                 {%-endif-%}
               {%-endif-%}
             {%-else-%}
               mdi:lock-check-outline
           {%-endfor-%}
         
#### LOW BATTERY SENSOR ###############################################################
#### Source: https://community.home-assistant.io/t/wildcard-entities-card/72969/3
#######################################################################################
- platform: template
  sensors:
    low_battery_summary:
      value_template: >
         {%-for state in states.sensor if(state.attributes.device_class=="battery" and state.state | int <= 25)-%}
             {%-if loop.last-%}
               {%-if loop.index > 0-%}
                 {%-for state in states.sensor if(state.attributes.device_class=="battery" and state.state | int <= 25)-%}
                   {{state.name}}{%-if not loop.last -%}{%-if(loop.index+1==loop.length)%} & {%else%}, {%endif-%}{%-else%} low{%endif-%}
                 {%-endfor-%}
               {%-endif-%}
             {%-endif-%}
           {%-else-%}
             Everything is charged
         {%-endfor-%}
      icon_template: >
         {%-for state in states.sensor
           if(state.attributes.device_class=="battery" and state.state | int <= 25)-%}
             {%-if loop.last-%}
               {%-if loop.index > 0-%}
                   mdi:battery-10
               {%-endif-%}
             {%-endif-%}
           {%-else-%}
             mdi:battery
         {%-endfor-%}

image

2 Likes

This type of functionality should really be packaged into a component that is more consumable for casual users. I read that entity-filter used to something similar, but that functionality was removed. It’s really a shame because having the ability to do wildcards on entity name/id’s would make HomeAssistant a lot more usable and approachable.

1 Like

Update: Looks like lovelace-auto-entities. will do the trick!

I haven’t tried it yet, though.