OH 4 – Replacing MQTT JS transformation to SCRIPT transformation

Which OH 4 milestone? All this changed between M1 and M2.

Particularly when using the testing version of OH, when you seen an error like this it’s vital that you review the Latest version of the docs to see if something changed (reviewing the announcements and list of changes is important too).

Looking at the latest docs Transformations | openHAB for GraalVM JS the pattern should be JS:Hue_HSB_Out.js (note the file name needs to end in .js). For Nashorn JS the pattern should be NASHORNJS:Hue_HSB_Out.js.

Because any Nashorn JS transform should be compatible with GraalVM JS, I recommend against using NASHORNJS unless you have a reason (e.g. don’t want to install the GraalVM add-on).

Ah, after I’ve migrated to M2 and noticed errors regarding JS transforms in the logs I incorrectly assumed that latest docs are not up to date. I rolled back to previous config (meaning JS:Hue_HSB_Out.js) and my config is working again.
Thanks for pointing me in right direction!

Just make sure to click on “Latest”. They are not guaranteed to be immediately updated but so far it’s been less than a day between a PR going live and updates to the docs. Just make sure to select Latest in the upper left or else you’re looking at the OH 3.4 docs.

Hi, I have experienced some issue with JS transformation with ModBus and I need some help here. Below is what I have configured based on the description:

Thing data hold4746 [ readStart="4746", readValueType="int16", writeStart="4746", writeValueType="int16", writeType="holding", readTransform="SCRIPT:graaljs:divide10.script", writeTransform="SCRIPT:graaljs:multiply10.script"  ]

In the log I got the error message:

2023-08-11 23:17:23.644 [WARN ] [s.internal.SingleValueTransformation] - couldn't transform response because transformationService of type 'SCRIPT' is unavailable

I have JavaScript scripting installed, any suggestion where to look? Thanks!

Did you read OH 4 – Replacing MQTT JS transformation to SCRIPT transformation - #21 by rlkoshak in this thread a few posts above yours ?

In openHAB 4.0 SCRIPT transformation was removed, and replaced with meta transformation that uses the scripting language’s abbreviation. For JavaScript it’s JS.

More details can be found here:

So your thing should be defined as:

Thing data hold4746 [ readStart="4746", readValueType="int16", writeStart="4746", writeValueType="int16", writeType="holding", readTransform="JS:divide10.js", writeTransform="JS:multiply10.js"  ]

Note you should rename your transform script file from .script to .js

Or you can use the inline syntax if you prefer.

1 Like

Hi thank you for your reply! I did read but was not sure if it’s the syntax in the final release, so I used the one marked as solution. Thanks for pointing it out!

1 Like

Thank you for the help! I changed to this syntax and it works again!
Now looks like the only problem with modbus is after restart all configured things are gone, have to manually update the things file to bring them back, bumpy journey to upgrade I guess :slight_smile: