Sensor Value Rounding Error and measurement

Hello!

A confusing one (for me)!

I am trying to create a sensor that provides the charging cost of my EV charging, using the Zappi Charge Added Session sensor, and multiplying it by my charge rate (7.5p, 0.075).

I have managed to get this to partially work, but with numerous errors that are confusing me.

I have configured the following in templates but it gives me a random number of decimal places (and the wrong figures and I am not sure what part must be wrong. noting that if I use 7.5 as the multiplier I ended up 10 out but with the more logical figure (26.26).

      - name: EV Session Cost
        device_class: monetary
        state: "{{(states('sensor.myenergi_zappi_charge_added_session') | float(0) * 0.075 | round (2))}}"

This gives the following view:

if I modify it to be:

        state: "{{(states('sensor.myenergi_zappi_charge_added_session') | float(0) * 0.075 | round (0))}}"

It gives an output value of 0.0 £, and if I modify it to;

        state: "{{(states('sensor.myenergi_zappi_charge_added_session') | float(0) * 0.075 | round (0))}}"

If gives me a session cost of 3.502£

I’m perplexed by the jump from 4 decimal places to none!

The figure should be 35.02 * 0.075 which is 2.62

I am perplexed?!

Your |round is only working on the 0.075, turning it into 0.08 or 0 in your various attempts. Put brackets around everything you want rounded.

state: > 
 {{ (states('sensor.myenergi_zappi_charge_added_session')|float(0) * 0.075)|round(2) }}

Ahhh , its always something simple!

1 Like