Error in template.py

In the log it gives me the following error code, at first I see that the error is in the name of the list “compras” not “comprasa” but I check all the cards and codes and it is correctly placed

Registrador: homeassistant.helpers.event
Fuente: helpers/template.py:587
Ocurrió por primera vez: 17:49:56 (27 ocurrencias)
Último inicio de sesión: 20:27:24

Error while processing template: Template<template=({% if states('todo.google_keep_lista_de_comprasa') | int >= 15 %} ha-state-icon { animation: beat 2s ease-out infinite both; transform-origin: 50% 50%; } @keyframes beat { 0% { transform: scale(1); } 10% { transform: scale(1.2); } 17% { transform: scale(1.05); } 33% { transform: scale(1.30); } 60% { transform: scale(1); } } ha-card { --primary-text-color: #ffffff; --secondary-text-color: #ffff00; background: linear-gradient( rgba(238, 82, 79, 1), rgba(181, 42, 39, 1) ) }}'); } {% endif %}) renders=70>
Error while processing template: Template<template=({% if states('todo.google_keep_lista_de_comprasa') | int >= 15 %} ha-state-icon { animation: beat 2s ease-out infinite both; transform-origin: 50% 50%; } @keyframes beat { 0% { transform: scale(1); } 10% { transform: scale(1.2); } 17% { transform: scale(1.05); } 33% { transform: scale(1.30); } 60% { transform: scale(1); } } ha-card { --primary-text-color: #ffffff; --secondary-text-color: #ffff00; background: linear-gradient( rgba(238, 82, 79, 1), rgba(181, 42, 39, 1) ) }}'); } {% endif %}) renders=74>
Error while processing template: Template<template=({% if states('todo.google_keep_lista_de_comprasa') | int >= 15 %} ha-state-icon { animation: beat 2s ease-out infinite both; transform-origin: 50% 50%; } @keyframes beat { 0% { transform: scale(1); } 10% { transform: scale(1.2); } 17% { transform: scale(1.05); } 33% { transform: scale(1.30); } 60% { transform: scale(1); } } ha-card { --primary-text-color: #ffffff; --secondary-text-color: #ffff00; background: linear-gradient( rgba(238, 82, 79, 1), rgba(181, 42, 39, 1) ) }}'); } {% endif %}) renders=78>
Error while processing template: Template<template=({% if states('todo.google_keep_lista_de_comprasa') | int >= 15 %} ha-state-icon { animation: beat 2s ease-out infinite both; transform-origin: 50% 50%; } @keyframes beat { 0% { transform: scale(1); } 10% { transform: scale(1.2); } 17% { transform: scale(1.05); } 33% { transform: scale(1.30); } 60% { transform: scale(1); } } ha-card { --primary-text-color: #ffffff; --secondary-text-color: #ffff00; background: linear-gradient( rgba(238, 82, 79, 1), rgba(181, 42, 39, 1) ) }}'); } {% endif %}) renders=82>
Error while processing template: Template<template=({% if states('todo.google_keep_lista_de_comprasa') | int >= 15 %} ha-state-icon { animation: beat 2s ease-out infinite both; transform-origin: 50% 50%; } @keyframes beat { 0% { transform: scale(1); } 10% { transform: scale(1.2); } 17% { transform: scale(1.05); } 33% { transform: scale(1.30); } 60% { transform: scale(1); } } ha-card { --primary-text-color: #ffffff; --secondary-text-color: #ffff00; background: linear-gradient( rgba(238, 82, 79, 1), rgba(181, 42, 39, 1) ) }}'); } {% endif %}) renders=86>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 585, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2600, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2243, in forgiving_int_filter
    raise_no_default("int", value)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1849, in raise_no_default
    raise ValueError(
ValueError: Template error: int got invalid input 'unknown' when rendering template '{% if states('todo.google_keep_lista_de_comprasa') | int >= 15 %}
ha-state-icon {
  animation: beat 2s ease-out infinite both;
  transform-origin: 50% 50%;
}  
@keyframes beat {
  0% { transform: scale(1); }
  10% { transform: scale(1.2); }
  17% { transform: scale(1.05); }
  33% { transform: scale(1.30); }
  60% { transform: scale(1); }
}    
ha-card {
  --primary-text-color: #ffffff;
  --secondary-text-color: #ffff00;
  background: linear-gradient( rgba(238, 82, 79, 1), rgba(181, 42, 39, 1) ) }}');
}
{% endif %}' but no default was specified

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 713, in async_render_to_info
    render_info._result = self.async_render(
                          ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 587, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: int got invalid input 'unknown' when rendering template '{% if states('todo.google_keep_lista_de_comprasa') | int >= 15 %}
ha-state-icon {
  animation: beat 2s ease-out infinite both;
  transform-origin: 50% 50%;
}  
@keyframes beat {
  0% { transform: scale(1); }
  10% { transform: scale(1.2); }
  17% { transform: scale(1.05); }
  33% { transform: scale(1.30); }
  60% { transform: scale(1); }
}    
ha-card {
  --primary-text-color: #ffffff;
  --secondary-text-color: #ffff00;
  background: linear-gradient( rgba(238, 82, 79, 1), rgba(181, 42, 39, 1) ) }}');
}
{% endif %}' but no default was specified

Thanks in advance

You need to supply defaults for your |int filters for the situation when the state is unable to be converted to an integer (e.g. when unknown or unavailable). e.g. change this:

{% if states('todo.google_keep_lista_de_comprasa') | int >= 15 %} 

To this:

{% if states('todo.google_keep_lista_de_comprasa') | int(0) >= 15 %} 

Or to a number larger than 15 in the brackets if you want the if to be true when the state is unavailable.

Alternatively add a check to see if the state is available and deal with it that way {% has_value('todo.google_keep_lista_de_comprasa') %}

1 Like

thanks very much!

1 Like