Is_number() buggy?

seriously?

{{states('sensor.stats_us5000c_ac_power') }}
{{is_number('sensor.stats_us5000c_ac_power') }}
{{is_number('-259') }}

result:

-259
False
True

I think states() returns a string so it isn’t a number,

'sensor.stats_us5000c_ac_power' is definitely not a number, but the state of the sensor with that name might be. Try:

             vvvvvv
{{ is_number(states('sensor.stats_us5000c_ac_power')) }}
             ^^^^^^
2 Likes

There are examples in the docs: https://www.home-assistant.io/docs/configuration/templating/#states-examples

{% set state = states('sensor.temperature') %}{{ state | float + 1 if is_number(state) else "invalid temperature" }}

{% set state = states('sensor.temperature') %}{{ (state | float * 10) | round(2) if is_number(state)}}

{% set state = states('sensor.temperature') %}
{% if is_number(state) and state | float > 20 %}
  It is warm!
{% endif %}

thanks all! Was as easy as that. This fixes the situation when my battery management system is reporting silly value for whatever reason.
Now I’ll have to check if it works when the homeassistant entity states if not defined yet at start and BMS is not reporting anything yet (would add a test on states being defined if needed).