Is there a way to fire a rule if the item registry changed?
E.g., I need to reinitialise a rule if items are added to or removed from a group item, and I want to see if I can avoid having to restart OH (or use a “reinitialize” item to manually reinitialize) when this happens to fire a reinitialization of the rule.
I don’t think you can do this directly. However, if there is a log statement that reflects the changes you are making you can use the LogReader binding.
I believe that if you add or remove an Item from a Group it will cause the Group to recalculate it’s state so you could trigger on updates to the Group Item, but that will cause your initialization Rule to run a whole bunch of times.
Since you are already using the Jython helper libraries, try out the ItemAddedTrigger and ItemRemovedTrigger. You’ll need to use an extension rule, since I haven’t incorporated these into the decorators (yet). I haven’t tested these in a while, so hopefully they are still working. There are a few more undocumented gems in the libraries!
According to the documentation, these triggers only relate to rules being added, removed or edited:
ItemAddedTrigger - fires when rule is added to the RuleRegistry (implemented in Jython)
ItemRemovedTrigger - fires when rule is removed from the RuleRegistry (implemented in Jython)
ItemUpdatedTrigger - fires when rule is updated in the RuleRegistry (implemented in Jython, not a state update!)
I actually didn’t write this part of the docs… thank you for pointing this out. These triggers are for when Items are added/changed/removed. They subclass the ItemRegistryTrigger, which is a subclass of OsgiEventTrigger. Try the ItemUpdatedTrigger on the group Item. You could also use the GenericEventTrigger. If OH knows the event occurred, Jython can get to it.