Giter VIP home page Giter VIP logo

Comments (4)

ruifung avatar ruifung commented on June 2, 2024
- 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.

from hass.agent.

avenom avatar avenom commented on June 2, 2024
- 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

from hass.agent.

ruifung avatar ruifung commented on June 2, 2024

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.

from hass.agent.

avenom avatar avenom commented on June 2, 2024
  1. I generated a UUID for the sensor (https://www.uuidgenerator.net/version4) and can now round up in the sensor properties in HA
  2. Converted bytes to the binary system of gibibytes (GiB).

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 }}"

storage-mebibyte_measurements

2024-04-13 17-30-10 Home Assistant

2024-04-13 17-28-49 Home Assistant

from hass.agent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.