Execute Script with karaf

  • Platform information:
    • Hardware: Raspi 3
    • OS: Debian stretch
    • Java Runtime Environment java version “1.8.0_171”
    • openHAB version: 2.4.0

Hello,
on the page “https://www.openhab.org/docs/administration/runtime.html#automation” you wrote, we can ececute some scripts. So I create a file “/home/pi/hab/conf/thingInfo.script”, which is readable for all users.
But when I try to call it, I’ll get the error:

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown openHAB.

openhab> smarthome:> thingInfo
Command not found: smarthome:
openhab> smarthome:>thingInfo
Command not found: smarthome:
openhab> smarthome:
Command not found: smarthome:
openhab> smarthome:>
redir> 
redir> ^CingInfo
redir> thingInfo
redir> 
openhab> smarthome:>
redir> thingInfo
redir> ^C
openhab> smarthome:>thingInfo
Command not found: smarthome:
openhab> smarthome:>thingInfo.script
Command not found: smarthome:
openhab> smarthome:> thingInfo.script
Command not found: smarthome:
openhab>

and so on, but nothing will happend. The content of the scriptfile:


var thingName = “zwave:device:18af13d3:node3”
var thingStatusInfo = getThingStatusInfo(thingName)

if ((thingStatusInfo !== null) && (thingStatusInfo.getStatus().toString() == "ONLINE")) {
    logInfo("ThingStatus", "The thing is online.")
} else {
    logError("ThingStatus", "The thing is offline or doesn't exist.")
}

What I do wrong? Must I load an extension to karaf? I’d not found some info about this problem…

Sincerely
Jens

openhab> smrarthome:help
Gives:
Usage: smarthome:script <script to execute> - Executes a script

So I tried:
openhab> smarthome:script test.script
And that gives:

 ___ test.script
   The method or field test is undefined; line 1, column 0, length 4

The contents for test.script

logInfo("TEST", "SCRIPT")

So 2 issues here:
1 - The docs are incorrect and it should be smarthome:script <script to execute> (I’ll do a quick PR for that)
2 - It doesn’t work (I don’t know why)

1 Like

I try, and thats the same problem:
openhab> smarthome:script “thingInfo.script”
___ thingInfo.script
The method or field thingInfo is undefined; line 1, column 0, length 9
openhab> smarthome:script thingInfo
___ thingInfo
The method or field thingInfo is undefined; line 1, column 0, length 9
openhab> smarthome:script “thingInfo”
___ thingInfo
The method or field thingInfo is undefined; line 1, column 0, length 9
openhab> smarthome:script

, it seems, it’s a problem with the karaf konsole. But it had run in the past, I’d read it on a (older) topic here…
So I’ll try to start the script within a rule.

2 Likes