Human readable format

Hi,
Quick question.
Is there a way to shorten long numbers into a human readable format, in sitemap config? like making 1300 Byte to 1,3kB, or 5600m to 5,6km.

Thanks!

http://docs.openhab.org/configuration/items.html#state-formatting

This will get you part way there. But to do conversions like you are asking for you will need to either use a Rule and a Proxy Item to store the converted value for display on your sitemap or see if you can get a JavaScript Transformation to work in the Item’s label.

Thanks,
I solved it with javascript.

Bytes.js

(function formatBytes(a){
var d = 2;
e=[“b”,“kB”,“mB”,“gB”,“tB”,“pB”,“eB”,“zB”,“yB”];
if(0==a)return"0 “+e[0];
var c=1e3;
var f=Math.floor(Math.log(a)/Math.log(c));
return parseFloat((a/Math.pow(c,f)).toFixed(d))+” "+e[f];
})(input)

sitemap:
Text item=XXXlabel=“Size [JS(bytes.js):%s]”

Very rough, but it works!

2 Likes