Sensor template throwing error

I get the error message below in the log. However, if I paste the template into Developer Tools/Template I get the expected result and no error. What am I doing incorrectly?

Logger: homeassistant.helpers.template
Source: helpers/template.py:1254
First occurred: 05:03:02 (510 occurrences)
Last logged: 09:26:23

Template warning: ‘float’ got invalid input ‘unknown’ when rendering template ‘blahblah’ but no default was specified. Currently ‘float’ will return ‘0’, however this template will fail to render in Home Assistant core 2022.1

But when I put the script into the Developer Tools/Template I get the following result with no error:

Result type: list
[
  5,
  5,
  5,
  5,
  5,
  5,
  5,
  5,
  5,
  5,
  5,
  5,
  5,
  5
]

The actual template is below

{% set day_trigger = states('input_number.day_trigger') | float %} 
{% set night_trigger= states('input_number.night_trigger') | float %} 
{% set day_baseline = states('input_number.day_baseline') | float %} 
{% set night_baseline = states('input_number.night_baseline') | float %} 
{% set twilight_baseline = states('input_number.twilight_baseline') | float %} 
{% set solar_trigger = states('input_number.solar_trigger') | float %} 
{% set solar_sensitivity = states('input_number.solar_sensitivity') | float %} 
{% set temp_sensitivity = states('input_number.temp_sensitivity') | float %} 
{% set temp_baseline = states('input_number.temp_baseline') | float %} 
{% set outdoor_temp = states.sensor.miles_home_outdoor_temperature.state | float %} 
{% set solar = states.sensor.miles_home_solar_percentage.state | float %} 
{% set elevation = states.sun.sun.attributes.elevation | float %} 
{% if elevation > day_trigger %} 
  {% set temp_offset = day_baseline %} 
{% elif elevation < night_trigger %} 
  {% set temp_offset = night_baseline %} 
{% else %} 
  {% set temp_offset = twilight_baseline %} 
{% endif %} 
{% if solar > solar_trigger %} 
  {% set temp_offset = temp_offset + solar_sensitivity*(100-solar)/(100-solar_trigger) %} 
{% else %} 
  {% set temp_offset = temp_offset + solar_sensitivity %} 
{% endif %} 
{% set temp_offset = temp_offset + temp_sensitivity * (temp_baseline - outdoor_temp ) %} 
{% set temp_offset = temp_offset | float | round(1) %} 
{% set temperatures = namespace(new = [] )%} 
{% if states('input_number.heating_on_off') == on %} 
  {% set num_thermostats = expand('group.tado_baseline') | list | count %} 
  {% for i in range(0,num_thermostats) %} 
    {% set temperatures.new = temperatures.new + [expand('group.tado_baseline')[i].state | float + temp_offset] %} 
  {% endfor %} 
  {% set num_thermostats = expand('group.tuya_baseline') | list | count %} 
  {% for i in range(0,num_thermostats) %} 
    {% set temperatures.new = temperatures.new + [expand('group.tado_baseline')[i].state | float + temp_offset] %} 
  {% endfor %} 
{% else %} 
  {% set num_thermostats = expand('group.tado_baseline') | list | count %} 
  {% for i in range(0,num_thermostats) %} 
    {% set temperatures.new = temperatures.new + [5.0] %} 
  {% endfor %} 
  {% set num_thermostats = expand('group.tuya_baseline') | list | count %} 
  {% for i in range(0,num_thermostats) %} 
    {% set temperatures.new = temperatures.new + [5.0] %} 
  {% endfor %} 
{% endif %} 
{{temperatures.new}}

It’s a warning, not an error message. You should add a default value when using the float filter in your templates, for example float(0).
The warning message is simply not shown when using the developer tools.

1 Like

Ah, thanks.

these warnings are frustrating
I retrofitted float(0) below and default 0 value in the as_timestamp function

'{{ as_timestamp(now(),0)|float(0)-as_timestamp(states.sensor.ha_uptime.state,0)|float(0) }}'

Yet I still get the WARNING, implying I will get errors in future HA upgrades

2021-11-11 00:38:00 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'float' got invalid input 'None' when retamp_local(0))|float|round(0)-as_timestamp(states.sensor.ha_uptime.state)|float(0)|round(0)) }}

{{ as_timestamp(now(),0)|float(0)-as_timestamp(states.sensor.ha_uptime.state,0)|float(0) }}' but no default was specified. Currently will fail to render in Home Assistant core 2022.1
  • List item

That template doesn’t even need a float filter.

"{{ now().timestamp() - as_timestamp(states('sensor.ha_uptime'), 0) }}"

ok thanks I can remove it in this instance, but I don’t understand why adding |float(0)
is giving me warning no default was specified,

isn’t the (0) a default?

The error message you posted isn’t referring to the template you posted.

Look carefully at what is in the error message

retamp_local(0))|float|round(0)

sorry i had pasted the earlier log 1st, while talking about the 2nd part of the log
this is what i had 1st

"{{ ((as_timestamp(now()|timestamp_local(0))|float|round(0)-as_timestamp(states.sensor.ha_uptime.state)|float|round(0))) }}"' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2022.1
2021-11-10 22:49:47 WARNING (Thread-12) [homeassistant.helpers.template] Template warning: 'float' got invalid input 'None' when rendering template '{{ (as_timestamp(now()|timestamp_local(0))|float|round(0)-as_timestamp(states.sensor.ha_uptime.state)|float(0)|round(0)) }}

I attempted to fix it by adding enclosed zero float(0)

then got the WARNING thrown again even with float(0)


{{ as_timestamp(now(),0)|float(0)-as_timestamp(states.sensor.ha_uptime.state,0)|float(0) }}' but no default was specified. Currently 'as_timestamp' will return 'None', however this template will fail to render in Home Assistant core 2022.1
2021-11-11 00:38:00 WARNING (MainThread) [homeassistant.helpers.template] Template warning: 'float' got invalid input 'None' when rendering template '{{ (as_timestamp(now()|timestamp_local(0))|float|round(0)-as_timestamp(states.sensor.ha_uptime.state)|float(0)|round(0)) }}

Well I’m also sorry because I can no longer be certain anything you post is correct. Even your most recent post contains a float without a default: timestamp_local(0))|float|round(0)

Good luck.

The template it’s trying to render still contains an un-defaulted float:

{{ (as_timestamp(now()|timestamp_local(0))|float|round(0)-as_timestamp(states.sensor.ha_uptime.state)|float(0)|round(0)) }}
---------------------------------------------^

Either you’ve missed one, or it hasn’t correctly loaded your changes.

guilty as charged I missed one, need new glasses!.