I’m trying to scale a value of an item in my sitemap. This can be done using a rule which works fine.
However I was hoping that somehow it would be possible to scale the value directly in the items file.
This is the basic item:
Number nCpuLoad_1_minute "Load (1 min)" <none> (gSystem) { channel="systeminfo:computer:raspi:cpu#load1" }
Now I would like to add another item that has the value of the basic item multiplied by 100:
Number nCpuLoad_1_minute_scaled "Load (1 min) scaled" <none> (gSystem)
Is there a way to scale the value of nCpuLoad_1_minute_scaled directly in the items file?
You can add a transformation to show the value of the Item scaled. You probably need to use the JS transformation which means you’ll have to put it in a separate .js file. The Scale transformation doesn’t do what you are after here.
You could modify the value coming from the channel by applying a profile. But here again you’d need to use the transform profile with a JS transformation which puts the actual multiplication in another file.
So the short answer is no, you can’t do it wholly within the .items file. You’ll either need a JS transformation or you’ll need a rule.
NOTE: OH 2.5 does not have the the same set of profiles as are available in OH 3. Make sure you look at the OH 2.5 version of the docs.
I wrote recently for my own use very basic scale profile (which works also with quantities): ScaleProfile, maybe some day similar thing will come into openHAB core without pulling gain/offset profile from modbus binding?
Anyhow, above can be easily ported to OH 2.5 where APIs are pretty much the same.