# OH3: Jython - Notification of every item in a group that fulfills a certain condition

**URL:** <https://community.openhab.org/t/oh3-jython-notification-of-every-item-in-a-group-that-fulfills-a-certain-condition/126916>\
**Category:** Scripts & Rules\
**Tags:** rules, python, notifications\
**Created:** [September 27, 2021, 10:51am UTC](https://community.openhab.org/t/oh3-jython-notification-of-every-item-in-a-group-that-fulfills-a-certain-condition/126916 "2021-09-27T10:51:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![boogie](https://community.openhab.org/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@boogie](https://community.openhab.org/u/boogie)\
**Post date:** [September 27, 2021, 10:51am UTC](https://community.openhab.org/t/oh3-jython-notification-of-every-item-in-a-group-that-fulfills-a-certain-condition/126916/1 "2021-09-27T10:51:49Z")

</div>

Hello everyone! For several hours i have been trying to get a simple rule to work, without success. I have read through the following articles and tried various approaches:

> **[But How Do I…? — openHAB Helper Libraries documentation](https://openhab-scripters.github.io/openhab-helper-libraries/Guides/But%20How%20Do%20I.html#items)**

> **[But How Do I…? — openHAB Helper Libraries documentation](https://openhab-scripters.github.io/openhab-helper-libraries/Guides/But%20How%20Do%20I.html#groups)**

> [@Design Pattern: Working with Groups in Rules](https://community.openhab.org/t/design-pattern-working-with-groups-in-rules/20512):
>
> Edit: Updates for OH 4, inclusion of JS Scripting and Blockly examples, removed the doors example as it’s superfluous. Please see [Design Pattern: What is a Design Pattern and How Do I Use Them](https://community.openhab.org/t/design-pattern-what-is-a-design-pattern-and-how-do-i-use-them/40319) for how to read and use DPs. Problem Statement One powerful way to consolidate code in rules is to use array/list manipulation operations on the members of a Group. For example, filter down to just those members that are ON, get a list of the labels of those Items that are NULL, etc. Concept T…

My current rule is:

```auto
from core.rules import rule
from core.triggers import when
import org.openhab.io.openhabcloud.NotificationAction as NotificationAction
import core

@rule("rule_notification_humidity")
@when("Member of group_humidity received update")

def check_humidity(event):
  if items["group_humidity"].state > 40:    
    get_items = [item for item in items["group_humidity"].members if item.state > 40]
    NotificationAction.sendNotification("xxx@xxx.com", "Alert humidity at" +get_items)

```

I also tried:

```auto
name = Transformation.transform("MAP", "entry.map", event.itemName.split("_")[0]
NotificationAction.sendNotification("{} has been open for over an hour!".format(name))

```

or:

```auto
ir.getItem("group_humidity").members.filter[item | item.state > 40].forEach[item | NotificationAction.sendNotification("xxx@xxx.com, "Humidity: " + item.name)]

```

or:

```auto
listOfMembers = [item.name for item in ir.getItem("group_humidity").members if item.state > DecimalType(40)]

```

I just want to receive a notification via the openHAB app (cloud connector) about all items that have exceeded a defined value. This notification should also only be given once an hour. Can someone help me with this, that would be great! Thanks in advance!

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [September 27, 2021, 11:06am UTC](https://community.openhab.org/t/oh3-jython-notification-of-every-item-in-a-group-that-fulfills-a-certain-condition/126916/2 "2021-09-27T11:06:23Z")

</div>

What happens instead of what you wanted? What are the states of your Items? (hint - units are part of the state)

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [September 27, 2021, 1:51pm UTC](https://community.openhab.org/t/oh3-jython-notification-of-every-item-in-a-group-that-fulfills-a-certain-condition/126916/3 "2021-09-27T13:51:19Z")

</div>

> [@boogie](#):
>
> `items["group_humidity"].members`

`items` is a dict using Item names as the key and the Item’s current state as the value. It is not a dict of the actual Item Objects. Therefore you can’t get the members of a Group using the `items` dict. You must pull the Group Item using the ItemRegistry.

> [@boogie](#):
>
> I also tried:

Well, that snippet of code is meaningless to us if we don’t also have the .map file and more information about the names of the Items.

> [@boogie](#):
>
> `ir.getItem("group_humidity").members.filter[item | item.state > 40].forEach[item | NotificationAction.sendNotification("xxx@xxx.com, "Humidity: " + item.name)]`

That’s a start. You are pulling the Group Item from the ItemRegistry before trying to get its members, but it’s using Rules DSL syntax to filter the list which does not work in Python (or any other language outside of Rules DSL).

> [@boogie](#):
>
> `listOfMembers = [item.name for item in ir.getItem("group_humidity").members if item.state > DecimalType(40)]`

This last one looks like it could work. So what’s not working?

Remember, we are not computers. We are humans. We usually need _all_ relevant information which often includes:

- should _should_ the code do
- what _is_ the code doing
- any and all relevant logs, especially errors.

You’ve given us what it should do but not what the code is actually doing nor any errors in the logs. At least three if your attempts should have generated error logs.
