Error with (working) template

Hello everybody,

I created a template so I can monitor my Delta T ( ΔT ). Simply said the difference of temperatures between two measuring points.
In my case this is the water-heating system in my floors.
My boiler has both outputs for supplied temperature and return temperature, so I created a template to calculate the difference between them.

  - platform: template
    sensors:
      delta_t:
        value_template: >
          {{ '%0.1f' | format(states('sensor.actual_supply_temperature') | float - 
                              states('sensor.return_temperature') | float) }}
        unit_of_measurement: '°C'
        friendly_name: Delta T

Now this works, but I always get these errors in my log:

Logger: homeassistant.helpers.event
Source: helpers/template.py:546
First occurred: 09:13:17 (1 occurrences)
Last logged: 09:13:17

Error while processing template: Template<template=({{ '%0.1f' | format(states('sensor.actual_supply_temperature') | float - states('sensor.return_temperature') | float) }}) renders=2>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1893, 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/template.py", line 544, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2164, in _render_with_context
    return template.render(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 936, 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 1896, in forgiving_float_filter
    raise_no_default("float", value)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1594, in raise_no_default
    raise ValueError(
ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ '%0.1f' | format(states('sensor.actual_supply_temperature') | float - 
                    states('sensor.return_temperature') | float) }}' 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 665, in async_render_to_info
    render_info._result = self.async_render(variables, strict=strict, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 546, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ '%0.1f' | format(states('sensor.actual_supply_temperature') | float - 
                    states('sensor.return_temperature') | float) }}' but no default was specified

and

Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:379
First occurred: 09:13:17 (1 occurrences)
Last logged: 09:13:17

TemplateError('ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ '%0.1f' | format(states('sensor.actual_supply_temperature') | float - states('sensor.return_temperature') | float) }}' but no default was specified') while processing template 'Template<template=({{ '%0.1f' | format(states('sensor.actual_supply_temperature') | float - states('sensor.return_temperature') | float) }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.delta_t'

These are the only red fault errors in my log and like to get rid of them.
I understand the above errors show me what is wrong, I just dont understand it, and my google-fu is failing me in this matter.

Thanks for the help!

You need to supply default values to your float filters for when your incoming sensor values cannot be converted: replace them with float(0).

Se also availability_template:

2 Likes

Lord almighty, that was fast.
I will try this out as soon as possible, and I thank you.