TemplateError ('ValueError: Template error: int got invalid input

Hello,

I’m getting error messages from the template engine.

The template is used to find out if the garage door is open/close.
The template reads the angle of the door as a numeric value.

The automation that uses this sensor is working fine. The template gives a good result in the template editor. but the logs are keeping giving errors.

What am I missing here?


Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:173
Integration: Template (documentation, issues)
First occurred: 11:22:36 AM (9 occurrences)
Last logged: 12:36:16 PM

TemplateError('ValueError: Template error: int got invalid input 'unknown' when rendering template '{% set positie = states('sensor.zb_kanteldeur_rechts_angle_y')| int %} {% if positie | int >= -50 %} mdi:garage-open-variant {% elif positie | int < -50 %} mdi:garage-variant {% endif %}' but no default was specified') while processing template 'Template("{% set positie = states('sensor.zb_kanteldeur_rechts_angle_y')| int %} {% if positie | int >= -50 %} mdi:garage-open-variant {% elif positie | int < -50 %} mdi:garage-variant {% endif %}")' for attribute '_attr_icon' in entity 'sensor.kanteldeur_positie_fiat'
TemplateError('ValueError: Template error: float got invalid input 'unknown' when rendering template '{% set positie = states('sensor.zb_kanteldeur_links_angle_y') %} {% if positie | float >= -30 %} Open {% elif positie | float < -30 %} Closed {% endif %}' but no default was specified') while processing template 'Template("{% set positie = states('sensor.zb_kanteldeur_links_angle_y') %} {% if positie | float >= -30 %} Open {% elif positie | float < -30 %} Closed {% endif %}")' for attribute '_attr_native_value' in entity 'sensor.kanteldeur_positie_tesla'
TemplateError('ValueError: Template error: float got invalid input 'unknown' when rendering template '{% set positie = states('sensor.zb_kanteldeur_links_angle_y') %} {% if positie | float >= -30 %} mdi:garage-open-variant {% elif positie | float < -30 %} mdi:garage-variant {% endif %}' but no default was specified') while processing template 'Template("{% set positie = states('sensor.zb_kanteldeur_links_angle_y') %} {% if positie | float >= -30 %} mdi:garage-open-variant {% elif positie | float < -30 %} mdi:garage-variant {% endif %}")' for attribute '_attr_icon' in entity 'sensor.kanteldeur_positie_tesla'
TemplateError('ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ states('sensor.voerhok_th_am2301_temperature')|float < 0 }}' but no default was specified') while processing template 'Template("{{ states('sensor.voerhok_th_am2301_temperature')|float < 0 }}")' for attribute '_state' in entity 'binary_sensor.voerhok_onder_nul'
TemplateError('ValueError: Template error: float got invalid input 'unavailable' when rendering template '{{ states('sensor.voerhok_th_am2301_temperature')|float < 0 }}' but no default was specified') while processing template 'Template("{{ states('sensor.voerhok_th_am2301_temperature')|float < 0 }}")' for attribute '_state' in entity 'binary_sensor.voerhok_onder_nul'

This is my template config

- sensors:
    kanteldeur_positie:
      friendly_name: Kanteldeur positie
      value_template: >-
        {% set positie = states('sensor.zb_kanteldeur_angle_y')| int %}
        {% if positie | int <= 70 %}
          Open
        {% elif positie | int > 70 %}
          Closed
        {% endif %}
      icon_template: >-
        {% set positie = states('sensor.zb_kanteldeur_angle_y')| int %}
        {% if positie | int <= 70 %}
          mdi:garage-open-variant
        {% elif positie | int > 70 %}
          mdi:garage-variant
        {% endif %}
# de sensor van autogarage Panda heeft sensor R (dus van binnenuit gezien)
    kanteldeur_positie_fiat:
      friendly_name: Kanteldeur positie Fiat
      value_template: >-
        {% set positie = states('sensor.zb_kanteldeur_rechts_angle_y')| int %}
        {% if positie | int >= -50 %}
          Open
        {% elif positie | int < -50 %}
          Closed
        {% endif %}
      icon_template: >-
        {% set positie = states('sensor.zb_kanteldeur_rechts_angle_y')| int %}
        {% if positie | int >= -50 %}
          mdi:garage-open-variant
        {% elif positie | int < -50 %}
          mdi:garage-variant
        {% endif %}

You need to supply defaults for your |int filters. You don’t need to use the filter once you have set the value of the variable.

- sensors:
    kanteldeur_positie:
      friendly_name: Kanteldeur positie
      value_template: >-
        {% set positie = states('sensor.zb_kanteldeur_angle_y')| int(0) %}
        {% if positie <= 70 %}
          Open
        {% elif positie > 70 %}
          Closed
        {% endif %}
      icon_template: >-
        {% set positie = states('sensor.zb_kanteldeur_angle_y')| int(0) %}
        {% if positie <= 70 %}
          mdi:garage-open-variant
        {% elif positie > 70 %}
          mdi:garage-variant
        {% endif %}
      availability: "{{ states('sensor.zb_kanteldeur_angle_y')|is_number }}"

# de sensor van autogarage Panda heeft sensor R (dus van binnenuit gezien)
    kanteldeur_positie_fiat:
      friendly_name: Kanteldeur positie Fiat
      value_template: >-
        {% set positie = states('sensor.zb_kanteldeur_rechts_angle_y')| int(0) %}
        {% if positie | int >= -50 %}
          Open
        {% elif positie | int < -50 %}
          Closed
        {% endif %}
      icon_template: >-
        {% set positie = states('sensor.zb_kanteldeur_rechts_angle_y')| int(0) %}
        {% if positie >= -50 %}
          mdi:garage-open-variant
        {% elif positie < -50 %}
          mdi:garage-variant
        {% endif %}
      availability: "{{ states('sensor.zb_kanteldeur_rechts_angle_y')|is_number }}"
1 Like