OH3.1 - 2111: ReferenceError: "executeCommandLine" is not defined in <eval>

Tried to migrate an old DSL rule to JavaScript, but I always get the following error message:

Script execution of rule with UID ‘pyduofern_az_spielplatz’ failed: ReferenceError: “executeCommandLine” is not defined in at line number 14

Here’s the script:

var logger = Java.type("org.slf4j.LoggerFactory").getLogger("org.openhab.rule." + ctx.ruleUID);
var received_command = itemRegistry.getItem('pyduofern_az_spielplatz').getState();
var ScriptResponse = ""
logger.info("Rule wurde getriggert. Empfangener Befehl: " + received_command);

switch (received_command)
  {
    case ON: 
      ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "python3","/etc/openhab/_duofern/duofern_cli.py", "--up", "495dbd", "--configfile", "/etc/openhab/_duofern/.duofern.json");
      logger.info("RC=" + ScriptResponse);
      break;
      
    case OFF:
      ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "python3", "/etc/openhab/_duofern/duofern_cli.py", "--down", "495dbd",  "--configfile", "/etc/openhab/_duofern/.duofern.json");
      logger.info("RC=" + ScriptResponse);
      break;
      
    default:
      logger.info("Unbekannter Befehl - keine Aktion gestartet");
  }

Where’s my error? Thanks!

1 Like

Found the solution! The reason is lack of information in the documentation. Don’t know where and how to change the docu, but for others running into this problem, this would be helpful. here it goes:

You need to include the following line into your ECMA script:
var Exec = Java.type("org.openhab.core.model.script.actions.Exec");

And the call of the function is like:
Exec.executeCommandLine("command");

2 Likes