Help Needed! items in group can't show the correct counts?

Hey guys, noob here, I am trying to show all my lights but seems like it won’t work, what have I done something wrong?
I have a root group called gLight that contains 2 sub-groups(gLiving and gKitchen, each group has lights)

Group:Switch:OR(ON,OFF) gLight "all lights" <light>
Group:Switch:OR(ON,OFF) gLiving "living area" <light> (gLight)
Group:Switch:OR(ON,OFF) gKitchen "kitchen area" <light> (gLight)

Switch liv01 "V1_liv01" <light> (gLiving)
Switch liv02 "V2_liv02" <light> (gLiving)
Switch liv03 "V3_liv03" <light> (gLiving)

Switch kit01 "V1_kit01" <light> (gKitchen)
Switch kit02 "V2_kit02" <light> (gKitchen)

Then in habpanel,

<div class="section">
  <div class="sectionIconContainer"><div class="sectionIcon"><svg viewBox="0 0 48 48"><use xlink:href="/static/matrix-theme/matrixicons.svg#light_bulb"></use></svg></div></div>
  <div class="title"><div class="name"><font color="#267A50">Light Counts</font></div>
    <div class="summary"> 
      ON: <font color="#267A50"><b>{{(itemsInGroup('gLight') | filter:{state:'ON'}).length}}</b></font>
      / OFF: <b>{{(itemsInGroup('gLight') | filter:{state:'OFF'}).length}}</b>
      / ALL: <b>{{(itemsInGroup('gLight')).length}}</b>

The result returns to total light counts is only 2, but I do have 5 visual lights, what cause this problem? Does the gLight group only counts 2 because there are only two groups in this group?(but can’t count the items in sub-group?)…

btw, do this code can counts item in groups and sub-groups?

Could someone please help a noob guy? Thank you so much!

OK so sorry about the noob and dump questions
I solved it by chaning to this:
{{(itemsInGroup('gLiving')).length + (itemsInGroup('gKitchen')).length}}

A simple + solved my pretty dump questions… and I wasting my whole day trying to make this right :frowning:

But still, I am wondering what cause the wrong counts of using just {{(itemsInGroup('gLight')).length}}
I thought gLight is the root group, it should counts the total items inside gLiving and gKitchen, it should returns value 5(lights, or items I should call), not value 2(two sub-groups)… why?

1 Like

The itemsInGroup function isn’t smart enough to expand groups in groups, it only returns the direct members of the group, sorry.

Are there Plans to have a function to expand groups in groups? I tried to solve this by an own filter but I came to my java script limits paired with my poor know how regarding Angular.js.

hi Kevin, did you find a solution to count up the members of sub groups? I have a nested group, and i want the members of each sub group added together to display how many are ON or OFF. Be keen to know how you got on.