Jython rules not triggered anymore

So I’ve been updating my OH from 2.4.1 to 2.5.10 recently and all my Jython rules are not triggered anymore…
Does someone have a clue why?
I downloaded the new Jython Binding & Helper classes and checked the docs but I have no clue where to start since I didnt change anything.
Thanks in advantage

Bump…
I configured it manually about 1 year ago, setting the Environment Variable to the Jython.jar on Version 2.7.0
Jython, extra libraries and the experimental rule engine Bindings are all installed.
When reinstalling the ‘Experimental rule engine’ I get those erros on all my scripts I’ve programmed:

2020-11-02 21:07:46.642 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'personal/roborock.py'

2020-11-02 21:07:46.862 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngine for language 'py' could not be created for identifier: file:/etc/openhab2/automation/jsr223/personal/roborock.py

2020-11-02 21:07:46.863 [ERROR] [me.core.service.AbstractWatchService] - Script loading error, ignoring file: personal/roborock.py

So therefore my Rules are not getting the Trigger:

2020-11-02 21:18:53.808 [vent.ChannelTriggeredEvent] - mihome:sensor_cube:158d000278d7a9:action triggered ALERT

2020-11-02 21:18:53.815 [vent.ChannelTriggeredEvent] - mihome:sensor_cube:7811dcb37d0d:158d000278d7a9:action triggered ALERT

2020-11-02 21:18:53.817 [vent.ItemStateChangedEvent] - mihome_sensor_cube_158d000278d7a9_lastAction changed from NULL to 2020-11-02T21:18:53.805+0100

2020-11-02 21:18:54.337 [vent.ItemStateChangedEvent] - mihome_sensor_cube_158d000278d7a9_rotationAngle changed from NULL to 108 °

2020-11-02 21:18:54.345 [vent.ChannelTriggeredEvent] - mihome:sensor_cube:158d000278d7a9:action triggered ROTATE_RIGHT

2020-11-02 21:18:54.347 [vent.ItemStateChangedEvent] - mihome_sensor_cube_158d000278d7a9_rotationTime changed from NULL to 500 ms

2020-11-02 21:18:54.352 [vent.ChannelTriggeredEvent] - mihome:sensor_cube:7811dcb37d0d:158d000278d7a9:action triggered ROTATE_RIGHT

2020-11-02 21:18:54.354 [vent.ItemStateChangedEvent] - Cube_RotationAngle1 changed from NULL to 108

2020-11-02 21:18:54.355 [vent.ItemStateChangedEvent] - Cube_RotationTime1 changed from NULL to 500

2020-11-02 21:18:56.676 [vent.ChannelTriggeredEvent] - mihome:sensor_cube:158d000278d7a9:action triggered ROTATE_RIGHT

2020-11-02 21:18:56.680 [vent.ChannelTriggeredEvent] - mihome:sensor_cube:7811dcb37d0d:158d000278d7a9:action triggered ROTATE_RIGHT

2020-11-02 21:18:56.681 [vent.ItemStateChangedEvent] - mihome_sensor_cube_158d000278d7a9_rotationAngle changed from 108 ° to 86 °

2020-11-02 21:18:56.683 [vent.ItemStateChangedEvent] - Cube_RotationAngle1 changed from 108 to 86

This is my script handling the events: (There are alot of other rules in the .py File, so there are more Inputs than needed in this case)

Scriptspath:

openhab2-conf/automation/jsr223/personal
from core.triggers import when
from core.rules import rule
from core.log import logging, LOG_PREFIX
from org.joda.time import DateTime
from threading import Timer
from time import sleep
from org.eclipse.smarthome.model.script.actions.ScriptExecution import createTimer
#-----------------------------------------------------------------------------
# Xiaomi Cubes
#-----------------------------------------------------------------------------

#Cube 1 Schlafzimmer:

            #Schlafzimmer:
#---------------------------------------
    #MOVE:             Spotify
    #ROTATE_RIGHT:     Lichterfarbe
    #ROTATE_LEFT:      Raumlicht
    #FLIP90:           Wohnzimmerlicht
    #FLIP180:          Alle Lichter
    #TAP_TWICE:        Helligkeit
    #FREE_FALL:
    #SHAKE_AIR:
    #ALERT:
#---------------------------------------

@rule("Aqara Cube Controller Nr.1 im Schlafzimmer")
@when("Channel mihome:sensor_cube:7811dcb37d0d:158d0002565037:action triggered")
def getCubeEvent1(event):
    event = event.event
    logXC.info("Event: "+str(event))
    if "MOVE" in str(event):
        sleep(0.5)
        if items["AlexaSZ_Player"] !=  PlayPauseType.PLAY:
            events.sendCommand("AlexaSZ_MusicProviderId","SPOTIFY")
            events.sendCommand("AlexaSZ_Player","PLAY")
            events.sendCommand("AlexaSZ_Volume","40")
            logXC.info("Jython: Move (Schlafzimmer Cube-Event) - Spotify AN")
        else:
            events.sendCommand("AlexaSZ_Player","PAUSE")
            logXC.info("Jython: Move (Schlafzimmer Cube-Event) - Spotify AUS")
    elif "ROTATE_RIGHT" in str(event):
        global iColor
        if (iColor < 7):
            iColor = iColor+1
            events.sendCommand("farbWahl",str(iColor))
        elif (iColor == 7):
            iColor = 1
            events.sendCommand("farbWahl",str(iColor))
        logXC.info("Jython: Rotate right (Schlafzimmer Cube-Event)")
    elif "ROTATE_LEFT" in str(event):
        global iRoom
        if (iRoom < 4):
            iRoom = iRoom+1
            events.sendCommand("zimmerWahl",str(iRoom))
        elif (iRoom == 13):
            iRoom = 1
            events.sendCommand("zimmerWahl",str(iRoom))
        logXC.info("Jython: Rotate left (Schlafzimmer Cube-Event)")
    elif "FLIP90" in str(event2):
        logXC.info("Jython: Flip 90 grad (Wohnzimmer Cube-Event)")
        if items["gBedYeelight"] == OnOffType.ON:
            events.sendCommand("gBedYeelight","OFF")
        elif items["gBedYeelight"] == OnOffType.OFF:
            events.sendCommand("gBedYeelight","ON")
    elif "FLIP180" in str(event2):
        logXC.info("Jython: Flip 180 grad (Wohnzimmer Cube-Event)")
        if items["gLights"] == OnOffType.ON:
            events.sendCommand("gLights","OFF")
            logXC.info("Jython: Flip 180 grad (Wohnzimmer Cube-Event) - Licht aus")
        elif items["gLights"] == OnOffType.OFF:
            events.sendCommand("gLights","ON")
            logXC.info("Jython: Flip 180 grad (Wohnzimmer Cube-Event) - Licht an")
    elif "TAP_TWICE" in str(event):
        if (items["gBrightness"] < 80):
            i = items["gBrightness"] + 20
            event.sendCommand ("gBrightness",str(i))
        logXC.info("Jython: Tap Twice (Schlafzimmer Cube-Event)")
    elif "SHAKE_AIR" in str(event):
        if (items["gBrightness"] > 20):
            i = items["gBrightness"] + 20
            event.sendCommand ("gBrightness",str(i))
        logXC.info("Jython: Shake Air (Schlafzimmer Cube-Event)")
    elif "FREE_FALL" in str(event):
        logXC.info("Jython: Free fall (Schlafzimmer Cube-Event)")
    elif "ALERT" in str(event):
        logXC.info("Jython: Alert (Schlafzimmer Cube-Event)")

There was a rules-not-triggering bug in OH2.4, when you upgraded. That was something to do with rule status, so I’d imagine you have imported that. From memory, you had to deactivate each rule, reboot, and then reactivate.
Ah yes - found it -

It’s always @5iver knowing everything about Jython! :sweat_smile:
I don’t quite know how to deactivate a rule. I will look further into that.
What’s interesting too is that I get those errors in the Logpanel everytime I make changes to it:

2020-11-02 22:33:14.627 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'personal/xiaomicontroller.py'

2020-11-02 22:33:14.630 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab2/automation/jsr223/personal/xiaomicontroller.py

2020-11-02 22:33:16.063 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/personal/xiaomicontroller.py': ImportError: No module named automation in <script> at line number 1

Thanks alot by now!

my java environment environment variables set under /etc/default/openhab2:

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"

Well, that might more likely explain why they don’t work …

Easier and future proof to use…

from core.actions import ScriptExecution

Use the logger that is added by core.rules.rule as an attribute of the rule callback function. Also, string concatenation here is dangerous, since you could end up with unicode, so use format…

getCubeEvent1.log.info("Event: {}".format(event))

PLAY, ON, and OFF will work.

Use Jython 2.7.2. One more thing… you are using str() a lot. When possible, use the methods that are provided in the OH objects, like toString().

That issue only affected UI created rules. However, here is one that affected the startup of scripted automation rules on Windows…

This is very different than…

The former means that Jython is not loaded and that you probably need to fix your EXTRA_JAVA_OPTS. The latter sounds really familiar and there should be something in the forum, but search didn’t find anything and may still be broken. IIRC, this had come up with a very old version of the helper libraries and was due to a user configuration issue. What did you change between these two errors? Since you are using the latest helper libraries, what do you have in the log at startup? There should be some system information logged. Does the hello_world.py script work?

BTW, I’ve added your topic to an appropriate category and added the jython tag. I am subscribed to both of these.

Big thanks 5iver!

Will rewrite that!

My Code is pretty old. I started programming in Jython back in 2018/19 when everything was a bit under construction. I will refactor that :slight_smile:

I just downloaded the standalone Jar of 2.7.2. Will upgrade my Extra_java_opts! They’ve been like this from 2018/19 since today:

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"

I literally just updated a comment, so nothing that needs to be compiled/loaded in the first place …
The ‘could not be created for identifier:’ Error comes during startup when first time loading the scripts (on all of them)

I set the loglevel to debug for org.openhab.core.automation and org.eclipse.smarthome.automation to DEBUG and will restart my Pi now …

Thanks, it’s been a while since I’ve been actively using the Forum :stuck_out_tongue:

Edit: I really only get those errors for all my scripts and actually some Triggers on startup, that might be it:

2020-11-03 08:51:10.287 [INFO ] [tomation.jsr223.jython.startup_delay] - Complete

2020-11-03 08:51:10.292 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'core/components/100_DirectoryTrigger.py'

2020-11-03 08:51:10.717 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngine for language 'py' could not be created for identifier: file:/etc/openhab2/automation/jsr223/core/components/100_DirectoryTrigger.py

2020-11-03 08:51:10.718 [ERROR] [me.core.service.AbstractWatchService] - Script loading error, ignoring file: core/components/100_DirectoryTrigger.py

2020-11-03 08:51:10.721 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'core/components/100_OsgiEventTrigger.py'

2020-11-03 08:51:10.934 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngine for language 'py' could not be created for identifier: file:/etc/openhab2/automation/jsr223/core/components/100_OsgiEventTrigger.py

2020-11-03 08:51:10.936 [ERROR] [me.core.service.AbstractWatchService] - Script loading error, ignoring file: core/components/100_OsgiEventTrigger.py

2020-11-03 08:51:10.938 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'core/components/100_ShutdownTrigger.py'

2020-11-03 08:51:11.143 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngine for language 'py' could not be created for identifier: file:/etc/openhab2/automation/jsr223/core/components/100_ShutdownTrigger.py

2020-11-03 08:51:11.144 [ERROR] [me.core.service.AbstractWatchService] - Script loading error, ignoring file: core/components/100_ShutdownTrigger.py

2020-11-03 08:51:11.147 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'core/components/100_StartupTrigger.py'

2020-11-03 08:51:11.355 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngine for language 'py' could not be created for identifier: file:/etc/openhab2/automation/jsr223/core/components/100_StartupTrigger.py

2020-11-03 08:51:11.358 [ERROR] [me.core.service.AbstractWatchService] - Script loading error, ignoring file: core/components/100_StartupTrigger.py

2020-11-03 08:51:11.361 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'core/components/200_JythonBindingInfoProvider.py'

2020-11-03 08:51:11.733 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngine for language 'py' could not be created for identifier: file:/etc/openhab2/automation/jsr223/core/components/200_JythonBindingInfoProvider.py

2020-11-03 08:51:11.735 [ERROR] [me.core.service.AbstractWatchService] - Script loading error, ignoring file: core/components/200_JythonBindingInfoProvider.py

2020-11-03 08:51:11.737 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'core/components/200_JythonExtensionProvider.py'

2020-11-03 08:51:11.971 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngine for language 'py' could not be created for identifier: file:/etc/openhab2/automation/jsr223/core/components/200_JythonExtensionProvider.py

2020-11-03 08:51:11.973 [ERROR] [me.core.service.AbstractWatchService] - Script loading error, ignoring file: core/components/200_JythonExtensionProvider.py

2020-11-03 08:51:11.975 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'core/components/200_JythonItemProvider.py'

2020-11-03 08:51:12.174 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngine for language 'py' could not be created for identifier: file:/etc/openhab2/automation/jsr223/core/components/200_JythonItemProvider.py

2020-11-03 08:51:12.176 [ERROR] [me.core.service.AbstractWatchService] - Script loading error, ignoring file: core/components/200_JythonItemProvider.py

2020-11-03 08:51:12.177 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'core/components/200_JythonThingProvider.py'

2020-11-03 08:51:12.387 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngine for language 'py' could not be created for identifier: file:/etc/openhab2/automation/jsr223/core/components/200_JythonThingProvider.py

2020-11-03 08:51:12.389 [ERROR] [me.core.service.AbstractWatchService] - Script loading error, ignoring file: core/components/200_JythonThingProvider.py

2020-11-03 08:51:12.390 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'core/components/200_JythonThingTypeProvider.py'

2020-11-03 08:51:12.727 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngine for language 'py' could not be created for identifier: file:/etc/openhab2/automation/jsr223/core/components/200_JythonThingTypeProvider.py

2020-11-03 08:51:12.729 [ERROR] [me.core.service.AbstractWatchService] - Script loading error, ignoring file: core/components/200_JythonThingTypeProvider.py

2020-11-03 08:51:12.733 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'core/components/200_JythonTransform.py'

2020-11-03 08:51:12.930 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngine for language 'py' could not be created for identifier: file:/etc/openhab2/automation/jsr223/core/components/200_JythonTransform.py

2020-11-03 08:51:12.933 [ERROR] [me.core.service.AbstractWatchService] - Script loading error, ignoring file: core/components/200_JythonTransform.py
```

I updated my Java_Extra_opts: 
```
EXTRA_JAVA_OPTS="-Xbootclasspath/a:/etc/openhab2/automation/jython/jython-standalone-2.7.2.jar  -Dpython.home=/etc/openhab2/automation/jython  
-Dpython.path=/etc/openhab2/automation/lib/python"
```

If you haven’t, read though here…

If you want to save the hassle of installation, use the add-on…

Make sure you have copied in the updated scripts too (everything under /automationjsr223/python/core/). These have also been updated, and you definitely do not have all of them, since I do not see 000_startup.py being loaded.

But it is very odd that you get that error and then other scripts work…

Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/personal/Alexa.py': ImportError: cannot import name ScriptExecution in <script> at line number 7

Yeah so what I can see is, that all my scripts have no access to the org.eclipse.smarthome imput (Where is the .DLL located?)

Yeah, youre right! Because I had the startup delay from Back in the days:
image

I copied it from Github now

Are you now using core.actions.ScriptExecution?

DLL? ScriptExecution is here… https://github.com/openhab/openhab-core/blob/2.5.0/bundles/org.openhab.core.model.script/src/org/eclipse/smarthome/model/script/actions/ScriptExecution.java.

Does the hello_world.py script run without error?

What did it log when it ran? You can/should remove 000_startup_delay.py.

It seems to me like your EXTRA_JAVA_OPTS is messed up or file permissions changed so that you can’t get to the libraries. Can you get to anything in core? Can you import org.joda.time?

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.