var group = itemRegistry.getItem("Lights_Indoor");
var lightson = group.members.stream().filter(function(i){ return i.state == "ON" }).count();
var label;
if (lightson == 0) {
label = "Aus";
} else {
label = "Ein (" + lightson + ")";
}
events.postUpdate('Lights_Indoor_Count', label);
Result :
Lights_Indoor --> Group-Item
Lights_Indoor_Count --> In my case a String-Item, but can be a Number-Item in case you only would like to show the Number.
Works fine.
Still need extra rule for every group…
Only to simplify it a little bit: As you dont use the aggregate function anyway, you could define the Group Members Base type as number and update the Grouitem state directly:
var group = itemRegistry.getItem(“gDoors”);
var opendoors = Number(group.members.stream().filter(function(i){ return i.state == “OPEN” }).count());
events.postUpdate(‘gDoors’, opendoors);
That saves you to define an extra item and you could put something in Label like: = (items.gDoors.state == 0) ? “CLOSED” : “OPEN (”+items.gDoors.state+")".
If you only want the number you dont have to modify the label at all.
The other problem is also that you have to deal manually with the icon state…
=(items.gDoors.state == 0) ? “oh:door-closed” : “oh:door-open”
to create a second group with another base type, of course, would be an option.
But i would prefer to avoid creating another group and rule. Does some achieved it already without it?
The items get assigned to both groups.
gLight (gLichtErdgeschoss) is used to control all lights, gLightN (gLichtErdgeschossN: 0 aktiv) is used to show the number of active lights and results in a controllable group with the count of active lights: