Trigger based on group state in OH3?

Hi there,

I’m just getting used to OH3. I’ve got a group “windows” that contains motion sensors and I want to get a notification if a window is open for more than 10 minutes.

The group looks like this:

I then created a rule via the UI as a test:

triggers:
  - id: "1"
    configuration:
      itemName: windows
      state: ALARM
    type: core.ItemStateUpdateTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: >-
        var telegramAction = getActions("telegram",
        "telegram:telegramBot:xxx")

        telegramAction.sendTelegram("Windows Open!")
    type: script.ScriptAction```

Somehow it doesn't trigger. I guess because of the status "Err" in the windows group.
Why is this, isn't the state of the group similar to the state of all contained items?
(closed = motion, open = alarm for these motion sensors).

Followup question: I thought about how I would do the 10 minutes part. A way I can think of is create a dummy item with an expiration timer (metadata in OH3) of 10 minutes and send a message if it receive a command after 10 mins OR if windows.state updates to MOTION (all are closed) just update the state of the dummy item without a command, not triggering the msg.
Does this sound right?

“Err” in your display means the UI has a problem showing the state - not that there’s anything wrong with the state. For example, you asked for a decimal format display, but the actual state is string,or something like.

For your rule, you might be more interested in “Member of” style triggering anyway.

Thank you, I understand!

I’ve changed it to member of state change, and it works. With OH2 I just had a check on windows.state and it worked.

This seemed easier for the second part: How would I now check if all Windows are closed (in state MOTION)? So I can cancel the alarm if one is updated?

Edit, I just realized the Group definition (textfiles) in my old config is:

Group:String:AND("MOTION", "ALARM") windows "Open Windows [(%d)]" <contact> (all)

Is it possible to somehow add/use this in OH3?

I’ve got it working, with the following 3 rules, but I have one question left:

Set Timer based on Group state:

triggers:
  - id: "1"
    configuration:
      itemName: windows
      state: ALARM
      previousState: MOTION
    type: core.ItemStateChangeTrigger
conditions:
  - inputs: {}
    id: "3"
    configuration:
      itemName: dummy_windows_alarm
      state: OFF
      operator: =
    type: core.ItemStateCondition
actions:
  - inputs: {}
    id: "2"
    configuration:
      itemName: dummy_windows_alarm
      command: ON
    type: core.ItemCommandAction

Cancel Timer based on Group state:

triggers:
  - id: "1"
    configuration:
      itemName: windows
      state: MOTION
      previousState: ALARM
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      itemName: dummy_windows_alarm
      state: OFF
    type: core.ItemStateUpdateAction

Notify if timer expired:

triggers:
  - id: "1"
    configuration:
      itemName: dummy_windows_alarm
      command: OFF
    type: core.ItemCommandTrigger
conditions:
  - inputs: {}
    id: "2"
    configuration:
      itemName: dummy_windows_alarm
      state: ON
      operator: =
    type: core.ItemStateCondition
actions:
  - inputs: {}
    id: "3"
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: >-
        var telegramAction = getActions("telegram",
        "telegram:telegramBot:xxx")

        telegramAction.sendTelegram("Please close windows!")
    type: script.ScriptAction

Question: With OH3, how can I import the Group definition, or change it?

Group:String:AND("MOTION", "ALARM") windows "Open Windows [(%d)]" <contact> (all)

Also, the %d formatting doesn’t seem to work

Import it from where?

You seem to be defining your Group Item from a file, so to change it you would edit the file contents.

No, it never ever works with String type Items because it is a decimal format.
Remember the “Err” display?
Perhaps %s is the format you seek.

You seem to be defining your Group Item from a file, so to change it you would edit the file contents.

What I meant is: Is there a way to define this aggregation in the UI as well?

Right, I must have confused it. I’d like to have the state AND the count of open windows. Which doesn’t seem to be possible according to: Items | openHAB
There is only an example for switches with both.

However, I could use the example with count:

Group:String:COUNT("OFFLINE")

And change my rules to check for != 0

As well? No. Instead of …
If you define your Item from file, edit the the file.
If you create your Item in UI, edit in UI.
However
There is a UI bug that does not currently offer all possible aggregation types for all Group types.

Hm yes, I don’t even see String in the Member Base Type selection, that’s why I asked…