openHAB3 Group Count on Label Card


How can I add the number of “Lights ON” to this label card?


This is a group item with setting:


There is an option to display an expression result:


I tried this: =COUNT(ON) Lights_Indoor “[(%d)]”

Unfortunately no number and no errors.

How should the expression looks like? Or not implemented yet in OH3?


I do not know the recommended way, but I think this should work.

You could make a virtual Item to store that cound and have a rul increment or decrement the number for every state change in that group.

I’m interested to these topic too…

In openHAB2 it was possible to add %d to the aggregate group function:

Group:Switch:OR(ON, OFF) Lights_Outdoor “Lichter Aussen [(%d)]”

To have the same in OH3 label card I don’t know yet :worried:

I am interested, too.

Could anyone realize this, yet?

1 Like

I have implemented this now with a rule:


var group = itemRegistry.getItem("Lights_Indoor");
var lightson ={ return i.state == "ON" }).count();

var label;

 if (lightson == 0) {
   label = "Aus";
 } else {
   label = "Ein (" + lightson + ")";

events.postUpdate('Lights_Indoor_Count', label);


Result :slight_smile: :


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.

Hope this helps…

1 Like

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:

Your rule could then also be a bit simpler:

var group = itemRegistry.getItem(“gDoors”);
var opendoors = Number({ 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?


I am facing the same issue with OH3.
For now I have created two separate groups for example:

Group:Switch:OR(ON,OFF)    gLight
Group:Number               gLightN 

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:

From the documentation, however, I have also expected another behavior (Items | openHAB):

Group:Switch:OR(ON,OFF)     Lights        "Active Lights [%d]"              // e.g. ON and "2"
Group:Number:COUNT(ON)       Lights  "Alle Lichter [(%.0f)]"  <light2>  


1 Like

Did anybody find a solution in the meantime without creating a second group or a rule?

1 Like