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

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:



My current rule is:

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

@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:

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


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


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!

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

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.

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.

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).

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.