[Solved] Template Sensor convert file sizes bytes to KB to MB

I am absolutly not the expert, so I would ask what do you think about this calcuation? It seems it works fine

value_template: "{{ (states('sensor.frlmx_b_sent')|filesizeformat()) | round(2) }}"
1 Like

Regarding the fritzbox netmonitor the following code worked good for me:

- platform: template
  sensors:
    bytes_received:
      friendly_name: "Netzwerk GB empfangen"
      unit_of_measurement: "GB"
      value_template: "{{ (state_attr('sensor.fritz_netmonitor', 'bytes_received') | filesizeformat(GB)) }}"
    bytes_sent:
      friendly_name: "Netzwerk GB gesendet"
      unit_of_measurement: "GB"
      value_template: "{{ (state_attr('sensor.fritz_netmonitor', 'bytes_sent') | filesizeformat(GB)) }}"

it automatically rounds the outcome to 1 decimal and converts it from bytes to GB

2 Likes

please can you explain how to convert?

i have a card in lovelace:

type: sensor
entity: sensor.fritz_box_7490_kib_s_received
name: DOWNLOAD
graph: line
detail: 2
hours_to_show: 24