I’ve been trying to sort out template errors on startup where a lot of sensors are unknown/unavailable for obvious reasons.
A majority seem to be lovelace (or Mushroom where you can template icon colours etc.)
Here is an example error :
Error while processing template: Template<template=({% if (states('sensor.gas_usage_hourly')|is_number and states('sensor.hot_water_hourly'))| is_number %} {{ (states('sensor.gas_usage_hourly') + states('sensor.hot_water_hourly'))| round(2) }} kWh {% else %} 0{% endif %) renders=2>
What’s really odd is I changed that line to say or instead of and but it continues to insist it’s the old version, but that aside - here’s the code. Am I doing something wrong? (There are loads more but this seems to be the same issue as the others)
That template is flawed in multiple ways: you must convert sensor states (which are always strings) to numbers before doing arithmetic on them.
{% if (states('sensor.gas_usage_hourly')|is_number or states('sensor.hot_water_hourly'))| is_number %}
------^---------brackets don't match---------------------------------------------------^
Ignoring the syntactically-correct but functionally-wrong brackets, you’re checking if either sensor can be interpreted as a number, then trying to add them. If only one is a number, this will fail.
Your file search might not include all of the dashboard files. Try editing the dashboard, then three dots / raw configuration editor and search through your Lovelace YAML.
You may also need to look at any UI-created Helpers.
Right, thanks for the float(0) hint. I was using int(0) for most other errors. Fixed everything finally. It’s very annoying that local startup errors with anything in developer tools “template”. I had to go around all my devices and clear everything down
Still have some “floaters” that don’t exist in my actual config. Anyone got any idea where HA looks for anything that is in the developer tools template editor? It is obviously stored somewhere but I can’t find it
Home Assistant was built with a single-page application (SPA) architecture that pushes the work of rendering the web frontend on the client browser. As of Dec 2024, Home Assistant is missing an automatic SPA update mechanism. Meaning, failing to refresh every open browser tab’s frontend code after a dashboard updates leads to stale client code generating difficult to troubleshoot errors in server logs.