How to cout item states of group item in HABPanel

Hi

I’d like to count number of lights, which are switched on in a group. The group consists out of switches and dimmer.

I look to something similar like

{{(itemsInGroup('gLightsLiving') | filter:{state:'ON'}).length}}

Code above would work for switch items but not for dimmer.

Any tip for me?

1 Like

A dimmer would be considered on when it is set to a value other than 0. You can use separate filters based on each item type and add the counts.

{{(itemsInGroup('gLightsLiving') | filter:{type:'Switch', state:'ON'}).length + (itemsInGroup('gLightsLiving') | filter:{type:'Dimmer', state:'!0'}).length}}

Cool stuff by having two filters. This solves my issue partly.
But the Dimmer Filter is only working, if the state dos not contain a “0”. I tried it out:
state = 25 is counted as “On”, but state 0, 10, 20, 30, 40, … , 90 ,100 is counted as “Off”, due to the fact, that the state is transformed in a string and filter is checking if no “0” is in… grrrr

That is an oversight on my part. The filter needs to be set to strict comparison. Please try this version.

{{(itemsInGroup('gLightsLiving') | filter:{type:'Switch', state:'ON'}).length + (itemsInGroup('gLightsLiving') | filter:{type:'Dimmer', state:'!0'}:true).length}}
4 Likes

Works great! Thanks a lot! You made my evening :slightly_smiling_face:

I am interested in storing this same scenario in a variable on a rule. How can I accomplish this? I copied and pasted the solution post however got some errors, I did change my groups like this.

Group:Switch             gL_LucesSwitches
Group:Dimmer             gL_LucesDimmers

That helped me too. Thanks.

But what about color light…? I tried 0,0,0. But the lights only change the last part to 0.

Is it possible to write something like ,,0?

Greetings