Javascript Transformation "service not found"

  • Platform information:
    • Hardware:i5
    • OS: Ubuntu 24.04
    • Java Runtime Environment: 17
    • openHAB version: 4.3

I am using a transformation to remove the unit from an item before sending it to the thing.
I am 99% certain that everything was working fine until, maybe, when I upgraded to 4.3.

Thing relevant code

  - id: Set-Point
    channelTypeUID: mqtt:number
    label: Set Point Heating
    description: Temperature set point
    configuration:
      unit: °F
      min: 50
      formatBeforePublish: '{"value":%d}'
      transformationPatternOut:
        - config:js:21024793d7
      max: 80
      commandTopic: zwave/Living_Room/Thermostat/67/0/setpoint/1/set
      stateTopic: zwave/Living_Room/Thermostat/67/0/setpoint/1
      transformationPattern:
        - JSONPATH:$.value

The function (transformation) I am using is

(function(data) {
  var returnValue = data.split(" ");
  return returnValue[0]
})(input)

And the error is

20:37:17.144	WARN	org.openhab.core.thing.binding.generic.ChannelTransformation$TransformationStep	Failed to use TransformationStep{serviceName='CONFIG', function='js:21024793d7'}, service not found

I have JS Scripting installed

Thanks for any suggestions

This appears to be a bug/regression. see below

Thanks

For now removing the units in the channel definition so that I don’t have to remove it when sending commands fixes the problem.

Sorry… false alarm.

Please change your transformationPatternOut from config:js:21024793d7 to JS(config:js:21024793d7) - but JS:config:js:21024793d7 would also work. Both JS(xxx) and JS:xxx are supported syntaxes.

Did this use to work with your original config?

That fixed it. I am sure this was working when I set it up, because this was the first time writing a function other than additions or subtractions and I needed to make sure it was working. But maybe I followed the correct syntax then and later I made some edits and used the copy UID link and pasted the value in the thing channel configuration

I need to take a look at my other transformations.

Thanks for the quick reply.

I tested your original config in 4.2.3 - it didn’t work either. It too issued the exact same warning in the log.

The only difference is that in 4.2.3 when the transformation failed, it would pass through the original data, untransformed. In 4.3, the untransformed data is discarded and not sent out.

Since your transformation is subtle, you might not have noticed the issue.

PS you could also use REGEX transform if you just want to extract the first word

REGEX:(\S+).* would do the same, and it’s “lighter” than JS.

With Regex, the first capturing group is returned, so here we capture non whitespace characters that appear at the beginning of the match.

Note: this would transform " abc" to “abc” so it’s not quite the same. Your JS would transform this to blank.

Thanks again

Question
The change fixed the issue in the channel definition. I also have a transformation in a profile as follows

And this works, or at least it did until a few days ago when the sensor I was using stopped working :frowning:

Is there a difference in how javascript should be called depending on the openhab “location” ?

This configuration is correct. You’ve selected the profile transformation type as “ECMAScript”, so inside “Thing to Item Transformation” you just need to enter the transformation function (in this case the transformation uid)

In file-based config, you’d have written the profile as something like this:

String TestStringItem { channel="xxxxx" [ profile="transform:JS", toItemScript="config:js:xxxxxx" ] }

Also another tip: you can, and probably should, name your transforms with a descriptive id. So instead of 21024793d7, you could call it extract_first_word. This would make for a much more readable config

transformationPatternOut:
  - JS:config:js:extract_first_word

I was under the impression that most zwave thermostats understand units (maybe yours is different). It is part of Silab spec. I don’t use a transform and they work fine.

  - id: Main_Floor_Heating_Setpoint_n
    channelTypeUID: mqtt:number
    label: Main Floor Heating Setpoint
    configuration:
      unit: °F
      min: 60
      formatBeforePublish: "%.0f"
      max: 70
      commandTopic: zwave1/Thermostat_-_62/thermostat_setpoint/endpoint_0/setpoint/1/set
      stateTopic: zwave1/Thermostat_-_62/thermostat_setpoint/endpoint_0/setpoint/1
      transformationPattern:
        - JSONPATH:$.value

I am starting to think that you are right and that I overthought the issue from the beginning.

If my transformation was always ignored and the string was sent without removing the units, then I have to conclude that the thermostat understood the command. The problem arose when Openhab 4.3 started discarding the command when it could not process the transformation.