Template States help

Hi I am trying to compare a sensor state value against a helper input value.

The issue I am having is that the value I see in the helper slider and in the Developer states, is different to what the yaml states syntax is reporting:




The ‘input_number.charge_to_soc’ float value is being reported by the template syntax as 5 units lower than whatever I acually set it too using the slider?

Here is my code:

{% if float(states(‘sensor.victron_battery_soc’)) == float(states(‘input_number.charge_to_soc’)) %}
Yes
{% else %} No
{% endif %}

{{states(‘sensor.victron_battery_soc’) |float - 5}}
{{states(‘input_number.charge_to_soc’) |float - 5}}

The If statement is doing the comparison and the single state lines are simply printing the values I am testing so I can see if the comparitors are working as expected.

Can anyone explain whats going on and if i need to correct anything in my code to have the desired values being reported in my code?

Kind regards

Duncan

Stand down I was being a nob!.

I had {{states(‘input_number.charge_to_soc’) |float -5}} in my inital reporting vlaue line, as I assumed the float needed a default point value. Its deosn’t so the correct line is {{states(‘input_number.charge_to_soc’) |float}}.

and all is good.

That’s not a default value, it’s subtracting 5, hence the issue you saw. A default value would look like:

{{ states('input_number.charge_to_soc')|float(-5) }}

Unless you need decimals, it’s safer to use the |int filter instead of |float, to avoid comparing computer rounding errors (e.g. 70.00000001).

1 Like