OH 4 – Replacing MQTT JS transformation to SCRIPT transformation

Close to a successful migration from OH 3.4 (stable) to 4.0 (snapshot) for testing purpose, and being aware of Javascript transformation is removed from OH 4 (Java 17) I have tried to replace JS transformation to SCRIPT transformation, with mixed results. For both Modbus and MQTT, I have replaced (within main UI) from




, obviously also changing file endings from .js to .script in the transform folder. For Modbus, the change is successful for input under readTransform/writeTransform, and linked items get updated as before. However, for MQTT, changes made under transformationPattern does not seem to work, i.e. no errors/log information, but the linked items does not get updated as with JS transformation under OH 3.4.

Anyone being able to use MQTT transformationPattern within main UI using SCRIPT?

Did you install the transformation pattern

JavaScript Scripting, Javascript Transformation and Nashorn addons are installed/migrated from 3.4 to 4.0. OH4: openhab-js installed using npm, unchecked “Use included library” for JavaScript Scripting settings.

Haven’t identified a different/dedicated addon for SCRIPT transformation pattern…? And as mentioned, SCRIPT transform works for Modbus using OH 4.

You can add logging to the script. Add some to see whether or not the transform in question is even being invoked.

The JavaScript Transformation no longer exists in OH 4. In fact, if you have it in use somewhere you’ll see a warning in the log about that. Did you recode the transformation to be compatible with ECMAScript 11? The JS Transformation used Nashorn ECMAScript 5.1 and there might be incompatabilities.

There isn’t. It’s part of core and will work with an Rules language you have installed.

I’m also working on this to prepare for OH4.
I still have a few MQTT-Things as text files in OH 3.4. And that seems to work with new Script Transformation:

graaljs:filename.script → Is graaljs correct? Or just js? Also in docu only DSL, JS, JRuby are mentioned. But this are maybe only examples . . . not sure.

As described in docs, graaljs seems to be the correct approach:

Was a bit unclear here, all the listed addons were migrated from 3.4 to 4.0, although JavaScript Transformation was removed within OH4. Have installed openhab-js (npm).

For MQTT channel, following the documentation and defining

transformationPattern: SCRIPT(graaljs:compressorPercentage.script)

I now get the following log warnings:

[WARN ] [t.generic.ChannelStateTransformation] - Transformation service SCRIPT(GRAALJS for pattern compressorPercentage.script) not found!

Did you install the JS Scripting add-on? Note that openhab-js comes with the add-on and doesn’t need to be installed separately unless there is some new feature you want to use before the next release of OH.

Yes, JavaScript Scripting add-on is already installed as part of OH3.4, and is migrated to OH4.0 (as mentioned above). Also, SCRIPT(graaljs:filename.script) works for the Modbus part, just not for MQTT transformationPattern.

I haven’t used SCRIPT myself yet (I don’t need many transformations in my system) so there must be something wrong with the syntax. But I don’t know what.