Phantom Template Error

Hello -
Hoping someone can help me. I have an annoying log entry that doesn’t seem to be causing any issues but I can’t track it down. It’s referencing a device that’s been off the system for a number of weeks. I recently finally moved off of Vera and removed the integration. (It left a few devices behind that I can’t remove but that’s a different problem and this device doesn’t show up in Entities).

I have no templates that I know of. No dashboards calling this. Any idea where I can look?

Logger: homeassistant.helpers.event
Source: helpers/template.py:645
First occurred: 10:07:49 PM (3 occurrences)
Last logged: 10:52:25 PM

Error while processing template: Template<template=({{ states('sensor.office_temperature_398')| round(1)}}°F) renders=2>
Error while processing template: Template<template=({{ states('sensor.office_temperature_398')| round(1)}}°F) renders=6>
Error while processing template: Template<template=({{ states('sensor.office_temperature_398')| round(1)}}°F) renders=10>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1940, in forgiving_round
    value = round(float(value), precision)
                  ~~~~~^^^^^^^
ValueError: could not convert string to float: 'unknown'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 643, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2745, in _render_with_context
    return template.render(**kwargs)
           ~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/jinja2/environment.py", line 1295, in render
    self.environment.handle_exception()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/jinja2/environment.py", line 942, 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 1945, in forgiving_round
    raise_no_default("round", value)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1921, in raise_no_default
    raise ValueError(
    ...<2 lines>...
    )
ValueError: Template error: round got invalid input 'unknown' when rendering template '{{ states('sensor.office_temperature_398')| round(1)}}°F' 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 760, in async_render_to_info
    render_info._result = self.async_render(  # noqa: SLF001
                          ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
        variables, strict=strict, log_fn=log_fn, **kwargs
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 645, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: round got invalid input 'unknown' when rendering template '{{ states('sensor.office_temperature_398')| round(1)}}°F' but no default was specified

State values are strings, you need to convert them to numbers before you can round them.

Also your temperature sensor had a momentary unknown state:

So a default needs to be provided in this case.

e.g. change this

{{ states('sensor.office_temperature_398')| round(1)}}

to

{{ states('sensor.office_temperature_398')|float(-999)|round(1) }}

Likewise for the other two templates.

So if your sensor becomes unknown again the value will be replaced with -999. You can choose whatever value you want to alert you the sensor is unavailable.

Agreed. The problem is (was) I couldn’t even find where this was set. Long day. I found it in an old unused dashboard. The entity has long been removed.

Thanks for the help and sorry to waste your time. Helpful answer, assuming I knew where it was! :slight_smile: