Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ECMA integration #2056

Closed
Boby71 opened this issue Jan 2, 2021 · 6 comments
Closed

Improve ECMA integration #2056

Boby71 opened this issue Jan 2, 2021 · 6 comments

Comments

@Boby71
Copy link

Boby71 commented Jan 2, 2021

The built-in executeCommandLine command doen't work in rules:

Rule:
triggers:
  - id: "1"
    configuration:
      cronExpression: 0 0 8 * * ? *
    type: timer.GenericCronTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript
      script: executeCommandLine("/etc/openhab/bla.sh");
    type: script.ScriptAction

Result in the logfile:

2021-01-02 23:00:43.873 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'test' failed: ReferenceError: "executeCommandLine" is not defined in <eval> at line number 1

DSL rules don't show this problem - calling executeCommandLine there works fine.

@Boby71
Copy link
Author

Boby71 commented Jan 3, 2021

Found the solution! The reason is a 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");

I leave this issue open until someone can update the documentation. Thanks!

@Boby71 Boby71 changed the title [OH3.1 - build 2111]: executeCommandLine doesn't work in ECMA rules [OH3.1 - build 2111]: executeCommandLine doesn't work in ECMA rules (documentation issue) Jan 3, 2021
@Confectrician
Copy link
Contributor

@kaikreuzer maybe we should go on here with our discussion based on openhab/openhab-docs#1414 to get seom progress for ECMA Script implementation and also improve the docs with some proper explanations/tutorials.

@kaikreuzer
Copy link
Member

Hm, I guess we only need someone who can fix this issue - since it seemed to work in the past, I assume it should be possible to make it work again...

@Boby71 Boby71 changed the title [OH3.1 - build 2111]: executeCommandLine doesn't work in ECMA rules (documentation issue) [OH3.1 - build 2111]: Improve ECMA integration Jan 10, 2021
@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/syntax-for-sendhttpgetrequest-in-oh3-ecma-script/111863/8

@wborn wborn changed the title [OH3.1 - build 2111]: Improve ECMA integration Improve ECMA integration Oct 13, 2021
@J-N-K
Copy link
Member

J-N-K commented Jun 24, 2022

@kaikreuzer After re-reading this issue several times: I think it works for DSL rules (and did that in the past), but I don't think it ever worked for JS rules. And IMO the correct way is indeed to import the Java type of the core actions, we should not magically inject something. I would vote for closing this issue.

@kaikreuzer
Copy link
Member

Ok, in that case let's indeed close the issue - but we might want to revive the documentation update openhab/openhab-docs#1414 then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants