Create Groups dynamicaly

Somewhere in the deepest area of my brain i have the impression that there is out there as discussion about adding items dynamically to groups, but i can’t find it. I only remember that is has somthing with light groups.

at the end my idea is to items to a battery empty group that is shown if a battery is empty an not to show the hundred batteries that are ok.

Someone any ideas


I think there is a method in the GroupItem class that lets you add an Item to the Group (don’t have access to Designer right now, can’t remember the exact name of the method). However, I’m not sure what happens with you do this from within your rule. It might not persist that Group membership beyond the life of that one rule execution.

You can achieve the same thing your are after with a filter.

val emptyBatteries = gMyBatterys.members.filter[battery|battery.state == Empty]

NOTE: Replace the “battery.state == Empty” with whatever test you use to determine when the battery is empty.

This works for rules for sure.

Assuming the add method in the GroupItem doesn’t work, I don’t know how you would do this on the sitemap short of listing each and every battery with a visibility tag.

However, I would handle this case as follows:

  • Make the battery group be the MIN of all the battery levels: Group:Number:MIN gMyBatteries
  • Show the group on the sitemap as a Text
  • You will be able to see if one or more of the batteries are low or empty by just looking at the Group’s value. You could even make the Group only appear if one or more of the batteries are empty. Then you open the Group on the sitemap and scan down the list until you find the one(s) that are empty
  • In a rule, when any member of the Group falls below a certain level send an alert with the name of the Batteries that are empty using the filter above

Hi Thomas,

maybe you mean the example from the “Sample Rules” create-a-dynamic-group-that-holds-only-items-in-state

Thats the way i create my dynamic groups:

gStateON.members.forEach[ item | gStateON.removeMember(item)]
gAll.allMembers.filter(s | s.state == ON).forEach[ item | gStateON.addMember(item)]

Thats it,

thanks for the link. Now i am looking for emt batteries in my system :slight_smile: