Preparation for OH 4.0: How to find my JS transformations?


I’m looking forward for the next OH release. I noticed in the milestone 1 release notes, that there won’t be any JS transformation support in OH 4.0, one should use the SCRIPT transformation instead. I want to prepare my current OH installation for the next release, to make sure I can use it when it is released.

Right now I use JS transformations as described here. In my current OH installation I have probably more than 500 items. I know, that some of them are controlled by three different JS transformations, which are installed as a profile “between” the channel an the item. All of my channels and items are build in the OH3 UI, I don’t have any configuration files.

I’m wondering what is the best way to find the channels, which currently make use of the JS transformations. Do I have to open every single channel of every thing in the OH3 Admin UI to find all of my JS transformation, or is there a more easy way?

I’m also confused about the advice to replace any current JS transformation by SCRIPT transformation. I can’t find a SCRIPT transformation in the OH 3.4.3 and OH 4.0.0 docs. What is meant by “SCRIPT Transformation”?


Check the M2 release notes. It’s back. All you have to do is install one of the two JS Scripting automation add-ons.

You don’t need to but for now the best way would be to just watch the logs. The ID of the Link would be logged out if the Profile were invalid. But it won’t be for Oh 4.0.0 M2 forward.

Alternatively, you can open the links JSONDB file and search for JS to see which ones have the profile.

Profiles aren’t seamlessly compatible. The names of the parameters are different.

In openhab3 it was function, in openhab4 the Params are toItemScript and toHandlerScript

@rlkoshak do you think we should make this fully seamless by supporting the old Params?

@rlkoshak do you think we should make this fully seamless by supporting the old Params?

I wouls say please yes! I also have a few hundred to change.

That’s brilliant news! But to be honest I couldn’t find this information in the release notes. Are you talking about issue 3249?

Thx, I’ll try that.

Ah, okay. I was looking at the wrong place. But there’s documented, that SCRIPT transformation is not available as a profile.

So what do I have to do to be prepared for OH 4.0? There will be JS transformations, but will they also be available in profiles if I install one of the JS automations? As SCRIPT transformations aren’t available in profiles I have to look for an alternative.

Script transformations are available in profiles, have a look at the very latest docs (@rlkoshak you pointed to the stable docs, but this is currently only in the latest docs): Transformations | openHAB

JS transformation IS available for profile starting from Openhab 4 M2, as pointed out by @florian-h05 above. The only issue right now is you’d have to change from:

[profile="transform:JS", function="filename.js"]


[profile="transform:JS", toItemScript="filename.js", toHandlerScript="|input"]

You may not need the toHandlerScript if you aren’t sending command to the item and only receive state updates.

It is supposed to go into the BREAKING changes list, but I don’t know where users should be able to see this. Its buried in there under [4.0.0] heading. I guess the upgrade experience for Milestone builds isn’t meant to be as polished.

It’s now up to the maintainers to accept / reject this.

1 Like

I’m ambivalent. On-the-one-hand it will save a lot of work for people upgrading which would be good. On-the-other it greatly increases the complexity of the profile long term.

If possible, I would like to see a deprecation warning with enough information for users to find the profile in question and then on OH 4.1/4.2 time range remove the old way finally.

Alternatively, if there were a tool that could be added to the upgrade scripts to automatically adjust the old style to the new style that would be great too.

Ultimately, if can be challenging to find and change errant Profiles so anything we can do to prevent that work would be a win.

No, this one: Add dynamic scripting-language transformation service by jimtng · Pull Request #3487 · openhab/openhab-core · GitHub.

In OH 3.4 it’s not.

As @JimT indicates, there is a slight change in the syntax as Profiles now support defining a different transformation each direction (Channel to Item and Item to Channel). You’ll also need to install one of the JS Scripting add-ons (I’d choose the GraalVM one).

The issue you did link to implements SCRIPT transformations as Profiles.

OP is on 3.4 so I pointed to those docs deliberately. OP can’t prepare for OH 4 by using syntax and capabilities that don’t exist in 3.4.

No, changes between milestones are not as polished. We will probably want to write am upgrade tutorial as we get closer to June but it’s probably too early to write right now as things are still changing pretty drastically and we don’t know yet what, if any automatic upgrades might be applied, freeing the need to document it in a tutorial. The final OH 4 release notes will have more details and there will be a corresponding blog post and perhaps more if the past is any indication.

When we went from OH 1 to OH 2 we added an upgrade tutorial to the docs. For OH 2 to OH 3 in leu of an upgrade tutorial we have the Getting Started Tutorial. I’m not sure what will be necessary for OH 3 to OH 4. Most of the new great things in OH 4 are additions but there are a few things like this and the unit changes might need some explanation and require work on the end user’s part.

I have a solution:

  • Leave the current implementation of script profile in core as-is. So if it doesn’t find the toItemScript / toHandlerScript params, it will log a warning. This should be sufficient for text config people - they will need to adjust their config, although I do need to add the link details in the log message.

  • For MainUI created items, I will submit a org.openhab.transform.javascript fake addon to openhab4 addons repo. What this “fake addon” does is convert the main UI item’s links that use profile=“transform:JS” to the new config parameters. It’s a one-off process, and once it has converted the profiles, it does nothing, and it can be uninstalled (obviously preferred), or left alone.

The benefit of this, is for those upgrading from openHAB3, they will automatically upgrade this transform addon, and those who didn’t use JS transform to begin with, are completely unaffected. This also means that people can upgrade from OH3 later on even if they waited until OH 4.3 is out, for example, as long as we keep the fake addon around so it can be installed / upgraded to.

So basically all they need to do after upgrading to and booting up OH4 is to uninstall the javascript transform addon.

I have already tested this solution on my system and it works. I’ll push it sometime tomorrow after I’ve written a unit test and readme for it.

Tagging @J-N-K here since we also discussed this in the PR and the PR will be closed.

Since you can also link text items in UI, this is not a very good solution. We should integrate that in the CLI upgrade tool. and fix the profile there.

Could you please explain what this means? Ohh I get it now. The link can probably also be updated, but I haven’t tried this yet.

That is another option. Is it easy to do? I’m not familiar with the cli upgrade tool.

I’ve tested this scenario, and it works too.

Add-on should never mess with configuration, this is totally anti-pattern. The PR for the tool is here: Initial contribution of an CLI upgrade-tool by J-N-K · Pull Request #3268 · openhab/openhab-core · GitHub.


Cool! Should get that tool merged ASAP so people can start using it

OK, I opened the file and searched for the keyword function. Like this I could easily find all my current JS transformations used in profiles.

I understood, that currently I’m not able to prepare for OH 4.0 concerning to this JS transformations in profiles. It looks like in future I have to use SCRIPT transformations in profiles, but they are not available for profiles in OH 3.4, I have to wait for 4.0. Maybe there will be a migration script, maybe not. We will see. I keep the eyes open to the release notes.

Thx a lot!

1 Like

No, you still use “JS”, but the syntax after that is slightly different in 4.0, for now. There might be an automated update, there might not be.

“SCRIPT”, as a term end users will use in their configs only exists in OH 3.4 to OH 4.0 M1. OH 4.0 M2 forward no longer uses “SCRIPT” in the configs at all.

There will be an upgrade tool to migrate JS Profile


Nice! Thank you very much!

@rlkoshak , sorry to bother you, however I just upgraded to OH4 and have now issues with my .js files, which are in the transfromation folder. My divide10.js file looks like:

(function(inputData) {
    var DIVIDE_BY = 10;
    return parseFloat(inputData) / DIVIDE_BY;

I use the .js for the following:

Bridge modbus:tcp:Pool [ host="", port=502, id=1, connectMaxTries=3, connectTimeoutMillis=1000] {
	Bridge poller holding_low [ start=0, length=24, refresh=3000, maxTries=2, type="holding"]{
       	Thing data holding1		[ readStart="1", readValueType="int16", readTransform="JS(divide10.js)", writeStart="1", writeValueType="int16", writeType="holding", writeTransform="JS(multiply10.js)" ]

I understood that in OH4 one has to install the automation java script scripting add-on (and not the transformation add-on, which does not exist anymore). Is something else needed? Do I need to move my .js files in another folder and ist anything else needed? In any case I have the impression it is not working at the moment.

Any help would be highly appreciated