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

I know that It has been a while for this thread, but I’m using OH3.4.0.M1 and this is working fine without creating additional groups.

My use case is that I want to count how many alerts are active at any given time. By alerts, I mean count failed services marked by OFF or OFFLINE, OPEN contacts, UNLOCKED doors, OPEN gates or any OPEN Alarm zones in my DSCAlarm system, etc.

For my DSC Alarm system, I created a group DSCPartition1Zones with a Base Type of ‘Contact’ and an Aggregation Function of ‘One OPEN then OPEN else CLOSED’, then I added all the Zone Things to this group. I did the same for contact sensor equipment such as my outside gate contact sensors and my garage door contact sensor.

For my door lock equipments and monitored services (i.e. monitoring HTTP Service on BlueIris), or any equipment or thing that uses switch items that should be normally ON, I modified each to a Base Type of ‘Switch’ and an Aggregation Function of ‘One OFF then OFF else ON’,
If it’s equipment that should be normally OFF, then set the Aggregation Function of ‘One ON then ON else OFF’.

Then created a group(equipment) called “Alerts” with a Base Type of ‘Number’ and an Aggregation Function of ‘SUM’. Then I added each of the groups or equipments mentioned above to the Alerts group.

This works for both sitemaps and label cards. In both cases, it shows in REAL TIME how many items are in an undesirable state. The label card is very straight forward:

component: oh-label-card
  title: Alarms
  item: Alerts

And the sitemap code is also straight forward:

Text item=Alerts label="Alerts [%d]" icon=alarm
Default item=Alerts label="Alerts [%d]" icon=alarm
Group item=Alerts label="Alerts [%d]" icon=alarm



For sitemap, I use the visibility tag with the Group item, so that when I click on it, it only shows the
the active alerts. If there are no active alerts, it doesn’t show up at all in the site map.


1 Like