Hi all,
this is a follow-up to GitHub issue #93386, which was closed in 2023 with the statement that template sensors with numeric expectation should return either a number or Python None
.
While this makes sense in theory, it unfortunately doesn’t always work in practice – even with correct templates.
Problem summary
In recent HA versions (confirmed 2025.6.x), using {{ none }}
in a template sensor with unit_of_measurement
or device_class
still leads to this error:
ValueError: could not convert string to float: 'None'
This happens because internally, {{ none }}
sometimes gets converted to the string 'None'
, not Python NoneType
, even though the template syntax is 100% correct.
Real-world impact
This breaks many use cases:
- optional numeric sensors (e.g. finance, energy, ratios)
- fallback logic based on availability of source data
- robust template-based analytics
Returning 0
instead is not acceptable in most cases (e.g. price or valuation calculations), and removing the unit altogether is not an option either.
Current workaround (not ideal):
{% if valid %}
{{ value }}
{% endif %}
→ This avoids the error but suppresses the explicit fallback (none
).
→ The sensor stays in unknown
, but unintentionally.
Proposed solution
Home Assistant should:
- Ensure that Jinja
{{ none }}
is always treated as PythonNone
, not as the string'None'
, even in numeric sensors withunit_of_measurement
. - Apply stricter internal typing where needed (e.g. use
is None
checks instead of loosestr()
coercion). - Optionally: support an explicit mode like
strict_numeric: true
in template sensors to enforce clear numeric output (number orNoneType
, no strings).
Question
Could the original GitHub issue be revisited or re-opened?
Or should we start a new issue with a formal reproducible case?
I am happy to provide real examples, logs and templates if needed.
Thank you!
Thank you for considering this and for maintaining an outstanding and powerful templating system.
This one detail is still a footgun, especially for users trying to do things the right way.