Easiest way to multiply channel value before sending to item

Hi,
I am using OH3 and got a bit lost in the EASIEST option to correct my power readings of an MQTT channel (number format) and linked to an item. To correct this, a constant multiplier value would be enough.
I wonder how can I do this BEFORE it is stored to an item (I do not want to solve it with a rule/shadow item). I already googled a lot and found rules based & transformations (plenty of different ways, seperate bindings necessary, ??) but to be honest feel a littlebit lost what is the easiest way to achieve this.

Thx for your help!

Profiles can be used to manipulate data passing between binding channel and Item over a link. The profile is configured on the link. Different profiles do different things, one makes use of the Transformation services (which may themselves be used in various parts of openHAB).

So for your example, you might apply a Transform profile to your channel-Item link, and have the profile call a JS javascript transform, for which you write a little script that multiplies by 1000 or whatever.

Many bindings also allow manipulation by specifying something in the channel settings. That can be some specific thing like “off=code99” or “format %0.f”. Or a more generic opportunity to use one of the transformation services.
MQTT binding offers a wide range here, but to “do maths” you would probably select a stateTransformation of JS type and use the same little script outlined earlier.

I don’t think there is any efficiency advantage one way or another. For the sake of sanity I would prefer to do it in the channel settings, keeping all the settings for that data together.

You might also consider introducing units and using quantity type Item, e.g. transform “1500” into “1.5 kW” and feed to Number:Power type Item.

Thx a lot rossko57 for your fast and helpful reply.
I found now thx to your help under my mqtt:topic:xxx:power and the advanced tab the “Incoming transform” → here I only find JSON based examples → I used MQTT Attribute “version” (as suggested).

My Thing config looks like that:

  • id: power
    channelTypeUID: mqtt:number
    label: Power
    description: “”
    configuration:
    stateTopic: zigbee2mqtt/Plug_Power_2/power
    unit: W
    min: 0

I am still a bit lost how to make my “power*1.5” calculation.
I found this example:
Number Usage “Usage in Watt [MULTIPLY(1000):%s W]” { someBinding:somevalue }
and now wonder, if I can diretly “MULTIPLY” at the proper space?
Or do I need to go the route via stateTransformation and a seperate file for it (where I am to be honest also confused where to place it).
Sorry for the dumb question - but I am really a bit overwhelmed of the plenty options…

I don’t know what means in this context.

Yes. There are many transformation services, you will not be provided with examples for every one. Have you looked at the docs for Transformation Add-ons?

Where?
I have not heard of a MULTIPLY transformation service.

This is what I was suggesting, but you do not have to do it that way there are always other ways e.g. rule and proxy Item.
Use what you understand, or find out what you don’t.

Look for examples.

1 Like

Hi rossko57,
thx for your help - today I got some time to try out your suggestion with javascript transforms.

My main problem was, that in the UI I could not find for the MQTT thing/channel where to place the javascript file. BUT after installing the JS transformation, a new selection in profiles came up than it was really easy → hopefully this helps another newbee!

Thx again!