Get number of ON lights from a group in a widget?

Hi everyone,

I’m trying to display the number of lights that are currently ON from a group inside a MainUI widget.
The group contains several Switch items (lights).

This is the expression I’m currently using:

=(props.statusLightGroup && items[props.statusLightGroup]
  ? items[props.statusLightGroup].members.filter(m => m.state === 'ON').length
  : '0')

Unfortunately this does not work as expected (it either shows nothing or always 0).

My questions are:

  1. Is it generally possible in widgets to access the members of a group and evaluate their states?
  2. If not, what is the recommended way to display the number of items that are currently ON within a group?
  3. Do I need to use additional items/rules (e.g. a Number item updated by a rule), or is this doable purely in the widget?

Thanks in advance for any hints!

Not through the items object. That always has a very restricted amount of information about an item and will never return the members of a group.

You can use an oh-repeater to get all the members of an item. There are a couple different ways to do this, but the easiest is probably just to put a unique tag on the group item and use the repeater’s itemsWithTags source to get that one item. The object returned by the repeater is a complete representation of that item including the members array.

Even though this can be done in the widget it is not the best way to do it, in my opinion. I do this in numerous different situations and just use the group aggregation functions. Boolean values such as switches are treated as 0’s and 1’s so a simple sum aggregation gets you the number currently on:

Then you can just get the state of the group item as usual (and since it’s a number value use the # shortcut):

footer: "=(items.gLights.state == 'ON') ? `${#'gLightsCount'} (${#'gLightsCount_Upstairs'},  ${#'gLightsCount_MainFloor'},  ${#'gLightsCount_Basement'})` : ''"

Can you give me a complete code segment also with the items definitions

There’s no fancy code. This just comes from the standard group aggregation:

And the text item definition would be a short as:

Group:Number:SUM gLightsCount_Upstairs "Upstairs Lights On Count"

You can also create it easily in the UI and copy over the text definition if you would prefer.

I’m working on a oh-rpeater (multi-item-list-for-and-for) to iterate over multiple groups of items and display them in a list. I want to:

  1. Count only items of type Contact (doors/windows).
  2. Count the number of open windows and store it in a variable vars.countOpenFenster directly inside the oh-repeater.

Here’s the relevant snippet of my current setup:

uid: multi-item-list-for-and-for
tags:
  - list
  - repeater
props:
  parameters:
    - description: Comma‑separated list of groups (e.g., Group1,Group2)
      label: Groups List
      name: itemsList
      required: true
      type: TEXT
timestamp: Feb 1, 2026, 10:48:49 PM
component: f7-card
config:
  title: Door Sensors
slots:
  default:
    - component: oh-list
      slots:
        default:
          - component: oh-repeater
            config:
              for: item
              sourceType: array
              in: =props.itemsList.split(',').map(x => x.trim())
            slots:
              default:
                - component: oh-repeater
                  config:
                    for: subitem
                    sourceType: itemsInGroup
                    groupItem: =loop.item
                    filter: loop.subitem.type === 'Contact'
                  slots:
                    default:

Current problem / questions:

  1. How can I count the number of open windows (OPEN) and store it in vars.countOpenFenster directly in the oh-repeater?
  2. Is it possible to do this inline, without using an extra component?

Any tips or example code would be greatly appreciated!

You cannot. There is no variable assignment in widget expressions. Variables can only be set in an oh-context for a default value or as a result of a user action.

There are very convoluted ways to abuse an oh-repeater to get close to what you want to do, but to be honest, getting them up and running will take longer than just setting up some group items that do the counting for you automatically. I think the widget method would also be more prone to breaking whereas the group method will be robust and long-term stable.