from core import osgi
from core.rules import rule
from core.triggers import when
import core.items
reload(core.items)
import core.rules
reload(core.rules)
import core.triggers
reload(core.triggers)
import core.items
from core.rules import rule
from core.triggers import when
I’m not experiencing any issues calling methods on events.
That would seem to be an issue with the Windows installer (IIRC, your platform is a Windows box, right?) I’m running openHABian on an RPi 3B and the apt upgrade command is careful about not replacing my configs without giving me a chance to choose how to handle changes to configuration files. Bottom line, /etc/default/openhab2 (file containing startup options on openHABian) has been untouched since I edited it when I added Jython support to my OH2 system. I’m currently running a recent 2.5.0 SNAPSHOT and have updated a couple times since 2.4.0 STABLE was released.
Weird, I have what would seem to be the same setup as yours, but I haven’t had any problems with an upgrade wiping out my configs. Most recently an upgrade did propose to replace /var/lib/openhab2/etc/org.ops4j.pax.logging.cfg with an updated version, but one of the options provided was to launch a console so I could handle it myself. I then opened both the existing and updated versions of org.ops4j.pax.logging.cfg and reconciled the updates myself.
What is your update and upgrade process? I do the following:
apt update
apt list --upgradable
apt upgrade
[Update with a notion that just came to mind:
I do not run a GUI on my RPi, I use an SSH session exclusively, i.e., command line.]
Was cleaning up some tabs in my browser, and had one still open to your question, that it looks like I’d forgotten to answer! There wouldn’t be a way to do load this without an import. Later this year, I’ll work on adding most of the Jython helper libraries into a scripting API, so they can be used with any JSR223 language. Something like this will be added into the default scope for scripts.
In the meantime, you may want to use this for logging, which uses a class from the Rules DSL…
from org.eclipse.smarthome.model.script.actions.LogAction import *
logInfo("Rules", "Test logInfo")
logDebug("Rules", "Test logDebug")
Hmmm… you must not be aware of the log attribute (execute.log) that is added to the function when decorated with core.rules.rule. When decorating a class, it will also add self.log to the class instance.
As previously discussed in the forum somewhere, you really should be using unique names for your action functions! In addition to what was discussed, there is possibly a change coming to allow the use of Jython 2.7.1, which will cause some issues with your setup. Specifically, the function log attribute will not work.
@rule("Test duplicate name 1")
@when("Item Virtual_Switch_1 received update")
def testDuplicateFunctionName(event):
testDuplicateFunctionName.log.info("Function 1")
@rule("Test duplicate name 2")
@when("Item Virtual_Switch_1 received update")
def testDuplicateFunctionName(event):
testDuplicateFunctionName.log.info("Function 2")
These rules will produce this…
2019-01-28 03:46:06.170 [INFO ] [jsr223.jython.Test duplicate name 2] - Function 2
2019-01-28 03:46:06.198 [INFO ] [jsr223.jython.Test duplicate name 2] - Function 1
No I’m not aware of this. Haven’t updated my jython install in a while.
I remember that discussion well and havn’t used duplicate names since. In that PR they are named execute and execute2 so I think they are not duplicate?
This would be great! At some point last december I decided not to update until the developement cooled down a bit. So all breaking changes would be covered with one update. Think I already sould have done this but other things kept me busy. But with versioning and changelog it would’ve gone different.
I have setup the folders and paths according as described. However, I do not get any output in openhab.log, when creating the file test.py in automation/jsr223 as described in configuration-testing.
I have also tried enabling debug-output in the Karaf console log:set DEBUG org.openhab.core.automation. But that still does not give any output.
I also tried moving test.py to automation/lib/python/ and automation/jython/, which also appear in the EXTRA_JAVA_OPTS, but that does not change anything.
I restarted Openhab in between by doing sudo systemctl restart openhab2.service.
I have no idea what to try next, so any support would very appreciated. Thanks in advance!
In those docs, you can also find detailed installation instructions, if you’d like to manually install everything. The official documentation needs to be updated, but it’s hard to get started with that until some of the details for OH 3.0 become finalized. Shout if you need any help!
I tried to install jython on my dev machine (RPi4 running openHABian) but failed.
Purged OH, installed 2.5.9 and followed the install instructions first.
But I kept getting this error 2020-10-09 11:48:41.152 [INFO ] [me.core.service.AbstractWatchService] - ScriptEngine for py not available
EXTRA_JAVA_OPTS is properly set as you can see below.
I can’t find out what’s wrong. All settings (seem to) match that of my (working) production box.
Any ideas ?