Passing parameter to transformation script

  • Platform information:
    • Hardware: Orange Pi 3 lts
    • OS: armbian
    • Java Runtime Environment: openjdk 21
    • openHAB version: 5.0.1
  • Issue of the topic: briefly search the community I fount that it could be impossible, but still don’t believe that such a base feature don’t work.

I assume the DSL as the first\main\base scripting language inside openhab (maybe I’m wrong)

So for one of transformations in modbus binding I use small DSL script and it works well, however when I try to pass the parameter to it like DSL(config:dsl:9a48d8ad72?param=100) besides it still runs well (considering the syntax for passing works), since I try to get the param variable inside script - it falls with error.

PS: I write the script in UI, so don’t use the file based config, on fresh system after reinstall on new hardware.

PPS: in docs looks like it should work Transformations | openHAB

Not really. I’d call it the first legacy scripting language. But any of the other options will be as easy to get started in these days and provide a more complete set of capabilities. There’s lots that Rules DSL cannot do.

This is one of those things that Rules DSL cannot do. I don’t think there is a way to access the stuff that’s passed into the script in this way.

Rules DSL can be used in a Script Transformation certainly. But you can’t pass anything into the script like you can with the other languages. Or stated more precisely, you can pass the arguments but there’s no way to retrieve them inside the script.

If you need to do this, you need to use any of the other rules language options.

First of all - thanks for the answer, but I am a bit disappointed ))

  1. why there are no info about that DSL scripts can’t get parameters in docs?

  2. I just install groovy scripting and try to pass parameter there - still no success (

  3. by investigation of this file openhab-core/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java at main · openhab/openhab-core · GitHub looks like parameters parsed by rexes independently of the script lang type

  4. somehow any script gets parameter “input” injected, so there are some mechanism to pass parameter exists

  1. :person_shrugging: Because no one has volunteered to add that to the docs?
  2. I can’t help with Groovy. My understanding is it’s possible but I have no experience with Groovy.
  3. Indeed, the parameters are injected by OH core to all languages. But the language needs to have a way to access that parameter. There is no way to access it in Rule DSL. For jRuby and JS it’s as simple as referencing the variable by name. Maybe Groovy has a context Object or something like that.
  4. Indeed, otherwise there’s be no point to the transformation. But the other passed in arguments are handled through a different mechanism as far as I understand it. And for Rules DSL there is special handling required to make input available to the script that runs.