The color of the bage differs from the state of the input_number

Hi! Help me, pls. I need to change the color of the number with card_mod that differes from the input_number

Now I have:

type: entities
entities:
  - entity: sensor.nositel_local
    card_mod:
      style: |
        :host {
          color:
            {% if states(config.entity) | int <= 17 %} 
              red
            {% elif states(config.entity) | int >= 17 %}
              green
            {% endif %}
            ;
        }

And it works well.Tried to change to this, but it is not working(

type: entities
entities:
  - entity: sensor.nositel_local
    card_mod:
      style: |
        :host {
          color:
            {% if states(config.entity) | int <= input_number.target_temp_kuh %} 
              red
            {% elif states(config.entity) | int >= input_number.target_temp_kuh %}
              green
            {% endif %}
            ;
        }
states(config.entity) | int <= states('input_number.target_temp_kuh') | int
1 Like

Not working(
If I put “21” - it works
If I put states(‘input_number.target_temp_kuh states’) - not working
Now the states of input number is 21

Miss from my side, corrected above :grimacing:

1 Like

I’m trying to set the third IF value between -1 and +1 from the input number value, not working, can you help me?

type: entities
entities:
  - entity: sensor.nositel_local
    card_mod:
      style: |
        :host {
          color:
            {% if states(config.entity) | float < states('input_number.target_temp_kuh') | float -1 %} 
              blue
            {% elif states(config.entity) | float > states('input_number.target_temp_kuh') | float +1 %}
              red
            {% elif ((states(config.entity) | float > states('input_number.target_temp_kuh') | float -1) && (states(config.entity) | float < states('input_number.target_temp_kuh') | float +1)) %}
              green
            {% endif %}
            ;
        }

Try this for your third IF:

{% elif (states(config.entity) | float > states('input_number.target_temp_kuh') | float -1) and (states(config.entity) | float < states('input_number.target_temp_kuh') | float + 1 ) %}

With the risk of being hammered down by the gurus in the forum I think you should use and instead of && since that is used in javascript but Jinja is used in templating.

I also sorted out all your different () which were all over the place.

I strongly recommend to use Templating under development tools (which you should enable under settings) to test your templates. There it is easier to find problems. :slight_smile:

I made it simpler, I wrote

{% else %}

Thank you very much!

1 Like