I’m delighted by the member of group trigger feature, coupled with triggeringItem, as introduced in OH 2.3 and discussed here. (Thankyou devs!!)
It’s a very powerful feature set.
I think there is a missing feature though, which might be called triggeringGroup. An implicit variable giving the Group that triggeringItem is a member of, when the Member of trigger pattern is used.
To give a use-case ; suppose we have a number of sensors divided into several groups representing areas. Each area group associated with a light.
Group gBothyards Group gFrontyard .. (gBothyards) Item Contact SensorA .. (gFrontyard) Item Contact SensorB .. (gFrontyard) Item Switch FrontyardLight Group gBackyard .. (gBothyards) Item Contact SensorX .. (gBackyard) Item Contact SensorY .. (gBackyard) Item Switch BackyardLight Item Contact SensorQ .. (gFrontyard, gBackyard) // member of both
We might want to write a single rule to handle any sensor event and control the approprate light
rule "handle sensors" when Member of gFrontyard received update or Member of gBackyard received update then // we know what sensor triggered with triggeringItem // but we do not know which group it is in // if we knew which group, we could work out the light to operate end
I do not think there is a direct way to discover which group(s) an Item is a member of?
It would be possible to test if our triggering Item is a member of each possible group in turn, but that feels a bit hacky.
So my thought would be to have a triggeringGroup implicit variable in a similar way to triggeringItem.
This would get populated when Member of … is used.
This may or may not get populated when a group is used as a direct trigger like so?
rule "normal trigger example" when Item gFrontyard received update or Item gBackyard received update then // the group will of course be in triggeringItem // our imagined triggeringGroup may or may not contain it as well? // It should NOT contain gBothyards as that was not involved in triggering.
My gut feel is to only populate it when ‘Member of’ is involved.
I do not know how much effort would be involved in creating such an implicit variable, I suspect it might be fairly easy?
But is it worthwhile, useful?
EDIT - added the case where an Item is a member of both possible triggers. Expected action - rule triggers twice, once for each Member of, while triggeringGroup is different each time ?
EDITED AGAIN - yes, SensorQ will trigger the example rule twice - once for each membership condition satisfied.