OH3 pass Variable from rule to script

Is there a possibility to call a script from a rule within openhab 3.1 and pass variables to it? I would like to write generic scripts that can be reused. But I don’t like the idea to use a item to transfer a variable from one rule to another. This is somehow limited as I can not pass e.g. a Timer. Or if the script is triggered two times simultaneously I have a problem that only one state will arrive.

No, there isn’t. (At least I’m not aware of any changes in question of this).

ok thanks for the response. I opened an issue on GitHub for this. Hopefully we will get some possibility in the future. https://github.com/openhab/openhab-core/issues/2475

This is currently only possible inside scripted rules (like a .js file).

There is a circumvention to that.
While an Item state is a sort of “global variable”, and someoneelse might come along and change it before you’ve processed it …
an Item command is an event, no-one else can change it, send as many as you like and each is unique. In OH3 rules, processing of each command is neatly queued for you as well.

2 Likes

I replied on the GitHub issue before seeing this thread. See the issue for examples for how to do this in JavaScript. tl;dr it’s not possible in Rules DSL but quite well supported in just about all the other rules languages.

Hello dear developers,
as im new to openHab i want to adress (i think) the same topic.
I wrote a rule from dimming my lights stepwise from Off to 100% or the other way around.

Now i want to deploy that to every light switch in the house but i dont want to create a rule for every switch.

Therefor i would like to use a script:

Pseudo Code:

when
Item livingRoomDimmerItem received update)
then

callScript(“StepwiseDimmingAction”, livingRoomDimmerItem, dimmingDirection)

My question would be, can i parse the Items (livingRoomDimmerItem, and dimmingDirection) to the script somehow?