#How can I avoid showing an entity in a list of entities when that entity has no state?

1 messages · Page 1 of 1 (latest)

warped vector
#

I have this card in my dashboard. ```
type: entities
title: House Battery status
entities:

  • entity: sensor.battery_state_of_capacity
  • type: custom:template-entity-row
    icon: mdi:battery-90
    name: "{{states('sensor.battery_tou_period_1')}}"
  • type: custom:template-entity-row
    icon: mdi:battery-90
    name: "{{states('sensor.battery_tou_period_2')}}"
  • type: custom:template-entity-row
    icon: mdi:battery-90
    name: "{{states('sensor.battery_tou_period_3')}}"
  • type: custom:template-entity-row
    icon: mdi:battery-90
    name: "{{states('sensor.battery_tou_period_4')}}"```

Because the state of the entities when there is a state are rather long I decided to only show the state as the name, and that works nicelyas seen on the screen shot.

I have tried to filter with auto-entities and to use templates with config-template but nothing seems to work.

Anyone with a good idea?

digital quiver
#

Try applying some card_mod . ```yaml

  • type: custom:template-entity-row
    icon: mdi:battery-90
    name: "{{states('sensor.battery_tou_period_1')}}"
    card_mod:
    style:
    div#wrapper:
    .: |
    :host {
    {% if states('config.entity') == 'unknown' %}
    display: none !important;
    {% endif %}
    }
digital quiver
#

Actually, now that I think about it a bit more, you might not need a template for auto-entities. Perhaps excluding unknown states yaml exclude: - state: unknown and filter your entities to including a wildcard```yaml
filter:
include:
- entity_id: sensor.battery_state_of_capacity
options: {}
- entity_id: sensor.battery_tou_period_*
options:
type: custom:template-entity-row
name: '{{ states("this.entity_id") }}'
icon: mdi:battery-90

warped vector
#

The problem I ran into with auto-entities was that because I use the state as the entities' names, the name is only established after the filter is applied. In fact when excluding unknown as state the names still appeared as "Unknown".

#

Did your card_mod trick and that filters out fine - everything - even when there is a valid state:```
type: entities
title: House Battery status
entities:

  • entity: sensor.battery_state_of_capacity
  • type: custom:template-entity-row
    icon: mdi:battery-90
    name: "{{states('sensor.battery_tou_period_1')}}"
    card_mod:
    style:
    div#wrapper:
    .: |
    :host {
    {% if states('config.entity') == 'unknown' %}
    display: none !important;
    {% endif %}
    }
  • type: custom:template-entity-row
    icon: mdi:battery-90
    name: "{{states('sensor.battery_tou_period_2')}}"
    card_mod:
    style:
    div#wrapper:
    .: |
    :host {
    {% if states('config.entity') == 'unknown' %}
    display: none !important;
    {% endif %}
    }
  • type: custom:template-entity-row
    icon: mdi:battery-90
    name: "{{states('sensor.battery_tou_period_3')}}"
    card_mod:
    style:
    div#wrapper:
    .: |
    :host {
    {% if states('config.entity') == 'unknown' %}
    display: none !important;
    {% endif %}
    }
  • type: custom:template-entity-row
    icon: mdi:battery-90
    name: "{{states('sensor.battery_tou_period_4')}}"
    card_mod:
    style:
    div#wrapper:
    .: |
    :host {
    {% if states('config.entity') == 'unknown' %}
    display: none !important;
    {% endif %}
    }
digital quiver
#

🤦‍♂️ I forgot that you didn't actually define each entity. Just replace the config.entity with the respective entity.

  - type: custom:template-entity-row
    icon: mdi:battery-90
    name: "{{states('sensor.battery_tou_period_1')}}"
    card_mod:
      style:
        div#wrapper:
          .: |
            :host {
              {% if states('sensor.battery_tou_period_1') == 'unknown' %} 
                display: none !important;
              {% endif %}
            }
```or, by defining the entity, this should work too```yaml
  - type: custom:template-entity-row
    entity: sensor.battery_tou_period_1
    icon: mdi:battery-90
    name: '{{ states(config.entity) }}'
    card_mod:
      style:
        div#wrapper:
          .: |
            :host {
              {% if states(config.entity) == 'unknown' %} 
                display: none !important;
              {% endif %}
            }
warped vector
#

Ok, that brought back - everything - irrespective of state? and used the first method, as the second one reintroduced the 2 column layout

digital quiver
#

Try a captal U in unknown. States are normally lower cased so it's weird that your's in the screenshot show with a capital U.