I would like to catch any item events using Jython. I pieced the code below from various examples on the forum but still cannot get it to catch any events…
scriptExtension.importPreset("RuleSimple")
scriptExtension.importPreset("RuleSupport")
scriptExtension.importPreset("RuleFactories")
from core.rules import rule
from core.triggers import StartupTrigger, CronTrigger, ItemStateUpdateTrigger, GenericEventTrigger
from core.log import logging, LOG_PREFIX
@rule("Any Item Changed")
class AnyItemChanged(object):
def __init__(self):
self.triggers = [GenericEventTrigger("","openhab/*","ItemStateChangedEvent").trigger]
def execute(self, module, inputs):
self.log.warn("Item Changed ***************")
Looking at the JavaDocs, a Rule requires a list of EventTrigger Objects.
Browsing and clicking through the JavaDocs, I can’t even find a GenericEventTrigger Class nor Interface. So I can’t even tell if that’s something from OH at all or if the search is broken.
Looking at the Helper Library, a GenericEventTrigger is indeed something that only exists in the Helper Library. One thing that is telling is the comment
It’s one of the the most powerful triggers, but it is also the most complicated to configure.
I think your best bet will be to study the code and modify the logging on the event bus to log all events and see if you can gather what each of the arguments to the GenericEventTrigger need to be.
In general, I don’t know that it’s possible to trigger a rule on any and all events.