@Euphi, thank you for this! I’ve been working on making an adjustment for a few days now, and I could use some help. I’m converting my DSL rules to jsr223 Jython, and the most complex one relies heavily on nested groups which trigger the rule, and then using triggeringItem, another group is called by deriving it’s name from the name of the triggering group to take action on the lights, speakers, etc. in that area. Some day soon I’ll do a full writeup because this is working great… but I’m hoping for better performance with jsr223. Here is a simple example to illustrate what I’m trying to do…
Group gArea_Trigger
Group:Switch:OR(ON,OFF) gDS_FamilyRoom_Trigger (gArea_Trigger)
Group:Switch:OR(ON,OFF) gUS_LivingRoom_Trigger (gArea_Trigger)
Group:Switch:OR(ON,OFF) gUS_EntranceGarage_Trigger (gArea_Trigger)
Group:Switch:NAND(ON,OFF) gUS_EntranceGarage_Bathroom_Trigger (gUS_EntranceGarage_Trigger)
Group:Switch:NAND(ON,OFF) gUS_EntranceGarage_Lock_Trigger (gUS_EntranceGarage_Trigger)
gArea_Triggers
|_gFamilyRoom_Trigger
|_DS_FamilyRoom_Motion
|_DS_FamilyRoom_Contact
|_gLivingRoom_Trigger
|_US_LivingRooom_Motion
|_US_LivingRoom_Contact
|_gEntranceGarage_Trigger
|_US_EntranceGarage_Motion
|_US_Laundry_Contact
|_gUS_EntranceGarage_Bathroom_Trigger
|_US_GuestBathroom_Contact
|_gUS_EntranceGarage_Lock_Trigger
|_Lock_GarageAttached_Inner_State
gArea_Action
|_gFamilyRoom_Action
|_gDS_FamilyRoom_Bulbs
|_gLivingRoom_Action
|_US_LivingRoom_Dimmer
|_gEntranceGarage_Action
|_US_EntranceGarage_Dimmer
@item_group_triggered("gArea_Trigger", event_types=["ItemStateChangedEvent"])
def areaTrigger(event):
groupName = event.itemName.replace("_Trigger","")
for item in scope.itemRegistry.getItem(groupName + "_Action").getMembers():
#do stuff
Using .getAllMembers in your decorator returns the lowest leaf in the hierarchy, but I am looking for only direct descendants of the group. Changing to .getMembers creates the rules, but they never fire, and I have not been able to determine why. It’s entirely possible this is a bug somewhere. Is there any chance you could help me to modify your decorator, or create another? Or maybe @steve1 could point me in the right direction?
I started down the path of using your current decorator and getting the groups for the item that was triggered, filter on those that contain “_Action”, and then process those groups. Unfortunately, this destroys the simplicity of using the groups in the first place, since just because a device triggers does not mean the group has triggered.
Edit: I found something else. When I try…
@item_triggered("gDS_FamilyRoom_Trigger", event_types=["ItemStateChangedEvent"])
def test(event):
log.debug("JSR223: Area_Trigger: {0}: {1}: test [{2}]".format(event.itemName,event.itemState,event))
… the rule is created as with item_group_triggered, still with no errors, but the rule is never triggered. Switching to ItemStateEvent works, as well for item_group_triggered with .getMembers. This is looking like a bug using groups as triggers with ItemStateChangedEvent. I’m using OH snapshot 1302.
Edit 2: Correction. ItemStateEvent only partially corrects this. I was using Karaf to send updates to the group item, and this worked. But when the group is updated through item state changes, the rule is still not firing. As this is looking more and more like a bug, maybe @smerschjo could please take a look?
To summarize, when using item_triggered or item_grop_triggered (with decorator using .getMembers… not tested with .getAllMembers) with a group (without an itemtype) as the item, with members that are groups with itemtype and aggregation function defined:
- event_type=[‘ItemStateChangedEvent’] never triggers
- event_type=[‘ItemStateEvent’] only triggers when group state is directly updated, not when updated by member items