Jython @when("Item added/removed/modified") not working?

How do I make the trigger for Item added / removed / modified to work?
ping @5iver

This is my test code:

@rule("test2")
@when("Item added")
@when("Item removed")
@when("Item modified")
def test2(event):
    test2.log.info("Item event:")

I would expect the logging to happen whenever I added / removed / modified an (any) item, but no logging occurred.

You will need to wait for OsgiEventTrigger to function again. I have it partially completed. It’s been broken for a long time now due to API changes.

Thanks for the info! Is it broken in the openhab core or in the helper libraries?

I was thinking that these triggers could be used to update my dynamically attached rule discussed in the other thread, without resorting to cron reload.

The API changed in OHC in OH 2.4 S1319. This broke many things in the helper libraries, including the custom handlers. I overhauled everything except for OsgiEventTrigger and DirectoryWatcherTrigger, and only a few people have noticed that they are still broken. The OsgiEventTrigger is needed for the ItemRegistryTrigger. I hoped to get these implemented in the rule engine rather than fixing them in the helper libraries, but I’ve already put some time into getting them fixed in the helper libraries. It should just take another weekend to wrap them up, but I have higher priorities.

Another factor is that ItemUpdatedEvent, ItemAddedEvent, and ItemRemovedEvent events have been in OHC for a while now, so the GenericEventTrigger can be used instead of the OsgiEventTrigger. You’ would need to use the extensions to build the rule, rather than the when decorator. Another weekend task. Lots of possibilities. But still, this should be done in OHC so that they would be available in the UI rule editor and other scripting languages.

In case you are thinking that you will be able to use ItemUpdateEvent for metadata changes, there are no RegistryChangeListeners or even metadata events, so there is nothing listening for metadata changes and no events emitted. Changes will be needed in OHC to do what you are seeking, assuming the maintainers allow it. Using groups is the best solution, which is why I used them in Area Triggers and Actions. The “Member of” Trigger has been added to OHC in OH 3.0. However, there does not appear to be any mechanism to reload rules to reproduce the functionality in the old rule engine.