Need Help Linux Router: Converting kibs to mbps

The entities for my Linux router show data received and sent in kib/s, and I’ve been trying to create a custom sensor that converts it to mbps. Here is what I currently have, but it keeps erroring out.

Could someone please tell me what I’m doing wrong in the below template?

sensor:
  - platform: template
    sensors:
        ipfire_mbps_received:
            friendly_name: "Mbps Received"
            value_template: "{{ states('sensor.linux_router_kib_s_received') | /(122) | round(1) }}"
            unit_of_measurement: 'Mbps'
            icon_template: mdi:download-network
            
        ipfire_mbps_sent:
            friendly_name: "Mbps Sent"
            value_template: "{{ states('sensor.linux_router_kib_s_sent') | /(122) | round(1) }}"
            unit_of_measurement: 'Mbps'
            icon_template: mdi:upload-network

You have an empty filter. It should be converting to an integer.
value_template: "{{ states('sensor.linux_router_kib_s_received') |int /(122) | round(1) }}"

Also to go from kibps to Mbps you should be multiplying by 0.001024, or dividing by 976.5625.

Unless you want to go from kibps to MBps, in which case what you have is ok

Thank for you help, and I feel silly over overlooking that.

Also, thank you for the conversion tip. =)

More a unit thing. Mbps vs MBps. Which do you want?

I was needing to go to Mbps, so I updated my numbers.

1 Like

One last tip. It is much easier on the cpu if you multiply rather than divide.

Not so you would notice though. 2 clock cycles vs 20 sort of thing. Where clock cycles are (depending on your processor speed) measured in nano to pico seconds.

So I would change it from

| int /(122)  |

to

| multiply (0.001024) |

correct?

You can just do:

|int * 0.001024