In case it helps, the float
filter takes an option parameter which is the value it should return if it can’t interpret its input. So, e.g.,
{{ states('sensor.does_not_exist')|float(1) }}
Would result in 1. This is because the states()
function returns 'unknown'
, and that cannot be interpreted as a number, so float(1)
returns the default value passed in, which in this case is 1. Same would happen for 'unavailable'
.