[SOLVED] JSR223/Jyton setup problems

Moving from this topic as @5iver suggested.

Quick recap:
I followed the quick start guide from jython repo but run into few problems.

The one that I’m trying to solve right now prints in log this message:

[ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/hello_world.py': ImportError: No module named core in <script> at line number 3

the hello_world.py literally the one from Jython repo, the line number 3 is:

from openhab.triggers import when, CronTrigger

I just downloaded again zip of master branch, replaced jython files, rebooted my RPI and problem is still here :frowning:

I already searched a bit for a solution but didn’t find anything useful :confused: Any tips how I can debug/fix this issue?

Hi, @sonko,

Let’s see if we can get to the bottom of the error. First question, what version of openHAB do you have installed? You should be running a recent 2.4.0-SNAPSHOT or the latest 2.4.0 milestone build.

So the hello_world.py you are trying to run is a copy of Script Examples/hello_world.py, which in turn is from the master branch Zip archive that you downloaded from GitHub. My guess (with little evidence to support my guess) is that you do not have a JSR223 startup delay script in place and all of the Jython support modules were loaded before OpenHAB’s JSR223 automation machinery was “ready.” On my system I have the file 000_0_delay_startup.py located in /etc/openhab/automation/jsr223/ that prevents the Jython support modules from loading until the JSR223 scripting subsystem is ready to go. The contents of that file are:

import time                                                                                                                                                                                                                                                                                                                                                                                  
from org.slf4j import Logger, LoggerFactory                                                                                                                                                                                                                                                                                                                                                  
logger = LoggerFactory.getLogger("org.eclipse.smarthome.model.script.Rules.jsr223")                                                                                                                                                                                                                                                                                                          
logger.info("Startup: Checking for initialized context")                                                                                                                                                                                                                                                                                                                                     
while True:                                                                                                                                                                                                                                                                                                                                                                                  
        if automationManager != None:                                                                                                                                                                                                                                                                                                                                                        
            logger.info("Startup: context initialized... waiting 30s before allowing files to load")                                                                                                                                                                                                                                                                                         
    logger.info("Startup: Context not initialized yet... waiting 10s before checking again")                                                                                                                                                                                                                                                                                                 
logger.info("Startup: Complete")                                                                                                                                                                                                                                                                                                                                                             

Try creating a copy of this script named 000_0_delay_startup.py and place it in /etc/openhab2/automation/jsr223/. Once you have done that, restart your system.

There is a thread here in which this is discussed. I’ll track it down and add a link in this reply when I find it. Found it,

That entire thread is worth reading.


I’m running openHAB 2.3 release build (on RPi 0W if it makes any difference), I already encountered the problem with modules loading and have the delaying script in place and running, even with the same code as yours because I got my code from the linked thread :wink: I will read trough it again.

As @scottk stated you should update your OH.

There’s a older branch for 2.3 in github if you somehow can’t or won’t update to 2.4

1 Like

See post #37 of the thread I referenced. You need to be on a 2.4 build to use the @rule and @when decorators.

oh, in the readme I saw big openHAB 2.x and then just skipped to getting started since 2.3 is 2.x :sweat_smile:
ok I will try to update OH and let you know if it fixed the problem

I switched to latest snapshot version, got some errors and OH didn’t even loaded all modules, seeing that I just switched to the milestone build - 2.4.0.M5, added again EXTRA_JAVA_OPTS because they got deleted, reboot and it hello_world is working! :tada: :smile:

If I will have some questions regarding rules I am about to write should I just post them here or start new thread? :thinking:

1 Like

@sonko, I’m happy to hear you solved your problem. This community is great for helping with such issues, so don’t hesitate to ask if you get stumped with a problem.

A new thread would probably be best, makes it easier for others to search for issues like yours in the future. Also, please mark this topic as solved.

Have fun with OH2!

+1 on what Scott is saying. Open a new thread with proper title that describes the problem. And remember to tag them like you did with this post. It really helps future searchers :+1:

Glad you got everything sorted! I’m still puzzled by the error you were getting though, since the only way you could get this error is if I mistakenly updated files in master, or if you were using files from the restructuring branch. I’ve searched all of the file in master, but do not see any reference to ‘core’, so it must have been the latter. Were you definitely only using files from master?

@5iver, that puzzled me too. I’m guessing it could be related to one of the java imports, e.g., org.eclipse.smarthome.config.core.

It’s odd for me to see that error, since I was just seeing the same one when renaming the openhab package. But you’re right… from org.eclipse.smarthome.automation.core.util import TriggerBuilder (and possibly others) wouldn’t be possible in OH 2.3.

100% unless this is some other jython repo.

Anyway I would suggest adding somewhere at top of the quick start guide point like “Make sure you are running OpenHAB snapshot build 1318 (or newer) or OpenHAB milestone build 2 (or newer).” (dont know if milestone version is right) since “inviduals” like me may miss info from the main readme file :sweat_smile:

1 Like

All of your image links give me 404s. :smile: (you can paste them right into the forum). The error must have been from one of the ESH imports.

It’s very helpful getting feedback from people getting started up on JSR223-Jython, with fresh eyes on the docs. Keep it coming, and thank you! I’ll update the readme in the open PR, which will hopefully be merged this weekend. Also, don’t hesitate to make corrections yourself and submit a pull request, you can do it through your browser… no IDE required!