Item number - change decimal point

I read a value from the external device with scale factor 100 - means readed value is 43558 but it means value is 435,58. How to correctly setup item or how to correctly transform ?
Thank you

You have several options:

  1. create a SCRIPT Transformation and apply it to the Thing as an incoming value transformation

  2. create a SCRIPT Transformation and apply it as a Profile on the Item (if on OH 3.4 you’ll probably need to install and use the JS transformation for now, SCRIPT wasn’t supported on the Profile yet in 3.4)

  3. create a proxy Item and a rule that triggers when the Item changes, does the division and updates the Proxy Item with the correct value

  4. create a SCRIPT Transformation and apply it as the State Description Pattern on the Item, though that just changes how it’s shown, not it’s actual vlaue.

How about using the Gain-Offset profile?
Works pretty well on the values I receive from my ModBus energy meter. Those meters often send you integers that have to be scaled properly, exactly what is required her.
And it is code-free.
A gain factor of 0.01 should do the trick.

I thought that profile only did addition and subtraction and a division is needed here. It’s also missing from the table in the Items doc page. Is it an official Profile? Never mind, I found it. But it’s very vague in it’s description. Even in MainUI it implies it just adds or subtracts, not multiplication or division.

Yes it is - at least I do not remember installing it on top. I run OH 3.4.

If you link the profile you can see the documentation at the input field level.

You can add an offset before applying the gain, within the gain field it is possible to add the UoM as well.
Example: I bought a second hand meter that can not be reset.
So I substract the meter reading I bought it with to have a clean base value. Then I apply a gain of “0.01 kWh” to get the current value of energy consumed since I installed it.

Yep and on the 4.0 SNAPSHOT it says

I also don’t see the word “Gain” anywhere.

The main docs say:

An offset can be specified via the parameter offset which has to be a QuantityType or DecimalType . The specified offset will be applied to the value from the device before it arrives at the Item.

Again, here I cannot find the word “Gain” anywhere. Items | openHAB

As far as I can tell I can’t find “Gain” anywhere as a transformation or as a Profile. Maybe this is something specific to the ModBus binding? The Modbus docs do seem to imply that it is specific to that binding meaning it’s only available to users who have Modbus. It’s not a generic profile generally available.

You are right, seems this only comes with ModBus.Sad, but true.
Would have been a simple solution here, thanks for the clarification.
This is how it looks like:

From my perspective this profile is a candidate for the core then, makes life easier and could replace/enhance the current limited profile without breaking things.Code is already available and working well, should not be that tricky.

So in the end the options you mentioned are the way forward at the moment if you do not use ModBus.

You could open an issue to propose the move of this profile in the core

1 Like

ok, I have a item number readed:

but there is scale factor 100 so correct value is 456,66
if I will use a gain 0.01 value is 466 (missing decimal points)

and in the metadata / state description / pattern, don’t know if exist any function

next chance is transform somehow in the rule where I’m using deltaSince function

so I tried multiply by 0.01 but result of deltaSince isn’t 7.3 but 7.300 (before multiply was 730)

Opened feature request to merge GainOffset-Profile to core.

ok, thanks
Is there any output how to get from the readed value 46566 a value 465,66 with the gain ?
Or I must use a rule and recalculate all values ?

The multiplier fits, this scales the incoming value properly.
Did you set the state description for your item?
There you can format the output value. Maybe here the decimals are missing.
“%.2f” should result in two decimals being shown for the item.

Could you post your item and your channel definition?

ok, on the end I found a solution
gain I set to 0.01 and state state description in the metadata I set to %.2f
Then value is ok, but quite complicated solution