Correct incoming MQTT value

Hello everybody,

I have some temperature sensors which send their data via MQTT to my openhab server, this is the definition of one of these in the things-file:

  Thing topic sensor_01 "sensor 01" @ "room 39" {
    Type number : Temperature "Temperature" [ stateTopic="sensor_1/dht22/Temperature" ]

Now I want to correct the incoming values (p.e. add 1) so that they are written with the corrected value in the persistence data, anyone who knows how to accomplish this?

Use incoming value transformation with JS to change the value in a channel level of as a profile to change it for individual items only

Hallo Matthias,

wäre dir um einen Tipp bzgl. der Anwendung der value transformation dankbar, habe das noch nie gebraucht und bin beim ersten Lesen jetzt nicht schlauer geworden :expressionless:

Hi Matthias,

thanks for your answer, I would be grateful for a tip on how to use the value transformation, I have never used it before and didn’t get any wiser after reading the documentation for the first time :expressionless:

  1. Install the js transformation add on
  2. Create a new js file in the transformation folder with your function
(function(i) {
    return i*2;
  1. Add the transformation to the channel (I only use UI based configuration, therefore not exactly sure about the syntax, but there are samples in the mqtt binding docu)

Hey, that’s great, thank you very much!!!

Ok, I tried the following now:

created a transformthevalue.js file in transform folder:

(function(i) {
    return parseFloat(i) - 10;

Tested it with JavaScript Tester online, seems to work.

Changed the .items definition:
Number sensor_33_temperatur "Temperatur [%.1f °C]" <temperature> (gPersistence) { channel="mqtt:topic:mySecureBroker:sensor_33:Temperature" [profile="transform:JS", function="transformthevalue.js"], expire="30m,NULL"}

At first nothing happened, then I restarted openhab and now I get the following in the log file when the transformation should be executed:

[WARN ] [.thing.internal.CommunicationManager] - No ProfileFactory found which supports profile ‘transform:JS’

What did I miss? :confused:

My fault, installed JSONPath Transformation instead of JS Transformation :see_no_evil:
Now it’s working like a charm :slight_smile: