Lovelace Entity chip card conditions with sensor attribute

Hello

I tried to do a research about my issue but couldn’t find any solution, I already checked the documentation about conditions but seems like something is wrong from my side.

I have a template sensor of the count of my lights and wall switches.
I show an entity chip in my dashboard of the count of lights I have and the lights with status on, same for wall switches, but I want to show the chip only when there is a light on, if all off then no need to show the chip.

Sensor template:

- name: Counts
  unique_id: counts
  state: >
    {{ 0 }}
  attributes:
    lights: >
      {{
        states.light
        | rejectattr('state', 'in', '(unknown|unavailable)')
        | list
        | count
      }}
    lights_on: >
      {{
        states.light
        | rejectattr('state', 'in', '(unknown|unavailable|off)')
        | list
        | count
      }}
    lights_down: >
      {{
        states.light
        | selectattr('state', 'in', '(unknown|unavailable)')
        | list
        | count
      }}
    wall_switches: >
      {{
        states.switch
        | selectattr('attributes.device_class', 'eq', 'switch')
        | rejectattr('state', 'in', '(unknown|unavailable)')
        | list
        | count
      }}
    wall_switches_on: >
      {{
        states.switch
        | selectattr('attributes.device_class', 'eq', 'switch')
        | rejectattr('state', 'in', '(unknown|unavailable|off)')
        | list
        | count
      }}
    wall_switches_down: >
      {{
        states.switch
        | selectattr('attributes.device_class', 'eq', 'switch')
        | selectattr('state', 'in', '(unknown|unavailable)')
        | list
        | count
      }}

Chip YAML:

type: custom:mushroom-template-badge
entity: sensor.counts
content: >-
  {{ state_attr('sensor.counts', 'lights_on') }} of {{
  state_attr('sensor.counts', 'lights') }}
icon: |-
  {% if (state_attr('sensor.counts', 'lights_on') | int == 0) %}
  mdi:lightbulb-group-off
  {% else %}
  mdi:lightbulb-group
  {% endif %}
color: |-
  {% if (state_attr('sensor.counts', 'lights_on') | int == 0) %}
  disabled
  {% else %}
  orange
  {% endif %}
tap_action:
  action: navigate
  navigation_path: /lovelace/entities#wall-switch
visibility:
  - condition: template
    value_template: "{{ state_attr('sensor.counts', 'lights_on') > 0 }}"

for some reason, this condition does not work, I already found this in the HomeAssistant documentation here but didn’t work for me.

I tried with multiple ways I swear and I couldn’t make it work.

I appretiate your help, thanks.

EDIT:

Found the solution by doing this:

visibility:
  - condition: numeric_state
    entity: sensor.counts
    attribure: lights_on
    above: 0

Your template was a true/false question, not numeric based. Your logic simply asked if the number was greater than 0.

yes, cause I want to show the card if the lights on count is greater than 0, that’s why I check the count if it’s greater then it will return true to show the card.
am I wrong?

Your code is basically trying to compare text to a number so it will fail. Although the count looks like a number its a string value unless converted to an integer.

This would be one method to convert the string to an integer

value_template: "{{ state_attr('sensor.counts', 'lights_on') |int (0)> 0 }}"

I tried this and didn’t work.
Also the value of the sensor is number and not string, I tested it in the Developer Tools Template and compared it, the value is number.

I swear I tried many ways and nothing worked.