[beta testers wanted!] Jython addon w/ helper libraries (requires OH 2.5.x)

So I did a manual install of Jython and same problem. Weird.

2020-07-05 11:35:32.134 [ERROR] [eclipse.smarthome.model.script.Rules] - Traceback (most recent call last):

  File "<script>", line 14, in <module>

  File "/etc/openhab2/automation/lib/python/core/date.py", line 43, in <module>

    from org.openhab.core.library.types import DateTimeType as LegacyDateTimeType

ImportError: No module named library

2020-07-05 11:35:32.137 [WARN ] [jython.Startup                      ] - 

\*******************************************************************************

\    Jython version:       2.7.2.final

\    Operating system:     Linux

\    OS Version:           4.19.97-v7l+

\    Java vendor:          Azul Systems, Inc.

\    Java VM name:         OpenJDK Client VM

\    Java runtime name:    OpenJDK Runtime Environment

\    Java runtime version: 1.8.0_252-b225

\    sys.path:             /etc/openhab2/automation/lib/python

                      /etc/openhab2/automation/jython/Lib

                      /etc/openhab2/automation/jython/jython-standalone-2.7.2.jar/Lib

                      __classpath__

                      __pyclasspath__/

\    *******************************************************************************

Is that with your script or test script or both? What happens if you remove all scripts and create a new one, without copy/paste? Maybe thereā€™s a nonprintable character hidden in there.

Or post your script (just put .txt at the end of the name).

After the update to 2.5.6-2 jython was not started anymore. Only Javascriptā€¦
I had no clue. Removed nrge. Reinstalled it. Restarted opengaan. Nothing. Tried this a few times, including a complete reboot. Javascript engine started, nut no jython. Since i donā€™t Knox how the engine is started, i thought, iā€™ll look at the path. And, it was gone! I added the path, restarted OH. And up and running!
I thought an install of nrge was taking Care of the path? Anyway, everthing works again

@Suy, then you are not using the Jython add-on. Remove the core and community libraries from $OPENHAB_HOME/lib/python/, remove the Jython entries in EXTRA_JAVA_OPTS, and copy the jar to $OPENHAB_HOME/add-ons. If you donā€™t want to use the add-on, then please start a new topic.

I have been using the jython library almost from beginning and had long had the plan for trying this beta. Finally I decided to spent an evening spinning it all up. Previously the setup anything from straightforward. I decided to spin up a fresh install of openHAB on a fresh installed Ubuntu 20.04 Server.

The short story is that it went well and it was amazingly easy to setup. Only thing that I had problems with, was that I actually did to much configuring (EXTRA_OPTS), after some searching I found a thread where it was stated what to leave out from the usual config. After that it just started.
I have just copied the community scripts from the repo and my personal scripts from my current openHAB insatll, and its seems to work (no errors in the log)

Great work, I actually decided to use this new server for production, so I will for sure look into it. But it really looks good, and it seems to be quite easy to setup

2 Likes

https://www.openhab.org/docs/configuration/jsr223-jython.html ?
itā€™s confusingā€¦ Thereā€™s so much documentation in OH docs, but, not all accurateā€¦
using openhabian 2.5.6-2
I looked at $OPENHAB_HOME and ā€¦ there no core library in itā€¦ so can,ā€˜t remove anything
BUT, there is a $OPENHAB_HOME/add-ons which doesnā€™t have a jython jar fileā€¦
My jython-standalone-2.7.0.jar is located in $OPENHAB_CONF/automation/jython
So do I have to move that jar file to the $OPENHAB_HOME/add-ons library ?
Removing the JYTHON entries of EXTRA_JAVA_OPTS i can do (when I know what to do with the jar)
Iā€™m a bit scary to remove the ā€œcore and community librariesā€ as Iā€™m not certain which libraries you mean. Theyā€™"re not in the $OPENHAB_HOME ā€¦

updated: I looked in the openhab-helper-libraries-master.zip and saw that thereā€™s a Core libray and in that core library is the library automationā€¦ I guess you mean that i have to remove the automation library.
I once followed the installion here :Installation ā€” openHAB Helper Libraries documentation. Thereā€™s no mention of the community libraries, so I didnā€™t install them (as far as i remember)
Thanks for your help. Iā€™ll try the changes one of these days.
update: probably removed the wrong librariesā€¦ now only javascript is loadedā€¦
now, Iā€™m copying back my backupā€¦

update3

aaaah you mean: remove library community and core from \OPENHAB\openHAB-share\openhab2-conf\automation\lib\python I guessā€¦ (openhabian) ?
update
gave up. ā€¦ while searching for a solution (like error import osgiā€¦ error, i found a jar for the addon, ā€¦
info on different placesā€¦ I know, still betaā€¦ But Iā€™ll guess Iā€™ll waitā€¦ Maybe some day I do a clean install, maybe that helpsā€¦ Anyway, at the moment Iā€™m using jython the ā€œold wayā€ and thatā€™s is working for meā€¦
The DSL rule were very limiting for me, so Iā€™m glad I can work with Jythonā€¦
Iā€™m writing my backup image to my sd card, again (takes almost 2 hours)ā€¦
Iā€™m gonna try to follow the discussions here.

If you want to use the beta Jython addon, which is what this topic is about, then read the instructions in the OP. If you want to manually install Jython and the helper libraries, then use the following instructions and create a new topic if you have issuesā€¦ https://openhab-scripters.github.io/openhab-helper-libraries/Getting%20Started/Installation.html.

I did a completely fresh OH install using Openhabian. Still getting this error. It fails on the import. This works fine on my other OH install. I have tried both the bundle here and a manual jython install. So 2 complete new OH installs, 2 different ways of installing jython and getting the same error.

Does something else have to be enabled for Datetime/Joda to work?

from core.date import seconds_between

  File "<script>", line 14, in <module>

  File "/etc/openhab2/automation/lib/python/core/date.py", line 43, in <module>

    from org.openhab.core.library.types import DateTimeType as LegacyDateTimeType

ImportError: No module named library




"""

This is the first script to load and it will log system information to assist

with troubleshooting.

"""



import traceback



from org.slf4j import Logger, LoggerFactory  

log = LoggerFactory.getLogger("org.eclipse.smarthome.model.script.Rules") 



try:

    from core.date import seconds_between



except:

    log.error (traceback.format_exc())

       

  

 from org.slf4j import LoggerFactory

LOG = LoggerFactory.getLogger("jython.Startup")



from java.lang import System

import sys



LOG.warn("\n\n\*******************************************************************************\n\    Jython version:       {}.{}.{}.{}\n\    Operating system:     {}\n\    OS Version:           {}\n\    Java vendor:          {}\n\    Java VM name:         {}\n\    Java runtime name:    {}\n\    Java runtime version: {}\n\    sys.path:             {}\n\    *******************************************************************************\n".format(    sys.version_info[0], sys.version_info[1], sys.version_info[2], sys.version_info[3],    System.getProperty("os.name"),    System.getProperty("os.version"),    System.getProperty("java.vendor"),    System.getProperty("java.vm.name"),    System.getProperty("java.runtime.name"),    System.getProperty("java.runtime.version"),    "\n                      ".join(sys.path)))

What about this? No matter what I do, I cannot reproduce this, so I believe to be something in your configuration. Did you download the latest beta addon and helper libraries?

No

Iā€™m sorry if I missed in the discussion Michael but what is the hardware platform? I see linux is O/S

what is platform for this install?

One install (that works without problem) using the manual jython setup, works fine. That is on an old celeron box,

The install I cannot get to work is on a PI4. I have tried several installs of OH, removed bindings, tried the bundled jython and manual jython, same problem.

Bizarre :frowning:

Scott, I wish I had some better ideas. I would have hoped that a fresh install would work but nope. I cannot seem to narrow it down.

One weird thing, if I edit file and save it ONCE I see this in the log - it gets loaded twice

2020-07-07 18:05:19.996 [INFO ] [me.core.service.AbstractWatchService] - ScriptEngine for tmp not available

2020-07-07 18:05:20.031 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'python/personal/test.py'

2020-07-07 18:05:20.035 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/personal/test.py

2020-07-07 18:05:21.045 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'python/personal/test.py'

2020-07-07 18:05:21.048 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/python/personal/test.py

@5iver - I have an idea. The working install is in the US, the problematic install is in Canada. Could there be different date settings that would cause this?

Are you accessing through Samba? Iā€™m not sure if the NGRE ScriptFileWatcher picks up the file change twice when using smb like the old one didā€¦ havenā€™t used it in a long while since setting up SSH in VS Code. Something is definitely weird on your (Canadian) system.

I donā€™t see how regional settings would affect this. I have an update for the beta addons that Iā€™m very close to distributing. I doubt it will help, but it will be interesting to see what happens.

Are you using the latest core scripts? Rather than modify them with your tests, create a script in /jsr223/python/personal/. Have we seen the results of the startup script when run from Canada? Iā€™m curious about the Java version. Are you remoting into this box or the one at home?

a small remark: in your logging itā€™s like that the scriptengines are initialed twice? I see that in my logging too? Is that normal?

Yes, this is normal and will likely be a bit cleaner in OH 3.0. This behavior is due to the underlying behavior of OSGi, which OH is based on.

My current not working install is using the bundle from the top of this post - is there a more recent one?

The link in the OP is to a directory in my Google Drive and it has not changed. The contents of the directory has changed though, and it is best to use the latest from Jan 22.

That is the version I have, Jan 22

The lib/python/core/date.py file I have is different from github. Replacing that file with the one on github fixed the problem.

In the OP, #4

Download the addon and copy to $OPENHAB_HOME/addons/ (see here for more details). The jar contains the core and community helper libraries, so thereā€™s no need to copy them from the repo. However, the core scripts will need to be copied to /automation/jsr223/python/core/.

And then the reference to step 7

Include step 7, but understand that the core libraries (/automation/lib/python/core) are included in theis bundle, so the ones you copy will be ignored.

The instructions/behavior are a little confusing. But replacing the date.py file fixed the problem.