How to Setup Jython

I’m testing on an i7, so hardware does not seem to be the issue. :wink:

1 Like

Yes, rules seem to work. Here’s the rule from this morning and it runs on each restart.

2018-10-09 11:21:00.610 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_startup.py'

2018-10-09 11:21:00.773 [INFO ] [eclipse.smarthome.model.script.Rules] - JSR223: Startup: Checking for initialized context

2018-10-09 11:21:00.795 [INFO ] [eclipse.smarthome.model.script.Rules] - JSR223: Startup: context initialized... waiting 30s before allowing files to load

2018-10-09 11:21:30.799 [INFO ] [eclipse.smarthome.model.script.Rules] - JSR223: Startup: Complete

i’ll let you know - hopefully in the next hour or so

This is what we are looking to see in the log on startup (from my production box)…

2018-10-05 23:58:01.531 [INFO ] [org.eclipse.smarthome.automation.module.script.internal.GenericScriptEngineFactory] - Activated scripting support for ECMAScript
2018-10-05 23:58:01.539 [DEBUG] [org.eclipse.smarthome.automation.module.script.internal.GenericScriptEngineFactory] - Activated scripting support with engine Oracle Nashorn(1.8.0_181) for ECMAScript(ECMA - 262 Edition 5.1) with mimetypes [application/javascript, application/ecmascript, text/javascript, text/ecmascript] and file extensions [js]
2018-10-05 23:58:01.540 [INFO ] [org.eclipse.smarthome.automation.module.script.internal.GenericScriptEngineFactory] - Activated scripting support for python
2018-10-05 23:58:01.548 [DEBUG] [org.eclipse.smarthome.automation.module.script.internal.GenericScriptEngineFactory] - Activated scripting support with engine jython(2.7.0) for python(2.7) with mimetypes [text/python, application/python, text/x-python, application/x-python] and file extensions [py]

From test system (no Jython)…

2018-10-09 12:58:05.990 [INFO ] [.internal.GenericScriptEngineFactory] - Activated scripting support for ECMAScript
2018-10-09 12:58:05.991 [DEBUG] [.internal.GenericScriptEngineFactory] - Activated scripting support with engine Oracle Nashorn(1.8.0_181) for ECMAScript(ECMA - 262 Edition 5.1) with mimetypes [application/javascript, application/ecmascript, text/javascript, text/ecmascript] and file extensions [js]

I’m starting to think there’s something silly stupid that we’re missing, but I’ve checked everything I can think of between my two systems and they appear setup the same.

Just restarted to verify with debug on and looks like everything is there.

2018-10-09 12:12:04.390 [INFO ] [.internal.GenericScriptEngineFactory] - Activated scripting support for python

2018-10-09 12:12:04.412 [DEBUG] [.internal.GenericScriptEngineFactory] - Activated scripting support with engine jython(2.7.0) for python(2.7) with mimetypes [text/python, application/python, text/x-python, application/x-python] and file extensions [py]

2018-10-09 12:12:04.417 [INFO ] [.internal.GenericScriptEngineFactory] - Activated scripting support for ECMAScript

2018-10-09 12:12:04.431 [DEBUG] [.internal.GenericScriptEngineFactory] - Activated scripting support with engine Oracle Nashorn(1.8.0_152) for ECMAScript(ECMA - 262 Edition 5.1) with mimetypes [application/javascript, application/ecmascript, text/javascript, text/ecmascript] and file extensions [js]

Oracle Nashorn(1.8.0_152) your version is newer but that’s the only thing I see different.

I removed the jar file from /boot and checked that I only had one jar on the system. The cache and tmp are clean.
Now I’m missing Activated scripting support for python, ECMAScript is good but now it’s back to “ScriptEngine for py not available”

Where is your start.sh file located? Hopefully in /etc/openhab2/.

Start.sh is located in /usr/share/openhab2

O man… I knew it was going to be silly stupid :roll_eyes:. I thought using the DIRNAME variable in start.sh would help in case someone had a non-standard installation. It is defined as…

DIRNAME=`dirname "$0"`

This gives it the value of the path used to launch the script, and I’ve been using ./start.sh, so the paths were all messed up and the Jython script engine never loads!

You have a similar issue… I assumed incorrectly that the apt installs had start.sh in /etc/openhab2. SO… the solution is to just use this in your EXTRA_JAVA_OPTS…

export EXTRA_JAVA_OPTS="-Xbootclasspath/a:/etc/openhab2/automation/jython/jython-standalone-2.7.0.jar \
-Dpython.home=/etc/openhab2/conf/automation/jython \
-Dpython.path=/etc/openhab2/conf/automation/lib/python"

ok, up to 2.4 snapshot! :slight_smile:

copied jython 2.7 jar in the home folder of openhabian from my windows pc. should I copy it somewhere else on the PI3?

found start.sh in the usr/share/opehhab2 folder. note sure how I should setup these settings…

I just fond that out!!! As you were typing I was trying to stop the 000_HelloWorld.py from eating up the logs…:grinning: But it’s working!!!:sunglasses:

2018-10-09 13:36:50.718 [DEBUG] [er.handler.GenericCronTriggerHandler] - Scheduled cron job '0/10 * * * * ?' for trigger 'Cron-hellowWorldDecorator-47189e40cbf211e8be6bb827ebd7492b'.

==> /var/log/openhab2/events.log <==

2018-10-09 13:36:50.738 [.event.RuleStatusInfoEvent] - 4992f30d-aa05-4f03-8425-0e2fadd7328b updated: IDLE

==> /var/log/openhab2/openhab.log <==

2018-10-09 13:36:50.741 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 001_HelloWorld.py

2018-10-09 13:36:50.745 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'test.py'

2018-10-09 13:36:50.803 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: test.py

2018-10-09 13:36:50.807 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'test1.py'

2018-10-09 13:36:50.841 [INFO ] [clipse.smarthome.automation.examples] - Hello jython world!

2018-10-09 13:36:50.845 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: test1.py

2018-10-09 13:36:50.849 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'testing_example.py'

2018-10-09 13:36:56.104 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/testing_example.py': ImportError: cannot import name item_triggered in <script> at line number 13

2018-10-09 13:36:56.108 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: testing_example.py

2018-10-09 13:37:00.087 [DEBUG] [omation.core.internal.RuleEngineImpl] - The trigger 'Cron-hellowWorldDecorator-47189e40cbf211e8be6bb827ebd7492b' of rule '4992f30d-aa05-4f03-8425-0e2fadd7328b' is triggered.

==> /var/log/openhab2/events.log <==

2018-10-09 13:37:00.100 [.event.RuleStatusInfoEvent] - 4992f30d-aa05-4f03-8425-0e2fadd7328b updated: RUNNING

==> /var/log/openhab2/openhab.log <==

2018-10-09 13:37:00.130 [DEBUG] [omation.core.internal.RuleEngineImpl] - The rule '4992f30d-aa05-4f03-8425-0e2fadd7328b' is executed.

==> /var/log/openhab2/events.log <==

2018-10-09 13:37:00.142 [.event.RuleStatusInfoEvent] - 4992f30d-aa05-4f03-8425-0e2fadd7328b updated: IDLE

==> /var/log/openhab2/openhab.log <==

2018-10-09 13:37:10.075 [DEBUG] [omation.core.internal.RuleEngineImpl] - The trigger 'Cron-hellowWorldDecorator-47189e40cbf211e8be6bb827ebd7492b' of rule '4992f30d-aa05-4f03-8425-0e2fadd7328b' is triggered.

==> /var/log/openhab2/events.log <==

2018-10-09 13:37:10.082 [.event.RuleStatusInfoEvent] - 4992f30d-aa05-4f03-8425-0e2fadd7328b updated: RUNNING

==> /var/log/openhab2/openhab.log <==

2018-10-09 13:37:10.082 [DEBUG] [omation.core.internal.RuleEngineImpl] - The rule '4992f30d-aa05-4f03-8425-0e2fadd7328b' is executed.

==> /var/log/openhab2/events.log <==

2018-10-09 13:37:10.095 [.event.RuleStatusInfoEvent] - 4992f30d-aa05-4f03-8425-0e2fadd7328b updated: IDLE

==> /var/log/openhab2/openhab.log <==

2018-10-09 13:37:20.063 [DEBUG] [omation.core.internal.RuleEngineImpl] - The trigger 'Cron-hellowWorldDecorator-47189e40cbf211e8be6bb827ebd7492b' of rule '4992f30d-aa05-4f03-8425-0e2fadd7328b' is triggered.

Just need to put the esper back where it belongs.

@5iver when you update the repo it may be good to mention that EXTRA_JAVA_OPTS must be on one line. I mention this b/c the doc’s are written like this:

EXTRA_JAVA_OPTS=-Xbootclasspath/a:/home/pi/jython2.7.0/jython.jar \
  -Dpython.home=/home/pi/jython2.7.0 \
  -Dpython.path=/etc/openhab2/lib/python

If you place this in extra java opts it will cripple the entire OH. Found that out a while back when testing other things.

You don’t need the esper modules or the component script. I don’t know what they are for and I think I will removed them from this branch. Also, if you are not using the components, there’s no need to install them either. I’ll clean that up in the repo too.

And if anyone wants a way to use the DIRNAME variable in the EXTRA_JAVA_OPTS, use this…

DIRNAME=`dirname $(realpath "$0")`

If not using the DIRNAME like above then here is an example of what EXTRA_JAVA_OPTS should look like.

It will work if you are defining EXTRA_JAVA_OPTS in start.sh. If using an /etc/default/openhab file, you’re not in a shell script, so can’t use the shell escape character.

I’ll put something in the doc. Thank you!

ok, I am seeing

ScriptEngine for py not available

That’s what I learned a while back.:roll_eyes: Just wanted to give an example pic for others that may not understand all the Linux lingo, etc…

It would be a bad day for someone who’s never made a backup.:open_mouth:

1 Like

What are you using for EXTRA_JAVA_OPTS? Check our recent posts for the solution.

I am changing it so that all the code is on one line - I had it as per the readme file

In /usr/share/openhab2/start.sh or /etc/default/openhab2 ?

Your fine if using the first but OH rep install don’t like it there. Need’s to be in /etc/default/openhab2 EXTRA_JAVA_OPTS like in the pic posted above.