Errors in logs about frontend code "unknown" passed to float that have already been fixed! HA sees stale UI code?

So I saw these types of errors in the logs.

2023-12-03 11:51:18.726 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=({% from 'utils.jinja' import abbreviated_relative_time %}
{% set bl = states('sensor.xxx_battery_level')|float|round %}
{% if states('sensor.xxx_battery_state')|lower != 'not charging' %}🔌{%-endif-%}
{% if bl <= 29 %}{{bl}}%{% else %}{{bl}}%{% endif %}) renders=2>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/", line 1925, in forgiving_float_filter
    return float(value)
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/", line 568, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)


I fixed the code by adding a default for the float call as such (I’ve used this way to default in my dashboards often and it always works)

{% set bl = states('sensor.xxx_battery_level')|float(-99)|round %}

But even after restarting the entire machine, I still see the same error. It’s like HA is seeing the old version of the code. I’m completely stumped. I checked the raw frontend code and I only see the new code.

Any ideas?

What do you see if this template is placed to Dev tools → Template?

I usually use “float(default=xxxxx)”, may be it is same.

Thank you very much.
I tried that and float(-99) works fine.
More importantly, what worries me is that the error in the logs still reflects the OLD code.
If you notice it still says
{% set bl = states('sensor.xxx_battery_level')|float|round %}
whereas the code has been changed to
{% set bl = states('sensor.xxx_battery_level')|float(-99)|round %}
I’ve verified that by using the raw editor on the dashboard and I clearly see the new code.
I also tried searching for the textual string taken from the error logs and there are no matches on any dashboards.

So it almost seems like Home Assistant might be in some weird stuck state. Like maybe its database is corrupt or something (though it cannot be the case exactly because I do see the new code on the dashboard which is also loaded from the DB I’m sure. Perhaps it’s different tables in the database, I really don’t know HA’s data model at all).

Is there some cache internal to HA that could be corrupt that I can refresh? Note that this wouldn’t be a front-end app cache since the errors occur in the logs on the server side (I assume, unless the client sends back any errors from the front end back to the backend and they are logged there?)

There are two parts in Log:
– short (upper)
– full
I find the short part confusing - the last error displayed may not be a real one.
Suggest to always check the full log.

Woah I think I was right.
In the process of explaining to you the issue I had this idea that maybe it IS one of the 4-5 front end app clients we have in the apartment (phones, web ones on PCs and one on an old android device which is the GE kitchen hub).

I went through each of those and cleared the app cache (not all data as that would have logged me out).

Normally don’t need to do that but I think the culprit was the old Kitchen Hub device.

This also likely indicates that the backend does get data from front-end clients about errors and sends them to the backend logs. It would be cool if someone could confirm but either way this solved my problem.

Thanks again for engaging me on this post on a Sunday! I see you active on so many threads! You are a star! I won’t mark your response as the answer not to be misleading to others but I do have to thank you because without your replies I wouldn’t have been forced to think through the problem in this way!

1 Like

Assume I have a card supporting jinja templates.
Also could be any card with card-mod with jinja templates.
Assume some template contains a code like “convert unknown/none/unavailable to float w/o a default value”. Then you will see an error in Log when you open a view with this card.

And here is my guess:
You may have this error already fixed in yaml - but if a browser’s page is not refreshed, then you will keep seeing this error in Log.

It could be similarly for other client: if this client is not “refreshed” (not sure that a “frontend cache” should be purged - probably a simple page refresh is sufficient) - then this client produces these errors in Log.
But - what if a client is not active, i.e. a phone just lays on a table? A companion app could be active but none view is opened - so no errors are supposed to appear.

1 Like