Display number of switches in a group

My first steps with openHAB2 are done.
I have an item file like:

Group:switch:OR(ON, OFF) gBM_Light_WZ "Lampen im Keller [(%d)]" <cellar>
Switch BM_Light_WZ_TV_L "Hue TV links" <light> (gBM_Light_WZ) {channel="hue:0200:12345679:1:color"}
Switch BM_Light_WZ_TV_R "Hue TV rechts" <light> (gBM_Light_WZ) {channel="hue:0200:12345679:2:color"}
Switch BM_Light_WZ_hinten_L "Hue hinten links" <light> (gBM_Light_WZ) {channel="hue:0200:12345679:3:color"}

On the sitemap I can use this item as a switch and as group. I have seen some screenshots, where ppl display the number of members in the group, e.g. https://community.openhab.org/t/group-contact-vs-group-switch/12763. How to do this? (Besides I learned some Java in my apprenticeship, my Java-knowledge is nearly gone after 15 years and I bearly understand Java formatter class :worried:)

Switch item=gBM_Light_WZ icon=light
Group item=gBM_Light_WZ

var Number numAll = GroupName.members.size
var String retVal = "message " + numAll.intValue


Thx for your reply.

So there is no build-in procedure to display the number of members?

Where do I put this code: item, sitemap, … ?

I would be very happy if you could explain the code, so I know how things work.

Hello! Here is an example, in a group of 3 network device on the map displays the site as the network of all devices.


network:device:ip_192_168_215_101 [ hostname="", port=0, retry="1", timeout="5000",refresh_interval="60000", use_system_ping="true",dhcplisten="false"]
network:device:ip_192_168_215_111 [ hostname="", port=0, retry="1", timeout="5000",refresh_interval="60000", use_system_ping="true",dhcplisten="false"]
network:device:ip_192_168_215_112 [ hostname="", port=0, retry="1", timeout="5000",refresh_interval="60000", use_system_ping="true",dhcplisten="false"]


Group	gNetGarage
String	net_garage			"Garage [%s]"					<network>
Switch	net_garage_router	"Router ("		<network>	(gNetGarage)	{ channel="network:device:ip_192_168_215_101:online" }
Switch	net_garage_server	"Server ("		<network>	(gNetGarage)	{ channel="network:device:ip_192_168_215_111:online" }
Switch	net_garage_computer	"WorkStation ("	<network>	(gNetGarage)	{ channel="network:device:ip_192_168_215_112:online" }


rule "Garage"
    Item gNetGarage received update
    var Number numOnline = gNetGarage.members.filter(s | s.state == ON).size
    var Number numAll = gNetGarage.members.size
    var String retVal = numOnline.intValue + "/" + numAll.intValue


sitemap garage label="Garage" 
    Frame {
		Text item=net_garage {
			Text item=net_garage_router
			Text item=net_garage_server
			Text item=net_garage_computer
1 Like

Now it is working for me as described in the first post.
I did a second install of openHAB2 (this time on windows, the other one is openhabian on a RPi3), used the demo package. This uses the same code as I did in #1 demo.items and demo.sitemap

Two things were faulty:

  1. My Lightify Plug connect to Hue Bridge sometimes gets status NULL instead of ON or OFF - this gets the whole group gBM-Light-WZ faulty.

  2. items and their state seem to stay in memory or something, so altering my item files did not change everything: I did remove the Lightify Plug item and it still did not work - only full restart of openHAB clears cache/memory

I’m sorry, but I probably do not understand how to help you, perhaps I do not understand correctly, it is very bad English I (or rather from Google translator ha ha ha)