Specify default value for | float

The following template filters and functions will now log a warning instead of silently returning the input if the input is invalid and no default value is specified:

float

How is this done best ?

This seems to work :


{## Imitate available variables: ##}
{% set my_test_json = {
  "temperature": 25,
  "unit": "°C"
} %}

The temperature is {{ my_test_json.temperature | default(0) | float }} {{ my_test_json.unit }}.
The temperature is {{ my_test_json.temperature | float | default(0) }} {{ my_test_json.unit }}.

If this is a question about the 2021.10 beta it is best asked in the #beta channel on discord.

But this is the way:


The temperature is {{ my_test_json.temperature | float(0) }} {{ my_test_json.unit }}
1 Like