Rules triggering at Group-Change of an Item

Hey Community,

is it possible to write a rule that says something like:

rule "Update"
when
Member of Member of MyGroup changed
then
...
end

So I need a rule, that looks at the Items of Sub-Groups from a big Group. Is this possible, without listing all Subgroups in such a way:

rule "Update"
when
Member of MySubGroup1 changed OR
Member of MySubGroup2 changed OR
...
then
...
end

And another Question:
I’m looking for a rule, that triggers when I change the Groups of an item in my .items file. Is it possible to write such a rule?

Member of Member of MyGroup changed

No, the Member of trigger is only for the direct members of the group. See:

You will have to list your subgroups

No. Why would you want this feature?

Because I need to recognize, wether the groups of an Item changed by adding or removing an Group to the Item to update this Item in my selfmade-program.

You can use a group change as a trigger but you can check if an item belongs to a group or not by using the Members method.

See:

Okay in the case i want to check wether an item belongs to a group or not, where do I get the information from, to decide which item left the group or was a member in this group?

You’ll have to code that

Is this possible to code that only in OH? And how? Could you give me some tipps?

What do you want to achieve?
Why do you want to change item’s group?
What is the purpose?

In my programm i want to filter my items by groups. But while runtime it could be possible, that some groups could be added to or removed at specific items. And in this case i want to update this specific items in my programm by sending update messages from OH.

Why?

E.g. to sum up specific function-groups to a single Item. Or to add a new item to specific groups, that didn’t exist before.

So you plan to create groups dynamically in code and attaching items for those groups
If you can code this then you can code the testing of items in groups or not before and after.

I am sorry, I don’t mean to sound difficult, but I tried this approach and it was very cumbersome and difficult to implement in code. I went back to the drawing board and defined my groups and items for all the functionality I required.
There are no limits on the numbers of groups you can create
There are no limits on the numbers of groups an item can belong to
There are no limits on the nesting of groups
With proper planning and naming convention I have all the functionality I require.

I followed my own coding and the following design patterns:

If I understood it right I’m working on the same approach. I use group membership and group trigger to do some actions. If I do not need a special item in the group I just remove it from the group. And I have proxy items which controll group membership. If needed I can provide my solution.

Example:
I have a group for door/window contact. This group is checked for changes. If I do not want to monitor one item I just remove it from the group and thats all. Some work must be done to ensure that the group internal handling works well.

Please provide your solution.
I’ve tried to work with group-change trigger like:

when
Member of MyGroup changed
then
// give me the triggeringItem.name

The Member is also a Group. I’ve tried also to change the ‘changed’ to ‘received update’ but without success. The rule triggers not, if I remove a Subgroup (Member) of MyGroup from an item.

Could the fact, that I remove the groups via the .items file, is the reason that the rule is not triggering? Or how can i solve it, that the rule is triggering when the Subgroups are added or removed from the items?

I’ve read something about that Groups need an Item Type in order to get triggered. But how can I trigger a Group that contains Items with different Types like Dimmer, Switch and String?

Did you find a solution?

Found the solution: https://www.openhab.org/docs/configuration/rules-dsl.html#implicit-variables-inside-the-execution-block