I ask Modbus support for transformations with .js

I would like to be able to display and set the temperature threshold using the set (+) (-) buttons
The temperature detected by the system is shown in a 16bit decimaltype word, which reads and writes the value of the SP1 setpoint, in ° K x10
Example: value in word: 2980 value to be displayed: (2980-2730) / 10 = 25.0 ° C).
All setpoints can be set between 10.0 and 35.5 ° C in 0.1 ° C steps

Is it possible to work with the js transformation?

modbus: serial.O22.connection = / dev / ttyUSB0: 19200: 8: none: 1: rtu
modbus: serial.O22.id = 1
modbus: serial.O22.start = 278
modbus: serial.O22.length = 1
modbus: serial.O22.type = holding

Number NumberItem “Number [% .1f]” {modbus = “> [O22: 0: transformation = JS (divide10.js)], <[O22: 0: transformation = JS (multiply10.js)]”}

Setpoint item = NumberItem label = “-” icon = “” minValue = 10 maxValue = 35 step = 1

File divide10.js
(function (i) {
return parseFloat (i- 2730) / 10;

File multiply10.js
(function (i) {
return Math.round (parseFloat (i + 2730) * 10);

but unfortunately it does not work, did you please me?

I forgot …
binding modbus is

OH 1.8.3

Can you please format all the configuration as code? See this thread for instructions (“Using three backticks at the start and end of the code”)

With current formatting the whitespace seems to be wrong, and it’s hard to tell what you have in the configurations.

Also, could you please share what kind of errors (if any) you receive in the logs?

There is a small issue with transformation, at least

instead of

 return Math.round (parseFloat (i + 2730) * 10);

you should have

 return Math.round ( (parseFloat (i) + 2730) * 10 );

(notice the difference in parentheses with parseFloat)


hi, how can I check the log?

Please find the relevant docs here : https://docs.openhab.org/administration/logging.html

Let me know if there is something unclear.

I am sorry, I forgot you were using openHAB1. The logging manual is for openhab2. Try to find the openhab.log, it should contain all the logs.

Would help also if you would format the configurations with backticks, see above.


I found the log file, weighs 34Mb is full of data. what mistake should I see?

I suggest to focus on recent log lines, not any old ones. Most of the lines are probably old. Lines with error or warning are of interest when something does not work as expected.

hello, I tried to focus the period I was trying, but modbus errors I do not find.
place a piece of log file?

Using three backticks at the start and end of the code?

Thanks for your time

Great! Go ahead and paste it here.

I’m happy

hi, I tried again and everything seems to work properly.
Only problem that of the set point in steps of 1, I would need 0.1.






Number NumberItemSP1 “Number [%.1f]” (Termostato_Setup) {modbus=">[O12:0:transformation=JS(multiply10.js)],<[O12:0:transformation=JS(divide10.js)]"}




Setpoint item=NumberItemSP1 label=“SP1 [%.1f]” icon="" minValue=10 maxValue=35 step=1


file transform multiply10.js


(function(i) {
return Math.round(parseFloat(i*10) + 2730);


file transform divide10.js

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

what do you think about it?

Great stuff. You can control the step size by the step parameter of Setpoint in sitemap.

but the minimum value of the step is 1 or am I wrong?

Where did you read that? Please try it out and report back.

I tried with step = 0.1 it works.
But with Android system Item displays 20.1 … 20.2 … 20.3 etc.
but when I get to 20.4 it is displayed 20.400002 so also with the 20.9 it shows 20.900002 … why ???

Not sure, with the below format string it should be with one decimal.

The underlying numbers might not be even, due to floating point arithmetic. But format string should guarantee certain resolution.

Please note that this is openHAB1 which is quite old already, perhaps fixed in openHAB2?

but openhab 2 the modbus binding is in beta test.
and it scares me

You can use the old binding with openHAB2 – no need to use beta versions. Many people use Modbus 1.x binding with openHAB2.

But it will require some setup for sure, and lots of new things to learn. Unfortunately this is where openHAB is heading, so you might want to consider doing the transition at some point.