Please Help with rounding

Please help with rounding?

This works

      day_average_price:
        friendly_name: day_average_price
        value_template: >
          {{states.sensor.nordpool_kwh_fi_eur_3_10_024.attributes.average| round(2)}}

This does not?

      start_price:
        friendly_name: start_price
        value_template: >
          {{state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'average' ) * states('input_number.price_percentage') | round(2)}}

How can I get this second one working?

You are only rounding the last state. Put brackets around the lot:

{{ ( state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'average') * states('input_number.price_percentage') )| round(2) }}

I tried that one too but the result was:

Also you need to convert the second state to a number.

{{ ( state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'average') * states('input_number.price_percentage')|float(0) )| round(2) }}

1 Like

:+1:Thank you very much!