I’m migrating my system atm to OH3.0 and so finally decided to also give UoM a try during this migration. I was always a little worried about the unit handling when it comes to rules.
But now I’m struggling at a different step with UoM:
When there is a Binding/Thing providing just a normal Number channel (in my case it’s the SNMP binding which offers just String/Number/Switch channels) is there some possibility to “add” a unit to this number and save it as a Number: item (here again I try to use Number:DataAmount) to make use of unit conversions later on?
My idea was to define the item as Number:DataAmount and use a JS transformation on thing-level to add the unit.
But I couldn’t get it working as I have no idea what’s the syntax of a QuantityType in Javascript. Just tried the syntax like in Rules DSL w/o any success. Would this be possible at all? Do I need an import? Any other solution to add the unit?
Out of curiosity - why not making a channel configurable with unit? Obviously it would permit only reading of numeric values, but it would solve some of troubles related to lack of unit information coming from modbus poll. (this is more on development side of things)
In fact that is what I have come up with, but using profiles
The profile also supports offset and gain correction, often at least gain is used with modbus.
This makes the channels fully UoM aware, even accepting quantity commands, with units converted and descaled appropriately for writing the data back to integer.