Rounding will not work

Hi,

I tried different tutorials I found on the web but rounding just won’t work.

I successfully recalculated the sensor value (divide by 1000000), but the “round” at the end seems to be ignored.

My template sensors:

  - platform: template
    sensors:
      sensor_download_mbit:
        friendly_name: "InternetDownload"
        unit_of_measurement: 'MBit'
        value_template: "{{ (states('sensor.speedport_download') | int / 1000000 | round(0)) }}"
        
  - platform: template
    sensors:
      sensor_upload_mbit:
        friendly_name: "InternetUpload"
        unit_of_measurement: 'MBit'
        value_template: "{{ (states('sensor.speedport_upload') | int / 1000000 | round(0)) }}"

I also tried with float instead of int, it doesn’t make a difference.

How it looks:
Bildschirmfoto vom 2024-11-04 11-03-39

Can you help me? Thanks!

Order of operations. You are rounding the number 1000000

1000000 | round(0)

Use some parentheses:

value_template: "{{ (states('sensor.speedport_download') | int / 1000000) | round(0) }}"

Seems I failed a bit at basic math :nerd_face: Many thanks, this works fine!

1 Like