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: ???
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.