Mushroom Chips card icon_color changing based on state

Hello,
this is my script for my chips card on top of my dashboard. I would like the color of the battery icon to change, based on its sensor’s state:

  - type: custom:mushroom-chips-card
    chips:
      - type: entity
        entity: sensor.tabingresso_battery_level
        double_tap_action:
          action: none
        use_entity_picture: false
        hold_action:
          action: none
        icon_color: >-
          {% set level = state('sensor.tabingresso_battery_level') %}
          {% if level >= 7 %}
            green
          {% else %}
            red
          {% endif %}

…but con is always white:
immagine

This below code works if used for a custom:mushroom-template-card (still not works for chips card), but only if I tell the script to look for a specific value (29):

{% if is_state('sensor.tabingresso_battery_level', '29') %}
  yellow
{% endif %}

Any idea??
Thanks! :wink:

The function is states() not state()… but there are other changes you need to make as well.
States are always strings, so you need to convert them to a integer or float before using mathematical operations or comparisons.

Optionally, Mushroom allows use of a variable entity so you don’t need to use the whole entity_id

  - type: custom:mushroom-chips-card
    chips:
      - type: template
        entity: sensor.tabingresso_battery_level
        double_tap_action:
          action: none
        use_entity_picture: false
        hold_action:
          action: none
        icon: mdi:battery
        icon_color: >-
          {% set level = states(entity) | int(0) %}
          {% if level >= 7 %}
            green
          {% else %}
            red
          {% endif %}

Thank you very much for the explanation, but it is still not working.
If it helps, this is the entity: