Adjusting my temperature sensor data

I have noticed that my sensor is always +2 degrees above the normal temperature(*).
I would like to compensate that excess on the data.

Can I do it here ? on the item file ?

something like Temperature = ($.temperature -2)

//Upstairs Hall Temp
Number SoffSC_DWST “Temperature [%.1f °C]” {mqtt="<[broker:tele/SonoffSC/SENSOR:state:JSONPATH($.Temperature)]"}

I have tried I didn’t work.

Thank you

(*) The chinese put the heat sensor inside the box with all the circuits around ahahahaha!!!

You could do it using a Proxy item which gets updated by rule. The rule should be triggered by each update of your item and should do a postupdate to the Proxy item with the corrected value.
This Proxy item would be used for the Display on UIs, persistence etc.

Thanks Opus but I don’t understand your suggestion. I am not old with Openhab yet.
You direct me to rules I thought maybe I can execute an arithmetical operation somewhere in a simple way…

Because it is just and adjustment of an existing value!

Create a number item, which is not connected to anything.

Number proxySoffSC_DWST

Make a rule like:

rule "Populate ProxyItem"
    Item SoffSC_DWST received update
    proxySoffSC_DWST.postUpdate((SoffSC_DWST.state as decimal) -2)

Use the proxySoffSC_DWST item on your sitemap and/or HABPanel and for any persitence instead of SoffSC_DWST.

NOTE: I had to type in the rule without a system on hand, so I can’t check the syntax.

1 Like

Thank you Jurgen
I will try that!


If you used the JS transform instead of the JSONPATH transform you can extract the value from the JSON and subtract 2 using JavaScript.

1 Like

Waoooo I love this one and will get me familiar with JS transform…which I tried before but failed to display the result. It looks elegant solution.

Is there an example somewhere ou an indication ?

Thank you Richard

Here is one I use:

String vSonoff_3157_Uptime "Powercord 3157 Uptime [JS(hours2days.js):%s]"
    <time> (gResetExpire)
    { mqtt="<[mosquitto:tele/sonoff-3157/STATE:state:JSONPATH($.Uptime)]", expire="1h,state=NA" }


(function(i) {
    if(isNaN(i)) return "NA";
    var days = Math.floor(i/24);
    var hours = i%24;
    var pad = "00";
    return days+":"+(pad+hours).slice(-pad.length)+":00:00";

In your case, you will want to the transform on the mqtt binding, not just the label. This also means you will have to extract the JSON value inside the JS which I know is possible but you have to google to find out how. I don’t know off the top of my head.

1 Like

Rich thanks!
Excuse my ignorance WHY this talks about Uptime ? what have you tried to do with it in your case to understand better.

the Function is in the rules file ?



For some reason this sis not working.

it send me back the ProxySoffSC_DWST as label and nothing for value.

My Sonoff switches report their uptime (i.e. the amount of time they have been running without a restart or losing power) in number of hours. I use the JS to convert the hours to DD:HH:MM:SS format to match the uptime of my other devices. I only need this for my sitemap so it only applies to the label.

Follow the link on my posting which takes you to the docus for the JS transform.

See for generic instructions for using transformations.

Hi Rich
Very interesting this Transformation chapter. I like the connection that it can make between numbers and concrete understandable things.
Just one thing as I am not a Javascrpt advanced coder…

I did this :
Number SoffSC_DWST “Temperature [JS(CompSoFF.js):%.1f °C]” {mqtt="<[broker:tele/SonoffSC/SENSOR:state:JSONPATH($.Temperature)]"}

and the function that is located in transformation folder…
(function(i) {
//var res = i;
var degrees = Math.floor(i - 2);
return +degrees;

But for some reason I’m not getting anything !!

thanks for your help

Hi Saladin,
Your javascript file must be in the transform folder
and you function:

(function(i) {
var degrees = parseFloat(i) - 2;
return degrees;

The javascript transform unfortunately returns String only

Number SoffSC_DWST “Temperature [JS(CompSoFF.js):%s °C]” {mqtt="<[broker:tele/SonoffSC/SENSOR:state:JSONPATH($.Temperature)]"}

Good luck

1 Like

Thanks to all of you.
All working.


Hi Saladin,
Your javascript file must be in the transform folder
and you function:

(function(i) {
var degrees = parseFloat(i) - 2;
return degrees;

The javascript transform unfortunately returns String only

There are no way to retrieve a number value directly ?

What are you going to do with that?
If you pass a numeric string to a number type channel or a Number type Item it will get parsed as a number.