[SOLVED] Filter based on group?

I’m trying to utilize ng-repeat to generate a list of all light switches present in my living room;

In my item file I have items for each light (switches, dimmers etc). Each item is a member of the group “light” and the group “livingroom” (or “bathroom”, depending on its location).

To generate a list of all light switches, I use the folling in a custom habpanel widget:
ng-repeat=“item in itemsInGroup(‘lights’) | filter:{type:‘Switch’}”

This obviously lists all light switches in my house. How can I filter these items to only list the switches present in the livingroom? adding | filter:{group:‘livingroom’} does not work.

Thanks in advance!

can’t you use:

ng-repeat=“item in itemsInGroup(‘livingroom’) ...

Thank you for your reply. That is not an option because I also have non-light switches in the livingroom.

Create another group only for your light switches in the living room

the “filter” filter with an object predicate (as documented in https://code.angularjs.org/1.5.11/docs/api/ng/filter/filter) is quite lax by default so I think it will even look inside subarrays.

item in itemsInGroup('lights') | filter:{type:'Switch', groupNames: 'livingroom'}
might just work.

1 Like

Yes! This works! Thanks

Quick question to the specialists,
I’m trying to create an ng-repeat with 2 groups based on config.groups, but I cant get it to work.
This is what I have right now:

<tr ng-repeat="item in itemsInGroup(config.item_group) | filter:{groupNames: (config.item_group2)}">

When hardcoding the 2nd group it works fine, but I cant get it to work with config item.

Secondly I’m wondering if itemsInGroup does support nesting? In rules I use gGf.members vs. gGf.allMembers. Is there an equivalent for itemsInGroup?
my use-case is:

Group gGf "Groundfloor"
Group gHallway (gGf)
Group gKitchen (gGf)

Items only belong to gHallway or gKitchen. Ideally I’d like to iterate over the gGf group and search for all gRollershutters or gLights and have them in a widget in HABpanel.
Thanks for your help.
Best Sebastian

Edit: Alternatively I could also loop over gRollershutter and filter on a item.name substring as my item naming convention start with level_room_item_function

For the time being I’ve worked around the issue myself.
I’m looping over the whole group and do ng-if within the loop to only display items matiching the filter pattern.
Its a bit of resource overhead, to process items that are not neede, but should be fine.

In case someone has a more elegant solution, please let me know.

Hi Guys

I cant seem to get this to display

Im trying to get the number of switch items that are ON to display, but I get nothing. The items are in the group. Even removing the type: doesnt show anything

 <div class="title">
                    <div class="name" class="item in itemsInGroup('gDownstairsHallLights') | filter:query as filteredDownstairsHallLights">Hall</div>
                    <div class="summary on lights">ON: {{ ( filteredDownstairsHallLights | filter: { state: 'ON', type:'Switch' } ).length }} of {{filteredDownstairsHallLights.length}}</div>
                    <div class="summary on temp">Temp: {{itemValue('Downstairs_Passage_Motion_Temp')}}&#176C</div>
1 Like