[SOLVED]How to use Group items with the jsr223 engine/python?

I just wrote my first python rule using the jsr223 engine, and found it a lot easier than using xtend.
But how can I access Group items, and in particular iterate through a list of all members? In xtend that would look like this:

do something

How can this be done using python in the jsr223 framework?


I’m not at my development computer right now to verify the exact syntax, but you should be able to do something like…

for item in group.getAllMembers():
    # do something

If you need to filter the items, you could do something like…

for item in filter(myfilter, group.getAllMembers()):
    # do something

Where myfilter could be a Python function or lambda taking an item as an argument. You could also use list comprehensions to filter or transform the group members.

Works, thanks!

Steve, do you happen to know how this works in OH2?
Seems I can’t just use the group name as variable in jython.

found it.

for raffstore_position in itemRegistry.getItem('Raffstore_Position').getAllMembers():

hey @Bernd_Pfrommer I noticed you edited the topic to [SOLVED] but its not solved for the system.
Could you mark the Topic as solved? First button :slight_smile:

Thanks for pointing this out!