Conditional card based on attributes

Dear coders,

The season of POLLEN is coming up, and I want to make a nice informative dashboard.

Code 1 is the horizintal stack of my card. If shows 5 cards with POLLEN information.

My goal is that ONLY the cards are shown

if sensor.google_pollen_xxx_2 attribute index_level != 1 OR
if sensor.google_pollen_xxx_2 attribute tommorow > index_level

In human language, if no pollen are there and the level doesn’t go up the next day, don’t show.

I used Gemini to create a condition, but of course it cannot tip your knowledge level, of course :grin:

# Type kaart: Toont inhoud alleen als aan voorwaarden is voldaan
type: conditional

# De voorwaarden voor weergave
conditions:
  - condition: template # Nodig voor logica met attributen
    value_template: >
      {# De logische test: (index_value is niet 1) AND (tomorrow is groter dan index_value) #}
      {{ state_attr('sensor.google_pollen_grass_2', 'index_value') != 1 and
         state_attr('sensor.google_pollen_grass_2', 'tomorrow') > state_attr('sensor.google_pollen_grass_2', 'index_value') }}

# De kaart die getoond wordt als de voorwaarden WAAR zijn ("ja")
card:
  # --- Plaats hier de kaart die je voorwaardelijk wilt tonen ---
  type: entity
  entity: sensor.google_pollen_grass_2
  name: Graspollen (Alert) # Voorbeeld naam
  # --- Einde van de voorwaardelijke kaart ---

THANK YOU IN ADVANCE for your help!

Code 1:

type: horizontal-stack
cards:
  - type: custom:mushroom-template-card
    primary: "{{ state_attr('sensor.google_pollen_grass_2', 'display_name') }}"
    secondary: |-
      {% if states('sensor.google_pollen_grass_2') != "unknown" %}
        {% set level = state_attr('sensor.google_pollen_grass_2', 'index_value') | int %}
        {% set names = {0: 'None', 1:'Low', 2: 'Low +', 3:'Medium', 4:'High', 5:'Extreme'} %}
        {% set name = names[level] %} 
        {{ name }}
      {% endif %}
    icon: mdi:grass
    entity: sensor.google_pollen_grass_2
    layout: vertical
    fill_container: true
    tap_action:
      action: more-info
    hold_action:
      action: none
    double_tap_action:
      action: none
    icon_color: |-
      {% if states('sensor.google_pollen_grass_2') != "unknown" %}
        {% set level = state_attr('sensor.google_pollen_grass_2', 'index_value') | int %}
        {% set color = {0: 'grey', 1:'green', 2: 'yellow', 3:'orange', 4:'#FF6C71', 5:'red'} %}
        {% set level_color = color[level] %}
        {{ level_color }}
      {% endif %}
    badge_icon: |-
      {% if states('sensor.google_pollen_grass_2') != "unknown" %}
        {% if (state_attr('sensor.google_pollen_grass_2', 'tomorrow') | int < state_attr('sensor.google_pollen_grass', 'index_value') | int) %}
          mdi:arrow-down
        {% elif (state_attr('sensor.google_pollen_grass_2', 'tomorrow') | int > state_attr('sensor.google_pollen_grass', 'index_value') | int) %}
          mdi:arrow-up
        {% else %}
          mdi:minus
        {% endif %}
      {% endif %}
    badge_color: |-
      {% if states('sensor.google_pollen_grass_2') != "unknown" %}
        {% if (state_attr('sensor.google_pollen_grass_2', 'tomorrow') | int < state_attr('sensor.google_pollen_grass', 'index_value') | int) %}
          green
        {% elif (state_attr('sensor.google_pollen_grass_2', 'tomorrow') | int > state_attr('sensor.google_pollen_grass', 'index_value') | int) %}
          red
        {% endif %}
      {% endif %}
  - type: custom:mushroom-template-card
    primary: "{{ state_attr('sensor.google_pollen_oak_2', 'display_name') }}"
    secondary: |-
      {% if states('sensor.google_pollen_oak_2') != "unknown" %}
        {% set level = state_attr('sensor.google_pollen_oak_2', 'index_value') | int %}
        {% set names = {0: 'None', 1:'Low', 2: 'Low +', 3:'Medium', 4:'High', 5:'Extreme'} %}
        {% set name = names[level] %} 
        {{ name }}
      {% endif %}
    icon: mdi:leaf-maple
    entity: sensor.google_pollen_oak_2
    layout: vertical
    fill_container: true
    tap_action:
      action: more-info
    hold_action:
      action: none
    double_tap_action:
      action: none
    icon_color: |-
      {% if states('sensor.google_pollen_oak_2') != "unknown" %}
        {% set level = state_attr('sensor.google_pollen_oak_2', 'index_value') | int %}
        {% set color = {0: 'grey', 1:'green', 2: 'yellow', 3:'orange', 4:'#FF6C71', 5:'red'} %}
        {% set level_color = color[level] %}
        {{ level_color }}
      {% endif %}
    badge_icon: |-
      {% if states('sensor.google_pollen_oak_2') != "unknown" %}
        {% if (state_attr('sensor.google_pollen_oak_2', 'tomorrow') | int < state_attr('sensor.google_pollen_oak_2', 'index_value') | int) %}
          mdi:arrow-down
        {% elif (state_attr('sensor.google_pollen_oak_2', 'tomorrow') | int > state_attr('sensor.google_pollen_oak_2', 'index_value') | int) %}
          mdi:arrow-up
        {% else %}
          mdi:minus
        {% endif %}
      {% endif %}
    badge_color: |-
      {% if states('sensor.google_pollen_oak_2') != "unknown" %}
        {% if (state_attr('sensor.google_pollen_oak_2', 'tomorrow') | int < state_attr('sensor.google_pollen_oak_2', 'index_value') | int) %}
          green
        {% elif (state_attr('sensor.google_pollen_oak_2', 'tomorrow') | int > state_attr('sensor.google_pollen_oak_2', 'index_value') | int) %}
          red
        {% endif %}
      {% endif %}
  - type: custom:mushroom-template-card
    primary: "{{ state_attr('sensor.google_pollen_tree_2', 'display_name') }}"
    secondary: |-
      {% if states('sensor.google_pollen_tree_2') != "unknown" %}
        {% set level = state_attr('sensor.google_pollen_tree_2', 'index_value') | int %}
        {% set names = {0: 'None', 1:'Low', 2: 'Low +', 3:'Medium', 4:'High', 5:'Extreme'} %}
        {% set name = names[level] %} 
        {{ name }}
      {% endif %}
    icon: mdi:pine-tree
    entity: sensor.google_pollen_tree_2
    layout: vertical
    fill_container: true
    tap_action:
      action: more-info
    hold_action:
      action: none
    double_tap_action:
      action: none
    icon_color: |-
      {% if states('sensor.google_pollen_tree_2') != "unknown" %}
        {% set level = state_attr('sensor.google_pollen_tree_2', 'index_value') | int %}
        {% set color = {0: 'grey', 1:'green', 2: 'yellow', 3:'orange', 4:'#FF6C71', 5:'red'} %}
        {% set level_color = color[level] %}
        {{ level_color }}
      {% endif %}
    badge_icon: |-
      {% if states('sensor.google_pollen_tree_2') != "unknown" %}
        {% if (state_attr('sensor.google_pollen_tree_2', 'tomorrow') | int < state_attr('sensor.google_pollen_tree_2', 'index_value') | int) %}
          mdi:arrow-down
        {% elif (state_attr('sensor.google_pollen_tree_2', 'tomorrow') | int > state_attr('sensor.google_pollen_tree_2', 'index_value') | int) %}
          mdi:arrow-up
        {% else %}
          mdi:minus
        {% endif %}
      {% endif %}
    badge_color: |-
      {% if states('sensor.google_pollen_tree_2') != "unknown" %}
        {% if (state_attr('sensor.google_pollen_tree_2', 'tomorrow') | int < state_attr('sensor.google_pollen_tree_2', 'index_value') | int) %}
          green
        {% elif (state_attr('sensor.google_pollen_tree_2', 'tomorrow') | int > state_attr('sensor.google_pollen_tree_2', 'index_value') | int) %}
          red
        {% endif %}
      {% endif %}
  - type: custom:mushroom-template-card
    primary: "{{ state_attr('sensor.google_pollen_birch_2', 'display_name') }}"
    secondary: |-
      {% if states('sensor.google_pollen_birch_2') != "unknown" %}
        {% set level = state_attr('sensor.google_pollen_birch_2', 'index_value') | int %}
        {% set names = {0: 'None', 1:'Low', 2: 'Low +', 3:'Medium', 4:'High', 5:'Extreme'} %}
        {% set name = names[level] %} 
        {{ name }}
      {% endif %}
    icon: mdi:pine-tree-variant-outline
    entity: sensor.google_pollen_birch_2
    layout: vertical
    fill_container: true
    tap_action:
      action: more-info
    hold_action:
      action: none
    double_tap_action:
      action: none
    icon_color: |-
      {% if states('sensor.google_pollen_birch_2') != "unknown" %}
        {% set level = state_attr('sensor.google_pollen_birch_2', 'index_value') | int %}
        {% set color = {0: 'grey', 1:'green', 2: 'yellow', 3:'orange', 4:'#FF6C71', 5:'red'} %}
        {% set level_color = color[level] %}
        {{ level_color }}
      {% endif %}
    badge_icon: |-
      {% if states('sensor.google_pollen_birch_2') != "unknown" %}
        {% if (state_attr('sensor.google_pollen_birch_2', 'tomorrow') | int < state_attr('sensor.google_pollen_birch_2', 'index_value') | int) %}
          mdi:arrow-down
        {% elif (state_attr('sensor.google_pollen_birch_2', 'tomorrow') | int > state_attr('sensor.google_pollen_birch_2', 'index_value') | int) %}
          mdi:arrow-up
        {% else %}
          mdi:minus
        {% endif %}
      {% endif %}
    badge_color: |-
      {% if states('sensor.google_pollen_birch_2') != "unknown" %}
        {% if (state_attr('sensor.google_pollen_birch_2', 'tomorrow') | int < state_attr('sensor.google_pollen_birch_2', 'index_value') | int) %}
          green
        {% elif (state_attr('sensor.google_pollen_birch_2', 'tomorrow') | int > state_attr('sensor.google_pollen_birch_2', 'index_value') | int) %}
          red
        {% endif %}
      {% endif %}
  - type: custom:mushroom-template-card
    primary: "{{ state_attr('sensor.google_pollen_pine_2', 'display_name') }}"
    secondary: |-
      {% if states('sensor.google_pollen_pine_2') != "unknown" %}
        {% set level = state_attr('sensor.google_pollen_pine_2', 'index_value') | int %}
        {% set names = {0: 'None', 1:'Low', 2: 'Low +', 3:'Medium', 4:'High', 5:'Extreme'} %}
        {% set name = names[level] %} 
        {{ name }}
      {% endif %}
    icon: mdi:flower-pollen-outline
    entity: sensor.google_pollen_pine_2
    layout: vertical
    fill_container: true
    tap_action:
      action: more-info
    hold_action:
      action: none
    double_tap_action:
      action: none
    icon_color: |-
      {% if states('sensor.google_pollen_pine_2') != "unknown" %}
        {% set level = state_attr('sensor.google_pollen_pine_2', 'index_value') | int %}
        {% set color = {0: 'grey', 1:'green', 2: 'yellow', 3:'orange', 4:'#FF6C71', 5:'red'} %}
        {% set level_color = color[level] %}
        {{ level_color }}
      {% endif %}
    badge_icon: |-
      {% if states('sensor.google_pollen_pine_2') != "unknown" %}
        {% if (state_attr('sensor.google_pollen_pine_2', 'tomorrow') | int < state_attr('sensor.google_pollen_pine_2', 'index_value') | int) %}
          mdi:arrow-down
        {% elif (state_attr('sensor.google_pollen_pine_2', 'tomorrow') | int > state_attr('sensor.google_pollen_pine_2', 'index_value') | int) %}
          mdi:arrow-up
        {% else %}
          mdi:minus
        {% endif %}
      {% endif %}
    badge_color: |-
      {% if states('sensor.google_pollen_pine_2') != "unknown" %}
        {% if (state_attr('sensor.google_pollen_pine_2', 'tomorrow') | int < state_attr('sensor.google_pollen_pine_2', 'index_value') | int) %}
          green
        {% elif (state_attr('sensor.google_pollen_pine_2', 'tomorrow') | int > state_attr('sensor.google_pollen_pine_2', 'index_value') | int) %}
          red
        {% endif %}
      {% endif %}
visibility:
  - condition: numeric_state
    entity: sensor.google_pollen_grass_2
    above: 1
  - condition: or
    conditions:
      - condition: numeric_state
        entity: sensor.google_pollen_grass_2
        above: 2

can you Help me Custom cards not showing and not usable

im new to HA and HACS

im running on VM

  • Core2025.4.2
  • Supervisor2025.04.0
  • Operating System15.1
  • Frontend20250411.0

Sorry, I have no idea. I hope a member can help me :man_shrugging:t3:

Frontend conditional card / visibility options does not support templates, and does not support attributes.

https://www.home-assistant.io/dashboards/conditional/#conditions-options

Your only option is to either use custom cards to enable that, or to make a template sensor from your attribute that you want to monitor, and then write your conditions against that sensor.