Migration to OH4 - readTransform javascript

in OH3 i had JS transformation in MODBUS input:

how set transformation in OH4?

Exactly the same only you need to have the JS Scripting add-on installed.

Though if it’s just doing a map, why but use the Map transform?

In OH4 have not JS transformation.
I see in Transformation Add-ons only Regex transformation and JSONpath transformation.

Not a transformation, the JavaScript automation add-on. It’s also used for the transformation now (like any other scripting language can be used).

is this code correct? I don’t see an error in the log and transofmrace doesn’t work.

Bridge modbus:serial:R2 [ port=“/dev/ttyUSB0”, id=2, baud=115200, stopBits=“1.0”, parity=“none”, dataBits=8, connectMaxTries=1, receiveTimeoutMillis=1000 ] {
Bridge poller R2_INPUT [ start=0, length=8, refresh=1000, type=“discrete”, maxTries=1 ] {
Thing data I2_1 [ readStart=“1”, readValueType=“bit” , transformationPattern=“SCRIPT:js:modbus_contact.script”]


(function(inputData) {
var out = inputData ; // allow UNDEF to pass through
if (inputData == ‘1’ || inputData == true || inputData == ‘ON’ || inputData == ‘OPEN’) {
out = ‘CLOSED’ ; // change to OFF or OPEN depending on your Item type
} else if (inputData == ‘0’ || inputData == false || inputData == ‘OFF’ || inputData == ‘CLOSED’) {
out = ‘OPEN’ ;
return out ; // return a string

No. The file needs to be named modbus_contact.js and the pattern needs to be JS:modbus_contact.js. See Transformations | openHAB