I can't get prefixes to work with DataAmount (UoM)

Here I’d like to present another workaround for others who maybe have the same problem and are reading this.
The principle is to store the raw value as a plain Number item and convert it via the JS transformation to the desired “shape & format”.

In my very specific usecase it looks like this:
Items:

Number nas_freeram  "RAM frei [%.0f]"   (g_snmp_nas) { channel="snmp:target:nas2104:freeMem" }
Number nas_totalram "RAM gesamt [%.0f]" (g_snmp_nas) { channel="snmp:target:nas2104:totalMem" }

Sitemap:

Text item=nas_freeram  label="RAM frei [JS(BtoGB.js):%s]"
Text item=nas_totalram label="RAM gesamt [JS(BtoGB.js):%s]"

The JS transformation is called BtoGB.js (Bytes to Gigabytes) and is stored in the transform folder:

(function(i) {
    var result = ((parseInt(i)  / (Math.pow(1000,3))).toFixed(1) + " GB")
    return result;
})(input)

Now the sitemap for example converts the “raw” item state 8785828471 to 8.8 GB which is then shown in the sitemap.

Hope this maybe helps somebody! :slight_smile:

2 Likes