Lights Summary with Dimmers

Hi all

I am an openHAB beginner trying HABPanel with Matrix Theme.
I am trying to get the summary of lights based on their status (ON/OFF).

All my light items in the attached picture are Dimmer type.
With Dimmer type, the summary doesn’t work.
It works if the items are changed to Switch type.

Here is my template

<div class="title">
    <div class="name">Lights</div>
		<div class="summary">ON: {{ ( filtered | filter: { state: 'ON' } ).length }} off {{filtered.length}}</div>
  </div>

Please suggest alternative to filtering state:‘ON’ so that it could work with Dimmer type.
Thank you!

If you look at what the dimmer state is, it is numeric. Zero would be “off”, greater than zero “on”.
So you’ll want a test something like "> 0"

The pitfall is that the state will arrive in your script as a string I think, so you’ll have to parse it to a number before you can do the numeric comparison.

1 Like

Thank you!

I had another idea by creating a Group with all light items, then filtering based on type and checking their state to be non-zero…it works :slight_smile:

<div class="summary">On: {{ ( filtered | filter: { state: 'ON' } ).length + ( itemsInGroup('gLights') | filter: {type: 'Dimmer', state: '!0'} :true ).length }} Off {{ filtered.length }}</div>

I’m not sure about the options HABpanel, but if state is the standard method, maybe there is also the method getStateAs(). With getStateAs(OnOffType) you will get ON and OFF even for dimmers.

This is true for DSL rules, in HABPanel I don’t know…