Divide sensor with platform: template

Hi all,

I have an energy sensor giving power in Watts but I want to use kiloWatts so I need to divide the sensor by 1000.

I’ve done some searching on the forum and Google but don’t see the solution.

What I got so far:

  - platform: template
    sensors:
      zonnepanelen_meter_vermogen_kw:
        friendly_name: "Vermogen"
        unit_of_measurement: 'kW'
        value_template: "{{ (states('sensor.zonnepanelen_meter_vermogen_w') | int / 1000 | round(1)) }}"

With these code I do get the Watts down to kW but with 3 decimals. It looks like the “round(1)” is not working (I want 1 decimal) but I can’t seem to figure out what the proper code is.

Hopefully someone can help me with this one :slight_smile:

Thanks!

Darryl

2 Likes

Order of operations error. You are only rounding the number 1000. Put some brackets around the whole value - you had them round the whole template, including the round(). Try this

value_template: "{{ ( states('sensor.zonnepanelen_meter_vermogen_w') | int / 1000 ) | round(1) }}"
1 Like

This did the trick!

I was close xD Tried lots of ways except this one, thanks!