Badge Phone battery color question

At the moment I’m using the code below to see the state of my iPhone battery. Is there anyone that can help to adjust it have a between color. So if the battery is above 60% the color is green, between 30 and 60% orange and below 30% red.


- badges:
    - entity: sensor.iphone_battery_level
        icon: null
        name: null
        style: |
          :host {
            —label-badge-blue: {% if is_state(‘sensor.iphone_battery_level’, ‘> 60’) %} green {% else %} red {% endif %};
          }

Just add a second condition element. In the example below I am checking for different brightness values. You can adopt the same approach for your condition. You can easily test your adjusted template in the HA dev tools.

{% if state_attr('light.office_ceiling', 'brightness') > 125 %} green {% elif state_attr('light.office_ceiling', 'brightness') > 70 %} orange {% else %} red {% endif %}

Thanks. In the meanwhile found a solution that works fine.

      - entity: sensor.andys_iphone_battery_level
        icon: null
        name: null
        style: |
          :host {
            --label-badge-red:
            {% if states(config.entity)|int < 30 %}
              #e45649
            {% elif states(config.entity)|int < 70 %}
              #ffc640
            {% elif states(config.entity)|int <= 100 %}
              #50A14F
            {% endif %}
            ;
1 Like