thomasloven / lovelace-auto-entities

🔹Automatically populate the entities-list of lovelace cards
MIT License
1.26k stars 116 forks source link

show_empty doesn't work with template-entity-row #322

Closed shaymdev closed 1 year ago

shaymdev commented 1 year ago

I'm using template-entity-row to show entities that "need attention". Each row has its own condition (if garbage day is today, if the vacuum sensors need cleaning, if a window was left open, etc).

If there are no entities "needing attention" I want the whole card to disappear.

I'm trying to use the auto-entities card to achieve this but the way it triggers "empty" or not doesn't work with the way template-entity-row hides its row based on condition.

Is there another way to achieve what I'm hoping for? If not does this seem like a reasonable enhancement to the auto-entities card?

ildar170975 commented 1 year ago

Do not observe the same.

Card:

type: custom:auto-entities
card:
  type: entities
  title: title
show_empty: false
filter:
  include:
    - domain: person
      state: xxxxxx
      options:
        type: custom:template-entity-row

When state: xxxxxx line is removed: image

With this line: image

Surely, if your condition for "do not show a row" is a some complex expression - then standard filtering options of auto-entities (like state, attributes, ...) will not work, you will need to define templated conditions by using a template filter.

Actually, you should have started with posting a short code describing your problem.

shaymdev commented 1 year ago

You're right, I should have included some code! That will probably be the quickest to show you guys that I'm doing it wrong 😆 It's likely that what you say about the condition being too complex and that I need to do some template filter is the case... but I'm pretty new to this stuff and don't know my way around too well.

Here's my code as it stands now.

type: custom:auto-entities
card:
  type: entities
  title: Need Attention
entities:
  - type: custom:template-entity-row
    entity: sensor.recycle_day
    condition: '{{state_attr(''sensor.recycle_day'', ''days'') <= 1}}'
  - type: custom:template-entity-row
    entity: sensor.garbage_day
    condition: '{{state_attr(''sensor.garbage_day'', ''days'') <= 1}}'
  - type: custom:template-entity-row
    entity: input_boolean:thermostats_enabled
    icon: mdi:thermometer
    state: Thermostat is disabled
    condition: '{{is_state(''input_boolean.thermostats_enabled'', ''off'')}}'
  - type: custom:template-entity-row
    name: Robo Vacuum
    icon: mdi:robot-vacuum
    state: Replace main brush
    condition: '{{state_attr(''vacuum.robo'', ''main_brush_left'') <= 1}}'
  - type: custom:template-entity-row
    name: Robo Vacuum
    icon: mdi:robot-vacuum
    state: Replace side brush
    condition: '{{state_attr(''vacuum.robo'', ''side_brush_left'') <= 1}}'
  - type: custom:template-entity-row
    name: Robo Vacuum
    icon: mdi:robot-vacuum
    state: Replace filter
    condition: '{{state_attr(''vacuum.robo'', ''filter_left'') <= 1}}'
  - type: custom:template-entity-row
    name: Robo Vacuum
    icon: mdi:robot-vacuum
    state: Clean sensors
    condition: '{{state_attr(''vacuum.robo'', ''sensor_dirty_left'') <= 1}}'
  - type: custom:template-entity-row
    entity: sensor.samba_backup
    condition: '{{is_state(''sensor.samba_backup'', ''FAILED'')}}'
show_empty: false

image

ildar170975 commented 1 year ago
  1. Surely, posting a code to demonstrate an issue is a right way. But I strongly suggest you to post a short MWE (google it, Minimal Working Example). Long code is harder to understand and may distract people.
  2. The way you are using auto-entities is not 100% correct. Check the docs. You listed all your rows inside the entities section - surely this card will be shown as empty when all conditions are false. The card is supposed to show entities inside the entities section + entities defined inside the filter section (which you have not defined at all). Finally, since you listed ALL your entities - there is now need to use auto-entities at all.

Still, auto-entities may be used here. Place all entities INSIDE the filter section. Do not use the condition option - use these conditions inside the filter section (check Docs!!!!). Then each row will be shown when some conditions are met -> and the card will be NOT shown when all conditions are NOT met.

Suggest you to move this discussion into the dedicated auto-entities Community thread since this is neither a bug nor a feature request. It is better to use GitHub for bugs & FRs only.

shaymdev commented 1 year ago

Thanks for your help. I implemented this card quite a while ago and never figured out why I couldn't get the show empty to work. I was afraid I was using things wrong, which you have shown to me to be the case.

I'll reevaluate how I'm tackling this problem and post to that Community thread if I decide auto-entities is the right tool for the job.