Auto Entities card?: How to display another card when no results are found in the initial filters

Hello all,

Is there anyway to get the auto-entities card to show a message when there are no entities that pass all filters?

Below is what I have and I can’t figure out the syntax to get either the “else” arguement to work.

I would like the card to say “No battery devices are at their low battery threshold”

type: custom:auto-entities
card:
  type: custom:battery-state-card
  title: Low Battery Levels (Dynamic)
  show_header_toggle: true
  colors:
    steps:
      - value: 30
        color: '#ff0000'
      - value: 50
        color: '#ffff00'
  filter:
    exclude:
      - name: state
        operator: '>'
        value: 50
  sort: state
filter:
  include:
    - name: '*Battery Level*'
  exclude:
    - name: Lenovo*
    - name: '*Weston*'
    - name: '*Garage Door*'

The below is not working for me in terms of showing the 3 sensor entities if no entities meet the initial filters:

type: custom:auto-entities
card:
  type: custom:battery-state-card
  title: Low Battery Levels (Dynamic)
  show_header_toggle: true
  colors:
    steps:
      - value: 30
        color: '#ff0000'
      - value: 50
        color: '#ffff00'
  filter:
    exclude:
      - name: state
        operator: '>'
        value: 50
  sort: state
filter:
  include:
    - name: '*Battery Level*'
  exclude:
    - name: Lenovo*
    - name: '*Weston*'
    - name: '*Garage Door*'
else:
  type: entities
  entities:
    - sensor.time
    - sensor.date
    - sensor.date_time
  title: test
  state_color: true
  show_header_toggle: false

I don’t believe there is a way to do what you want with the auto entities card, but you could use a conditional card to display your auto entities card when there are low batteries and a markup card with your message when there is not. You’d probably have to come up with a template sensor to indicate when there are low batteries or use the custom state switch card.

But why are you using the auto entities card with battery state card? That functionality is built right into battery state card!

Also, why go through this effort to hide the card just to display a static message? Why not just let the battery state card (which is great btw) show all your batteries? If you have too many batteries just use the collapse parameter to control how many show and sort by battery level so lowest batteries are always on top.

image

Here’s my code for this card.

Thank you for this response @jazzyisj !

I will probably end up going the route you are speaking of (the multiple options you gave me)

Can you help me understand what the “else” parameter is for at the following github. I imagine you are correct because you have helped me multiple times here over the past few years.

I just thought that was it’s exact purpose. But I definitely can’t get it to work so I imagine I’m wrong.

Thank you again for your guidance.

I think you just taught me something! I didn’t realize that option had been added in (or maybe it was always there?) I didn’t see an example on the readme, but I think you should be able to use it like this.

else:
  type: markdown
  content: "No battery devices are at their low battery threshold"

For whatever reason, I can’t get it to work. Home Assistant makes me sad some days. haha. Most days.

type: custom:auto-entities
card:
  type: custom:battery-state-card
  title: Low Battery Levels (Dynamic)
  colors:
    steps:
      - value: 30
        color: '#ff0000'
      - value: 50
        color: '#ffff00'
  filter:
    exclude:
      - name: state
        operator: '>'
        value: 50
  sort: state
filter:
  include:
    - name: '*Battery Level*'
  exclude:
    - name: '*Lenovo*'
    - name: '*Weston*'
    - name: '*Garage Door*'
view_layout:
  position: main
else:
  type: markdown
  content: "No battery devices are at their low battery threshold"

What am I doing wrong, I feel like this should be simple based on the docs. I’m starting to think, it just doesn’t work.

Your exclude filter on the battery-state-card makes auto-entities still see a card to display.

Move the exclude filter to auto-entities.

Then, auto-entities can do the else.
Examples:

type: custom:auto-entities
card:
  type: custom:battery-state-card
  title: Low Battery Levels (Dynamic)
  colors:
    steps:
      - value: 30
        color: '#ff0000'
      - value: 50
        color: '#ffff00'
  sort: state
filter:
  include:
    - name: '*Battery Level*'
  exclude:
    - state: '> 50'
else:
  type: markdown
  content: >-
    <ha-alert alert-type="info">No battery devices are at their low battery
    threshold</ha-alert>

Shows:

And:

type: custom:auto-entities
card:
  type: custom:battery-state-card
  title: Low Battery Levels (Dynamic)
  colors:
    steps:
      - value: 30
        color: '#ff0000'
      - value: 50
        color: '#ffff00'
  sort: state
filter:
  include:
    - name: '*Battery Level*'
  exclude:
    - state: '> 10'
else:
  type: markdown
  content: >-
    <ha-alert alert-type="info">No battery devices are at their low battery
    threshold</ha-alert>

Shows:

2 Likes
  1. Strongly suggest to ask similar threads in the dedicated auto-entities thread. This way will keep the Community tidy, all solutions will be in one place (not scattered in 100500 places), you will attract more experienced users & share your solutions with more people.

  2. Auto-entities with a “template” filter can either show a set of cards (Ui elements) for filtered entities - or just show another card if a list of entities is empty. Depends on a template which a user defines.
    Example is here.

изображение

изображение

Nice catch!

1 Like

This code is strange.
First, these lines

view_layout:
  position: main

do not belong to the “auto-entities” card - they are from a custom:layout-card and are supposed be only used when the “auto-entities” card is placed inside layout-card.
Next, these lines

else:
  type: markdown
  content: >-
    <ha-alert alert-type="info">No battery devices are at their low battery
    threshold</ha-alert>

also do not belong to “auto-entities” - and I wonder where they came from?
I suppose they were used in a 1st place to demonstrate a logic “if true - show card_X, else show card_Y”, not as a working code.

1 Like

As usual, you are correct (mostly).

Your first comment is right on. I often just grab something I already have, throw it into a test card, and make the changes I am looking at while ignoring the extra. And, you have caught me on this before. Love the consistency!!!

But, you are wrong about the else. See below:

I also edited my above post to remove the extraneous crap pointed out by @Ildar_Gabdullin!

1 Like

Man! You are great))
Thank you))))

Props to @wtstreetglow for pointing it out above.

I just ran with it.

Never used “else” myself & probably missed a moment when it was added))

1 Like

@Ildar_Gabdullin Thank you for that suggestion. I will do that from now on and completely agree with you.

I follow you on this and thank you for that example!!

Thank you for showing me how to do this!!

1 Like

Thank you for making this simple for me!! It’s very possible that extraneous crap came from my first code post because I had it in there from my first attempt at writing this. I have since edited my first topic post to correct this also.

1 Like

Thank you again for all of your help on this one. I learned alot about how this works!!

1 Like