that works - thanks a lot.
But i have to use the script directly inside a rule. When I execute the same script (in the folder script) separately then the trigger-item doesn’t come. the result is “undefined”.
I use following script:
console.info('-----------------------------');
var myList;
var room;
myList = String(event.itemName).split('_');
room = myList[1];
console.info('testlog: ' + room);
items.getItem('Jalousien_' + room).sendCommand('100');
console.info('-----------------------------');
what could be the solution? in OH3 it was no difference to use script outside of the rules.
Thanks for your support!
i would like to create a Rule which get trigger, when a member of the groupitem “gFenster” changed (a window gets closed or open). In this case a script (in which i would read the trigger-item (window) ) should be run. I would like to have the script separately in case i must use with an oder rule.
You can’t do it like that. The called rule does not automatically inherit the variables that exist in the calling rule. So there is no event.itemName to access.
Don’t do that. Wait until you have an absolute need to use it in an other rule. And then first consider how you might combine those rules into one.
Having a rule call another rule should be the exception, not the rule and definitely not something you should do “just in case”.
In those cases where you do need to have a rule call another rule, the called rule must either assume it will be passed nothing, or you will have to pass to the rule everything that the rule needs. Of course, you won’t be able to use the “run a rule” UI action to do that. You’ll have to create a Script Action to gather all the data you want to pass to the rule into a Map and then include that Map as part of the call to the rule.
Blockly’s run a rule block supports this.
But especially given what this proposed rule does, I’d recommend creating a new Block Library (under Developer Tools → Block Libraries, see Tutorial: How To Write Block Libraries (also linked to from the official docs).