Everytime i start HA i get the following errors:
> 2024-11-06 11:42:55.531 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=({% set bl = states('sensor.oppo_battery_level') | int %}
> {% if bl < 10 %} mdi:battery-outline
> {% elif bl < 20 %} mdi:battery-10
> {% elif bl < 30 %} mdi:battery-20
> {% elif bl < 40 %} mdi:battery-30
> {% elif bl < 50 %} mdi:battery-40
> {% elif bl < 60 %} mdi:battery-50
> {% elif bl < 70 %} mdi:battery-60
> {% elif bl < 80 %} mdi:battery-70
> {% elif bl < 90 %} mdi:battery-80
> {% elif bl < 100 %} mdi:battery-90
> {% elif bl == 100 %} mdi:battery
> {% else %} mdi:battery-unknown
> {% endif %}) renders=4>
> Traceback (most recent call last):
> File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 632, in async_render
> render_result = _render_with_context(self.template, compiled, **kwargs)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2729, 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 2367, in forgiving_int_filter
> raise_no_default("int", value)
> File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1905, in raise_no_default
> raise ValueError(
> ValueError: Template error: int got invalid input 'unknown' when rendering template '{% set bl = states('sensor.oppo_battery_level') | int %}
> {% if bl < 10 %} mdi:battery-outline
> {% elif bl < 20 %} mdi:battery-10
> {% elif bl < 30 %} mdi:battery-20
> {% elif bl < 40 %} mdi:battery-30
> {% elif bl < 50 %} mdi:battery-40
> {% elif bl < 60 %} mdi:battery-50
> {% elif bl < 70 %} mdi:battery-60
> {% elif bl < 80 %} mdi:battery-70
> {% elif bl < 90 %} mdi:battery-80
> {% elif bl < 100 %} mdi:battery-90
> {% elif bl == 100 %} mdi:battery
> {% else %} mdi:battery-unknown
> {% 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 749, in async_render_to_info
> render_info._result = self.async_render( # noqa: SLF001
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 634, in async_render
> raise TemplateError(err) from err
> homeassistant.exceptions.TemplateError: ValueError: Template error: int got invalid input 'unknown' when rendering template '{% set bl = states('sensor.oppo_battery_level') | int %}
> {% if bl < 10 %} mdi:battery-outline
> {% elif bl < 20 %} mdi:battery-10
> {% elif bl < 30 %} mdi:battery-20
> {% elif bl < 40 %} mdi:battery-30
> {% elif bl < 50 %} mdi:battery-40
> {% elif bl < 60 %} mdi:battery-50
> {% elif bl < 70 %} mdi:battery-60
> {% elif bl < 80 %} mdi:battery-70
> {% elif bl < 90 %} mdi:battery-80
> {% elif bl < 100 %} mdi:battery-90
> {% elif bl == 100 %} mdi:battery
> {% else %} mdi:battery-unknown
> {% endif %}' but no default was specified
The template i am using is this:
> type: custom:mushroom-template-card
> entity: sensor.oppo_battery_level
> layout: vertical
> icon: |2
> {% set bl = states('sensor.oppo_battery_level') | int %}
> {% if bl < 10 %} mdi:battery-outline
> {% elif bl < 20 %} mdi:battery-10
> {% elif bl < 30 %} mdi:battery-20
> {% elif bl < 40 %} mdi:battery-30
> {% elif bl < 50 %} mdi:battery-40
> {% elif bl < 60 %} mdi:battery-50
> {% elif bl < 70 %} mdi:battery-60
> {% elif bl < 80 %} mdi:battery-70
> {% elif bl < 90 %} mdi:battery-80
> {% elif bl < 100 %} mdi:battery-90
> {% elif bl == 100 %} mdi:battery
> {% else %} mdi:battery-unknown
> {% endif %}
> icon_color: |2-
> {% set bl = states('sensor.oppo_battery_level') | int %}
> {% if bl < 10 %} #cc0c16
> {% elif bl < 20 %} #e61e28
> {% elif bl < 30 %} #e3464e
> {% elif bl < 40 %} orange
> {% elif bl < 50 %} #f0b93a
> {% elif bl < 60 %} #f3f56c
> {% elif bl < 70 %} #f2f536
> {% elif bl < 80 %} #69f095
> {% elif bl < 90 %} #2ee669
> {% elif bl < 100 %} #05ad3b
> {% elif bl == 100 %} #03872d
> {% else %} grey
> {% endif %}
Where i am wrong?