Issue with template: No default was specified. Currently 'int' will return 0

Hi all,
I would like to ask you what is wrong with my template. It is actually working but I am having warnings in LOGs:

Template warning: 'int' got invalid input 'unknown' when rendering template ':host { color: {% if states(config.entity) | int <= 300 %} green {% elif states(config.entity) | int <= 1000 %} greenyellow {% elif states(config.entity) | int <= 3000 %} yellow {% elif states(config.entity) | int <= 10000 %} orange {% elif states(config.entity) | int <= 25000 %} red {% endif %} ; }' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1
type: entities
entities:
  - entity: sensor.air_quality_sensor_voc
    card_mod:
      style: |
        :host {
          color:
            {% if states(config.entity) | int <= 300 %} 
              green
            {% elif states(config.entity) | int <= 1000 %}
              greenyellow
            {% elif states(config.entity) | int <= 3000 %}
              yellow
            {% elif states(config.entity) | int <= 10000 %}
              orange
            {% elif states(config.entity) | int <= 25000 %}
              red
            {% endif %}
            ;
        }
  - entity: sensor.air_quality_sensor_humidity
    name: Humidity Living room
  - entity: sensor.air_quality_sensor_temperature
    name: Temperature Living room
  - entity: sensor.air_quality_sensor_air_quality
    name: Air quality
state_color: false
show_header_toggle: true
footer:
  type: graph
  entity: sensor.air_quality_sensor_voc
  hours_to_show: 24
  detail: 2
title: Senzor kvality ovzduší

Thank you

1 Like

You havn’t supplied default values for your int filters.

no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1

See this post for help:

thanks for quick reply. The code is actually just copied from somewhere in this forum.
I have checked the help page but I do not understand it. Could you please help me with proper syntax?
Why I need default value? In my case default value would be green color?

Thank you

Then do this:

type: entities
entities:
  - entity: sensor.air_quality_sensor_voc
    card_mod:
      style: |
        :host {
          color:
            {% if states(config.entity) | int(0) <= 300 %} 
              green
            {% elif states(config.entity) | int(0) <= 1000 %}
              greenyellow
            {% elif states(config.entity) | int(0) <= 3000 %}
              yellow
            {% elif states(config.entity) | int(0) <= 10000 %}
              orange
            {% elif states(config.entity) | int(0) <= 25000 %}
              red
            {% endif %}
            ;
        }
1 Like

Replace | int by | int(0)

Because the sensor’s state value can be non-numeric.

2 Likes

thanks a lot for help!

2 Likes