[SOLVED] JSR223: Problem in execute in SimpleRule

I have just upgarded from 2.5.0M1 to 2.5.0M3. After that I have a problem with my jython scripts. The problem is in this code:


class RuleFactory(scope.SimpleRule): 
	def execute(self, module, input):
			getLogger().info(("Input: '{}'").format(input))

The output gives:

2019-10-09 23:44:43.051 [INFO ] [personal.jsr223core.rule.RuleFactory] - Input: '{switchTestInput_e0f4ea91eadd11e9944a9ef7ff3702ce.oldState: OFF, switchTestInput_e0f4ea91eadd11e9944a9ef7ff3702ce.event: switchTestInput changed from OFF to ON, oldState: OFF, module: switchTestInput_e0f4ea91eadd11e9944a9ef7ff3702ce, switchTestInput_e0f4ea91eadd11e9944a9ef7ff3702ce.newState: ON, event: switchTestInput changed from OFF to ON, newState: ON}'

The problem is that the item appears to be switchTestInput_e0f4ea91eadd11e9944a9ef7ff3702ce, where it should be switchTestInput.

The problem arises when I use the item name in my event handler.
I am 100% sure it worked before upgrading. I have downloaded latest jsr223 scripts.

@rlkoshak what do you say? You are fast becoming a JSR223 expert. :wink:

I use the Helper Libraries and have no experience with creating Rules in this way. Using the Helper Library the code would be:

from core.rules import rule
from core.triggers import when

@rule("Some rule name")
@when("some trigger")
def rule_func(event):
    rule_func.log.info("Input: '{}'".format(event.itemName)) 

I know that @5iver has been busily at work on both the core and the Helper Libraries so it’s likely something has changed. But I’ve no experience with building Rules without the Helper Libraries so I don’t know how it’s supposed to work.


My “problem” is that this code is pretty old, actually I started developing it with the first jsr223 library. And I guess JSR223 has changed pretty much in the mean time :slight_smile: So it might be time for some rework

I just tried something (that seems to work):
If I use the below code I get the ItemName with aout the extra GUID stuff


Your code snippet guided me towards the word i should have searched for in the beginnging. I found this https://community.openhab.org/t/what-item-triggered-simplerule-using-jsr223-jython-openhab2-2-2/38457, which was precisely what I needed. My code was obviously rubbish when looking closer at it. It is more a wonder that it ever worked, more than why it stopped working :slight_smile:

1 Like

Hello, Martin! I can’t tell from your code snippet if you are using extensions or the raw API to create your rule. I highly using the decorators, since this will simplify things quite a bit, and provide additional functionality. You mentioned that you’ve updated to the most recent helper libraries, so be sure to read through the updated documentation. Specifically, the Event Object Attributes and the sentence right before the table is pertinent to your previous question.

Let me know if you have any questions!

I use the openHAB extension, and inherit from that. I started way back when the new Rule Engine was in something like Pre Alpha Very Early Release state. When I looked carefully into my code i figured out that I have just beeen lucky that it did work before.

1 Like