Dividing MB into GB in a Sensor Template from IOT Link

Hello,
I´m playing around with this great Windows Integration for MQTT: https://iotlink.gitlab.io/index.html

There are some examples for Home Assistant, for example:

  - platform: mqtt
    name: "My Computer - HDD Free Space (C)"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/hard-drive/c/available-free-space"
    unit_of_measurement: 'MB'
    icon: mdi:harddisk
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

This templates displays the free space in Megabytes, but I would prefer Gigabytes, so I tried to change the line

value_template: "{{ value }}"

into

value_template: "{{ value | float / 1024 | round(2)}}"

The result I get is not 223343 MB, but 217,1318359375 GB, which seems correct. But I want only 2 digits after the comma, wasn´t the “round” command responsible for it?

Thnaks,
Philipp

It’s an order of operations problem. You are rounding the constant 1024. Use some parentheses.

See my similar answer here:

1 Like

Great, that worked. Thank you