How to Setup Jython

ok, its working :slight_smile: :slightly_smiling_face:

I removed the quotes around the line…

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

will Lucid work with this version of the jython library?

Not sure, you may have to test and see. This is the first time to install jython for me, I was more along for the install testing, maybe try and help Scott as well as the community.

But, guess now I need to start learning how to code and remove the Rules DSL prop.:smile:

@5iver anything else to try with apt install?

Sounds like we are doing the same thing. I am guessing the purpose of lucid is to make it easier to create rules using jython…

Not yet, but I’m sure @RRoe will be wanting to include it after any issues get flushed out. Lucid hasn’t been updated for the API changes, so will only work with 2.3.

1 Like

Please use the other thread for asking question about the new decorators. I’m excited to have some more people using Jython and able to test them out! Thank you!

1 Like

Not that I can think of. It was the install that I wasn’t sure of, but I think we got it all squared away.

thank you for the help - will post questions in the thread you linked above

1 Like

I was going to suggest I start over with a fresh install, I made lots of moves and permission changes, but I think @mjcumming proved the install is good.

Thanks

1 Like

Hi i restarted and followed your new Instructions. When i get to the point to restart i get the following error message for multiple of the files and in different lines:

2018-10-11 19:54:40.964 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/000_components/000_DirectoryTrigger.py': TypeError: can't set attributes of built-in/extension type 'NoneType' in <script> at line number 8

However in the end they seem to be all loaded.

Testing with the hello world script works as well

If you aren’t going to use the component scripts, then there is no need to install them. I think I should move them into a separate folder, like the Script Examples.

Line 8 is import openhab, so my guess is that the scripts are loading before the modules are fully loaded. This is a known bug, similar to the Rules DSL loading scripts before tiems are fully loaded. You could try adding this script to delay the loading of the other scripts (including the components). Name it 000_startup.py and put it in the root of /automation/jsr223/. Hopefully that helps. I use this script and do not see the same errors you are reporting. If this resolves it, I’ll add it to the repo.

import time

from org.slf4j import Logger, LoggerFactory
log = LoggerFactory.getLogger("org.eclipse.smarthome.model.script.Rules")

log.info("JSR223: Startup: Checking for initialized context")

while True:
    try:
        scriptExtension.importPreset("RuleSupport")
        if automationManager != None:
            log.info("JSR223: Startup: context initialized... waiting 30s before allowing files to load")
            break;
    except:
        pass
    log.info("JSR223: Startup: Context not initialized yet... waiting 10s before checking again")
    time.sleep(10)

time.sleep(30)
log.info("JSR223: Startup: Complete")

Scott. I am assuming this works because there is only one thread loading rules?

Correct. And files are loaded in a particular order.

If this is the problem, here is the issue for it. There was a recent change that made this better, and I thought it was resolved, but on slower hardware or a startup during high load, it can still happen…

The above error still pops up but the other ones are all gone

After a restart last night, I was kind of expecting that you’d have the same. :disappointed:

I’ll play with it… likely an issue with the loading order. Best to remove any components that you aren’t planning to use.

Will do. Thanks for your help and this awesome work!! I think it might make sense to maybe have a wiki page which collect all different Jython example rules. Similar to what we had for Openhab for the integrated rule engine. Will start testing a bit over the weekend

I agree. I’ve tried to include everything people have asked about into this readme, but I could also add a wiki for others to contribute to. I was also going to build out the example scripts too.

All I’ve done is piggyback on the much appreciated work of others and add some bling… and hopefully pump some life back into the new rule engine. But you are very welcome for anything I have been able to contribute!

@5iver I was looking at the error @Tomibeck is having and seems I have the similar. What I found that seems to work, move the delay script into the components directory, renumber all the components with the delay script as 000_startup.py. You may not need a different number for all components, just make sure 000_startup.py is the first to run.

Here’s the log after a restart and no more error’s.

2018-10-12 11:16:57.829 [DEBUG] [rg.eclipse.smarthome.automation.rest] - BundleEvent STARTED - org.eclipse.smarthome.automation.rest

2018-10-12 11:16:58.497 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app

2018-10-12 11:16:58.872 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui

2018-10-12 11:17:13.069 [INFO ] [eclipse.smarthome.model.script.Rules] - JSR223: Startup: Checking for initialized context

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

2018-10-12 11:17:43.098 [INFO ] [eclipse.smarthome.model.script.Rules] - JSR223: Startup: Complete

2018-10-12 11:17:43.108 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_components/000_startup.py

2018-10-12 11:17:43.121 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_components/001_StartupTrigger.py'

2018-10-12 11:17:43.603 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_components/001_StartupTrigger.py

2018-10-12 11:17:43.608 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_components/002_DirectoryTrigger.py'

2018-10-12 11:17:47.788 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_components/002_DirectoryTrigger.py

2018-10-12 11:17:47.795 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_components/003_OsgiEventTrigger.py'

2018-10-12 11:17:49.604 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_components/003_OsgiEventTrigger.py

2018-10-12 11:17:49.609 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_components/004_Esper.py'

2018-10-12 11:17:57.128 [DEBUG] [e.smarthome.automation.module.script] - ServiceEvent REGISTERED - {org.osgi.service.event.EventHandler}={service.id=371, service.bundleid=198, service.scope=singleton, event.topics=['*']} - org.eclipse.smarthome.automation.module.script

2018-10-12 11:17:57.202 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_components/004_Esper.py

2018-10-12 11:17:57.217 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_components/005_JythonExtensionProvider.py'

2018-10-12 11:17:59.588 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_components/005_JythonExtensionProvider.py

2018-10-12 11:17:59.598 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_components/006_ExampleExtensionProvider.py'

2018-10-12 11:17:59.663 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_components/006_ExampleExtensionProvider.py

2018-10-12 11:17:59.668 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_components/007_JythonThingProvider.py'

2018-10-12 11:17:59.812 [DEBUG] [e.smarthome.automation.module.script] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.thing.ThingProvider}={service.id=372, service.bundleid=198, service.scope=singleton} - org.eclipse.smarthome.automation.module.script

2018-10-12 11:17:59.840 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_components/007_JythonThingProvider.py

2018-10-12 11:17:59.846 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_components/008_JythonBindingInfoProvider.py'

2018-10-12 11:18:00.172 [DEBUG] [e.smarthome.automation.module.script] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.binding.BindingInfoProvider}={service.id=373, service.bundleid=198, service.scope=singleton} - org.eclipse.smarthome.automation.module.script

2018-10-12 11:18:00.183 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_components/008_JythonBindingInfoProvider.py

2018-10-12 11:18:00.195 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_components/009_JythonItemProvider.py'

2018-10-12 11:18:00.356 [DEBUG] [e.smarthome.automation.module.script] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.items.ItemProvider}={service.id=374, service.bundleid=198, service.scope=singleton} - org.eclipse.smarthome.automation.module.script

2018-10-12 11:18:00.368 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_components/009_JythonItemProvider.py

2018-10-12 11:18:00.372 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_components/010_JythonThingTypeProvider.py'

2018-10-12 11:18:00.500 [DEBUG] [e.smarthome.automation.module.script] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.thing.binding.ThingTypeProvider}={service.id=375, service.bundleid=198, service.scope=singleton} - org.eclipse.smarthome.automation.module.script

2018-10-12 11:18:00.518 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_components/010_JythonThingTypeProvider.py

2018-10-12 11:18:00.522 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_components/011_JythonTransform.py'

2018-10-12 11:18:00.649 [DEBUG] [e.smarthome.automation.module.script] - ServiceEvent REGISTERED - {org.eclipse.smarthome.core.transform.TransformationService}={service.id=376, service.bundleid=198, service.scope=singleton, smarthome.transform=JYTHON} - org.eclipse.smarthome.automation.module.script

2018-10-12 11:18:00.659 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_components/011_JythonTransform.py

2018-10-12 11:18:00.663 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script '000_test.py'

2018-10-12 11:18:00.717 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: 000_test.py

2018-10-12 11:18:00.721 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'test1.py'

2018-10-12 11:18:00.758 [INFO ] [clipse.smarthome.automation.examples] - Hello jython world!

2018-10-12 11:18:00.761 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - Script loaded: test1.py

Here you can see how the components are numbered.

Maybe the components can stay?

For those using the openHAB Debian Docker container on Ubuntu, I have created a guide of how I have setup Jython here.

@5iver, I just installed and set up Jython per your README in the OH-Jython-Scripters/openhab2-jython GitHub repository. I found your instructions quite clear and had no problem getting to the initial testing phase. I did see the following in the logs, which I suspect is not intended:

2018-10-14 13:44:13.716 [DEBUG] [rt.internal.loader.ScriptFileWatcher] - in queue: {md=[file:/etc/openhab2/automation/jsr223/000_components/README.md]}

I have since removed README.md from /etc/openhab2/automation/jsr223/000_components/.

Thanks for getting after this, it looks quite promising!

1 Like