Templates Help with rounding maths to 3 decimal

Hi everyone. I’m trying to perform calculation and rounding on my front end for air conditioner. I already have the wattage and have divided by the voltage to give me the running amps but do not know what I’m doing wrong in the rounding down of this number.

Can someone point me in the right direction

#######ATTRIBUTES AS ENTITIES############################################################

  • platform: template
    sensors:
    current_power:
    friendly_name: "Air Con Power Usage "
    value_template: ‘{{ states.switch.plug_158d0001fa63ab.attributes.load_power }}’
    unit_of_measurement: ‘Watts’

  ac_current_amps:
    friendly_name: "Air Con Current "
    value_template: '{{ states.switch.plug_158d0001fa63ab.attributes.load_power / 240 | round(3)}}'
    unit_of_measurement: 'Amps'

  washer_current_power:
    friendly_name: "Washer Dryer Power Usage "
    value_template: '{{ states.switch.plug_158d0001deb318.attributes.load_power }}'
    unit_of_measurement: 'Watts'

  washer_current_amps:
    friendly_name: "Washer Dryer Current "
    value_template: '{{ states.switch.plug_158d0001deb318.attributes.load_power / 240 | round(3)}}'
    unit_of_measurement: 'Amps'

  sun_angle:
    friendly_name: "angle of the sun "
    value_template: '{{ states.sun.sun.attributes.elevation }}'
    unit_of_measurement: '°'

When you do x / y | round, the rounding only applies to y. Think of it as having higher precedence than divide. So what you want is (x / y) | round(3).

2 Likes

Ok I see what u did there thanks so much just updated my configuration.yaml and now shows a much better result thanks so much @pnbruckner

1 Like