[solved] Template error: float got invalid input 'None'

Hi,

regularly this message appears in the logs:

ValueError: Template error: float got invalid input 'None' when rendering template '{{ state_attr('climate.trv_bathroom','current_temperature') | float}}' but no default was specified

I understand the general issue with it and it appears to be fixable by changing the template code to something like:

{{ state_attr('climate.trv_bathroom','current_temperature') | round(1, default=18) }}

What this does is setting the default value of the current_temperature attribute to 18 instead of ‘None’. But in that case, where the value should be the current_temperature my provided default value would almost always be wrong. Either to hot or to cold.

Is there a better way to handle that kind of situation? I mean, why is the attribute ‘None’ in the first place? Can the root cause be fixed somehow?

Cheers!

Make an availability template.

{{ state_attr('climate.trv_bathroom','current_temperature') | is_number }}

then you don’t need to specify a default. But it will be unavailable.

Thank you, this was exactly what I was missing.

HI,
I think I have something similar, but can’t get it to work:

  • sensor:
template:
      - name: "Temperatur Küche"
        unique_id: "template_sensor_temperatur_kuche"
        state_class: measurement
        device_class: temperature
        unit_of_measurement: '°C'
        state: "{{ float(state_attr('climate.kuche', 'current_temperature')) | round(1) }}"

I added

state: "{{ float(state_attr('climate.kuche', 'current_temperature') | is_number ) | round(1) }}"

But since than, the graphs are at “1” and not at the regular celsios number. I assume the reason is, that “is_numer” → true is convertet to “1”.

I would like to avoind the warnings in the logfile, as I know that the devices are WLAN, and sometimes loose a connect, which I don’t care, as it “happens” with WLAN.

I have no idea, how to make this sure.

thanks
Juergen

You’re using is_number wrong. You need a separate availability template using is_number

Hi @petro,
I read Template - Home Assistant but did not get what an “availability template” is.

template:
      - name: "Temperatur Küche"
        unique_id: "template_sensor_temperatur_kuche"
        state_class: measurement
        device_class: temperature
        unit_of_measurement: '°C'
        state: "{{ float(state_attr('climate.kuche', 'current_temperature')) | is_number }}"

but still it detects only “0/1”. So it seems I have to live with the errors in the log. I do not understand, why I cannot “say” somewhere: This device, is “flaky”, so don’t write a log, if you cannot read the sensors of this device, but please write throw an error, if on this device I do want to change something, and it is “gone”, but before “try” 5 times on your own.
As this device has 5 sensor data I think, this would make configuration easier. Anything to read, why this is done different, and what I did not get?

thanks
Juergen

Documentation on the field:

Example using it:

Hi @petro,
thanks again very much for you help. I really did not get this on that page.

thanks
Juergen

Hi Petro; I am trying to clear up my log errors, I can’t seem to crack this one. I have implemented a number of power sensors per room which add the current power, total power and yesterdays power, I have implemented the “is_number” as a condition and it seems to look okay using the development module however I still get an error. The error seems to indicate that one of the sensors is unavailable, however, when I past the sensor template into the development module I receive the value expected? Any help would be most appreciated.
as a sample the error is :

  • TemplateError(‘ValueError: Template error: float got invalid input ‘unavailable’ when rendering template ‘{{ (states(‘sensor.pool_blower_energy_yesterday’)|float + states(‘sensor.pool_light_energy_yesterday’)|float + states(‘sensor.pool_pump_energy_yesterday’)|float)|round(3) }}’ but no default was specified’) while processing template ‘Template<template=({{ (states(‘sensor.pool_blower_energy_yesterday’)|float + states(‘sensor.pool_light_energy_yesterday’)|float + states(‘sensor.pool_pump_energy_yesterday’)|float)|round(3) }}) renders=94>’ for attribute ‘_attr_native_value’ in entity ‘sensor.pool_energy_total_yesterday’
    The template is:
- sensor:
    - name: "Pool ENERGY Total Yesterday"
      unique_id: pool_energy_total_Yesterday
      unit_of_measurement: kwh
      state: >-
        {% if is_number('sensor.pool_blower_energy_yesterday')|float +
        states('sensor.pool_light_energy_yesterday')|float + 
        states('sensor.pool_pump_energy_yesterday')|float -%}

        {{ (states('sensor.pool_blower_energy_yesterday')|float +
        states('sensor.pool_light_energy_yesterday')|float + 
        states('sensor.pool_pump_energy_yesterday')|float)|round(3) }}
        {%- else -%}
        0
        {%- endif %}