Modbus Transformation?

Hello all. I am new to this so I will do my best to document properly and give all information needed.

Goal: To divide incoming Modbus data by 10 on read and multiply by 10 on write.

What I’ve done: I followed the scaling example in the modbus bindings doc to no avail. I must have something set up incorrectly.

Openhab Ver: 2.3.0
Modbus Ver: ???

before%20scaling%20value

Above are the current values I’m receiving from the device.

Here is my applicable Modbus Binding code:

#LOW SIDE

#Process Value Address
serial.slave1.connection = /dev/ttyS0:9600:8:none:1:rtu 
serial.slave1.type = holding
serial.slave1.start = 4096 
serial.slave1.length = 1 
serial.slave1.id = 1


#Set Point Address

serial.slave5.connection = /dev/ttyS0:9600:8:none:1:rtu 
serial.slave5.type = holding 
serial.slave5.start = 4097
serial.slave5.length = 1
serial.slave5.id = 1

Here is my applicable items code:
NOTE: BT1Scaled is the item I’m using to test the scaling

Number LowSidePV "Process Value is [%f]" <temperature> (All) {modbus="slave1:0"}
Number LowSideSV "Set Point [%f]" <temperature> {modbus="slave5:0"}
Number BT1Scaled "BT1 Scaled Value is [%f]" <temperature>{channel="modbus:data:SetPoint:holdingPoller:holding1scaled:number" }

Below is my things code for the channel:

Bridge modbus:serial:SetPoint [port= "/dev/ttyS0", id= 1, baud=9600, stopBits="1", parity="none", dataBits=8, encoding="rtu" ] {
	Bridge poller holdingPoller [start=4097, length=1, type = "holding" ] {
		Thing data holding1scaled [ readTransform = "JS(divide10.js)", writeTransform= "JS(multiply10.js"]
	}
}

Below is stored in the transform folder:
My divide10.js code:

// Wrap everything in a function (no global variable pollution)
// variable "input" contains data passed by openhab
(function(inputData) {
    // on read: the polled number as string
    // on write: openHAB command as string
    var DIVIDE_BY = 10;
    return parseFloat(inputData) / DIVIDE_BY;
})(input)

My multiply10.js code:

// Wrap everything in a function (no global variable pollution)
// variable "input" contains data passed by openhab
(function(inputData) {
    // on read: the polled number as string
    // on write: openHAB command as string
    var MULTIPLY_BY = 10;
    return Math.round(parseFloat(inputData, 10) * MULTIPLY_BY);
})(input)

I noticed there was a community post about something similar regarding the version of modbus binding, but I do not know how to find my binding version, it is not showing up in my paperUI.

I’ve worked at this issue on and off for a while now and can’t seem to find the problem. There’s so many things that seem to have to communicate just right for the item to get data to the channel which then calls the transform fxn that it’s hard for me to debug.

I appreciate any help.

In the image you are seeing LowSidePV and LowSideSV.

BT1Scaled returns [NULL] on my habpanel

Here you can see the version of the binding. As shown in the picture: 2.4.0-SNAPSHOT

I suggest you to use the newer 2.x binding and get to know its readme. Now you are mixing version 1.x and 2.x configurations.

I’m not sure how to get my version number outside of PaperUI. I cannot see the Modbus binding at all in PaperUI

Looks like you are running openHAB version 2.3 and that doesn’t include the new modbus binding. Only 2.4 snapshot builds does. Check out this link and see if you can install the 2.4 binding. One possibility is to switch your openHAB to 2.4 snaptshot. This way the new modbus binding would be available through PaperUI

For getting detailed info of your openHAB installation e.g. installed bindings and versions see this section of the docs about karaf console:

Got it. I will check out openHAB 2.4 and retest from there. Thank you so much!

1 Like