dniklas1
(Daniel)
May 25, 2025, 11:53am
1
I have a group with the member base type rollershutter so that I can control all the roller shutters in the house simultaneously.
Now I would like to count all the roller shutters that are closed (i.e., have a state > 0).
Is this possible?
What am I doing wrong?
rlkoshak
(Rich Koshak)
May 25, 2025, 2:40pm
2
I think COUNT only works with Switches and Contact Items. You’ll need a rule and a separate Item to keep up with the count like that. Thankfully it’s a one liner. Trigger the rule when any member of the Group changes. In JS the action would be:
items.Closed_Shutters.postUpdate(items.Gruppe_Rolladen_Alle.members.filter(rs => rs.state == "0").length);
The above assumes 0 means the rollershutter is closed. Change to 100 if it’s the inverse.
RegEx is at odds with me, but with [1-9]\d*
I get a value back that seems plausible.
dniklas1
(Daniel)
May 25, 2025, 6:37pm
4
Good idea, that works. this is what it looks like now:
component: oh-label-card
config:
action: group
actionGroupPopupItem: Gruppe_Rollladen_Alle
icon: =items.Gruppe_Rollladen_Alle_Geschlossen.numericState == 0
?'oh:rollershutter-0':'oh:rollershutter-100'
iconUseState: true
item: Gruppe_Rollladen_Alle_Geschlossen
noBorder: false
title: Rollladen
The rule:
When:
var numberClosedRolladen = items.getItem("Gruppe_Rollladen_Alle").members.filter(rs => rs.state > 0).length;
var rolladenClosedItem = items.getItem("Gruppe_Rollladen_Alle_Geschlossen");
rolladenClosedItem.postUpdate(numberClosedRolladen);
Thanks!