Errors in template sensor

Hi, I’m struggling with two errors of the following template sensor:

differenz_humidity_garage:
        friendly_name: "Differenz Luftfeuchte"
        unit_of_measurement: "g/m³"
        device_class: humidity
        icon_template: mdi:water
        value_template: "{{ ((states('sensor.garage_absolute_humidity') | float) - (states('sensor.aussensensor_absolute_humidity') | float))|round(2) }}"

HA is giving back these two errors:

TemplateError(‘ValueError: Template error: float got invalid input ‘unknown’ when rendering template ‘{{ ((states(‘sensor.garage_absolute_humidity’) | float) - (states(‘sensor.aussensensor_absolute_humidity’) | float))|round(2) }}’ but no default was specified’) while processing template ‘Template<template=({{ ((states(‘sensor.garage_absolute_humidity’) | float) - (states(‘sensor.aussensensor_absolute_humidity’) | float))|round(2) }}) renders=4>’ for attribute ‘_attr_native_value’ in entity ‘sensor.differenz_humidity_garage’

and

Error while processing template: Template<template=({{ ((states(‘sensor.garage_absolute_humidity’) | float) - (states(‘sensor.aussensensor_absolute_humidity’) | float))|round(2) }}) renders=2>

Any hint would be appreciated!

There’s the answer.

Change float to float(0) (or whatever you prefer).

differenz_humidity_garage:
        friendly_name: "Differenz Luftfeuchte"
        unit_of_measurement: "g/m³"
        device_class: humidity
        icon_template: mdi:water
        value_template: "{{ ((states('sensor.garage_absolute_humidity') | float(0)) - (states('sensor.aussensensor_absolute_humidity') | float(0)))|round(2) }}"

this way?

1 Like

Yes.