Open avenom opened 2 months ago
- platform: template
sensors:
storage_capacity_d:
friendly_name: "Storage Capacity Drive D"
unit_of_measurement: "GB"
value_template: "{{ state_attr('sensor.avenompc_avenompc_storage_d', 'AvailableSpaceMB') | float / 1000}}"
In case you're not aware, you can do math in HA templates. Note: I made the changes off the top of my head, if it don't work, there's probably a typo somewhere.
Also note, since your example is in MB (not MiB), you divide by 1000 to get GB. If the source data is actually in binary units (i.e. MiB), divide by 1024 to get GiB instead.
- platform: template sensors: storage_capacity_d: friendly_name: "Storage Capacity Drive D" unit_of_measurement: "GB" value_template: "{{ state_attr('sensor.avenompc_avenompc_storage_d', 'AvailableSpaceMB') | float / 1000}}"
In case you're not aware, you can do math in HA templates. Note: I made the changes off the top of my head, if it don't work, there's probably a typo somewhere.
Also note, since your example is in MB (not MiB), you divide by 1000 to get GB. If the source data is actually in binary units (i.e. MiB), divide by 1024 to get GiB instead.
Result: 181,953 GB
maybe you need parentheses for that. Try plugging the template into the HA devtools template tester and play around with it until you get the output you want.
Not perfect, but it works.
Sample:
- platform: template
sensors:
storage_capacity_d:
friendly_name: "Storage Capacity Drive D"
unique_id: 30a103c2-3147-4de3-be98-3a9a80ed7fc3
unit_of_measurement: "GB"
value_template: "{{ state_attr('sensor.avenompc_avenompc_storage_d', 'AvailableSpaceMB') | float / 1073.741824 }}"
Please help me convert MB to GB in this code:
Result: 181 953,0 MB