Divide number when displaying in sitemap?

I am querying my NAS using SNMP so I can show some details in my sitemap.

Free Space is shown as “793004” being Megabytes. Is there an easy way to divide this to get the gigabyte equivalent? I’m sure I can do it in a rule but hoping I can do something in my item or the sitemap?

Number RN2120_FreeSpace “Free Space [%.0f mb]” (AllItems, LogRRD4J, ReadyNAS) {snmp="<[192.168.1.37:public:.1.3.6.1.4.1.4526.22.7.1.6.1:10000]"}

You could probably use a javascript transform.

Here’s a javascript transform I use for exactly the same thing:
mb2gb.js

(function(i){
	return (i / 1000).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + ' GB';
})(input)

Copy this, place it in a file in the transform folder and reference it in your items file something like this:

Number LocalComputer_Storage_Available "Available Disk Space [JS(mb2gb.js):%s]" { channel="systeminfo:computer:rpi:storage#available" }

Your sitemap can reference the item in your sitemap like this:

Text item=LocalComputer_Storage_Available

Make sure you have the Javascript transformation installed.
In PaperUI go to->Addons->Transformations tab

3 Likes