Help with counting active items in a group

I have a quick question about counting active items in groups. I have a bunch of items defined as such, which refer to loads each ranging from 0 (off) to 1-100 (on). I would like to count the active nonzero loads:


Dimmer mod00ld0 "Module 00 Load 0" (gLoads)
Dimmer mod00ld1 "Module 00 Load 1" (gLoads)
Dimmer mod00ld2 "Module 00 Load 2" (gLoads)
...

I need something like below, but I cannot arrive at the correct syntax:

Group:Number:EQUAL(not 0)    gLoads  "Number of active nonzero loads [%d]"

Can someone offer a suggestion? Thanks.

Try it with OR only Values not 0 will count

My understanding is that Group aggregation functions do not currently provide what you are looking for. An alternative would be to create another item and update it with a rule.

Number    Active_Load_Count    "Active load count [%s]"

rule "Update active load count"
when
    Member of gLoads changed
then
    if (triggeringItem.state == 0 || previousState == 0) {// this could be removed, but will help reduce load with frequent changes
        Active_Load_Count.postUpdate(gLoads.members.filter(item | item.state > 0).size)
    }
end

If you are not currently using a recent OH 2.3 snapshot, you’ll need to replace the ‘Member of’ trigger with a trigger for each item within gLoads.