{% set over_forecasts = states('input_number.over_forecasts') | float %}
{% set under_forecasts = states('input_number.under_forecasts') | float %}
{% set num_days = (states('input_number.over_forecasts') + states('input_number.under_forecasts')) | round(0) %}
{% if num_days > 0 %}
{{ ((over_forecasts / num_days) * 100) | round(2) }}
{% else %}
0
{% endif %}
In the above code, input_number.over_forecasts = 5 and input_number.under_forecasts = 1
When I run the code, I get the error below:
Error rendering data template: ValueError: Template error: round got invalid input ‘5.01.0’ when rendering template ‘{% set over_forecasts = states(‘input_number.over_forecasts’) | float %} {% set under_forecasts = states(‘input_number.under_forecasts’) | float %} {% set num_days = (states(‘input_number.over_forecasts’) + states(‘input_number.under_forecasts’)) | round(0) %} {% if num_days > 0 %} {{ ((over_forecasts / num_days) * 100) | round(2) }} {% else %} 0 {% endif %}’ but no default was specified
So it seems like, instead of getting 5+1 = 6, the automation is getting 5 + 1 = 5.01.0. Both of the entities I’m using are integers rather than strings, so I can’t understand why this is happening?