The docs say you can launch a script in the /conf/scripts directory from the console using the following syntax:
smarthome:> <script to execute> Executes a script from the conf/scripts folder
However, I can’t get my scripts to launch. For instance, I have a script named “init.script”. I’ve tried calling it a couple of different ways:
openhab> smarthome:> init
___ init
The method or field init is undefined; line 1, column 0, length 4
With .script:
openhab> smarthome:> init.script
___ init.script
The method or field init is undefined; line 1, column 0, length 4
However, I am able to call script actions this way:
openhab> smarthome:> sendCommand(familyRoomLightSwitch, ON)
OK
How do you actually call a script file from the console?
rlkoshak
(Rich Koshak)
February 9, 2017, 10:11pm
2
According to the OH 1.x docs you would use callScript("<scriptname>")
.
Let us know if this works so the OH 2 documents can be updated.
Even that doesn’t work sadly.
openhab> smarthome:> callScript("init")
callScript( ___ init)
The method or field init is undefined; line 1, column 11, length 4
roher
(Victor)
May 9, 2017, 8:23am
4
Hello!
Not sure if it’s still actual, but I have run across the same problem, and found the way how to do it successfully:
openhab> smarthome:> callScript(\"init\")
true
By the way, it’s true for all string names passed into actions in the console, for example:
openhab> smarthome:> sendTelegram(\"home\", \"hello\")
true
Has this changed in the latest version? If I run a smarthome:help
I get a list of commands with the following message
...
...
Usage: smarthome:things trigger <channelUID> [<event>] - triggers the <channelUID> with <event> (if given)
Usage: smarthome:> <script to execute> - Executes a script
When I try to use smarthome:> <script>
in any way I get the following error:
openhab> smarthome:> callScript(\"school_holidays\")
Command not found: smarthome:
It doesn’t matter what I use for the <script to execute>
part.
1 Like
pyjamasam
(Chris Whiteford)
May 1, 2018, 7:29pm
6
Based on my googling/githubbing/and general code crawling, it looks like Karaf added support for redirecting output (similar to how a bash shell does it) on the console.
It uses the > character to do this. (https://github.com/apache/karaf/blob/karaf-4.1.x/shell/core/src/main/java/org/apache/felix/gogo/runtime/Parser.java#L319 )
The new parser is picking up the > character and attempting to redirect insted of letting the scriptengineconsolecommandextension handle it (https://github.com/eclipse/smarthome/blob/4204ce06bb28c28e5f711e720f87ef83beff2e27/bundles/model/org.eclipse.smarthome.model.script/src/org/eclipse/smarthome/model/script/extension/ScriptEngineConsoleCommandExtension.java#L38 )
This is only in the 4.1.x branch of Karaf. It seams somewhere around July of 2017 there was a pull request in openhab to use Karaf 4.1.x (https://github.com/openhab/openhab-distro/pull/484 ).
My suspicion is that this bug has existed since then but only rolled out when 2.2 was released. And there doesn’t look like a way to work around it to execute a script from the console.
An easy fix would be to change the > character used by the ScriptEngineConsoleCommandExtension to something else, but I’ll leave that up to the devs to decide.
chris.
1 Like