How to migrate js transformation rules?

OpenHAB installation: docker based with Ubuntu 22.04

Version 3.4.5 behavior:

  • things file:
Type number : Pressure [stateTopic="tele/multisensor03/SENSOR", transformationPattern="REGEX:(.*BMP280.*)∩JSONPATH:$.BMP280.Pressure∩JS:tasmotaBMP280Pressure.js"]
  • js transformation script
(function (data) {
  var number = parseFloat(data.replace(",", "."));
  number = number + 17.59;
  return number.toString(10);
  • addon configuration in addons.cfg
transformation = map,javascript,jsonpath,regex
  • thing operates as expected: returns data from Tasmota payload, extracts pressure data and tranformation script corrects pressure by altitude appropriately

Version 4.0.3 behavior:

  • Javascript transformation is no longer supported so during startup addon is not loaded
  • Transformation script is ignored in this case and unaltered value is shown. When only script is defined (without other transformations) information about js not found is visible in logs.

In current documentation this feature is still visible: JavaScript Scripting - Automation | openHAB (but here syntax with brackets, not colon which is accepted).

I’ve tried also with SCRIPT:graaljs:tasmotaBMP280Pressure.js but without success.

What is the proper syntax for this kind of transformation. Should I install something (via addons.cfg file)?

It’s always good to review the release notes, especially if there are problems after upgrading.

The JS Transformation no longer exists so remove that from your addons.cfg.

Now there is a generic Script transformation that comes with OH and works with any rules language.

To use JS Scripting as the rules language for your transformation, all you have to do is install the add-on. Your transformation code as well as the config on the Thing can remain unchanged from what it was in OH 3.

As is the case with all transformations, the syntax is slightly different depending on where you are using it: Item label, Item State Description, transform Profile, transform action in a Rule, and different add-ons have their own syntax (MQTT and HTTP being notable).

This is somewhat covered in Transformations | openHAB which is linked to from JavaScript Scripting - Automation | openHAB.

That’s the old 3.4 syntax when the SCRIPT transform was first added. Before OH 4 came out, the syntax was changed so that users of the JS Transformation would have minimal changes necessary to upgrade. All you need to do is install the add-on and remove the old JS Transformation add-on from trying to install which fails because it no longer exists.

Note:JS Scripting is an automation add-on, not a transformation add-on.

Thank you for suggestion.

Line in addons.cfg


fixed issue.

1 Like