[SOLVED] Accesing all JSR223/Jython Item Values

I’m currently trying to access more values then “state” from the “Items” Object in JSR223.

the ir.getItem("My_Item").state works fine but I am trying to access Groups and Tags of the Item.

[r223.jython.turn off kitchen lights ] - Kitchen_Light1 (Type=SwitchItem, State=ON, Label=Kitchen Light, Category=light, Tags=[Lighting], Groups=[gSonoffSwitches, gMaster_Lights, gNonWorkRelatedLights, gDoStamp, Kitchen])

[r223.jython.turn off kitchen lights ] - <type ‘org.eclipse.smarthome.core.library.items.SwitchItem’>

If I simply log the raw object it returns its name and a nice tuple with all the data im trying to access, well and if I type it returns that is an eclipse Switch item.

Is there already a way to access: (Type=SwitchItem, State=ON, Label=Küchen Licht, Category=light, Tags=[Lighting], Groups=[gSonoffSwitches, gMaster_Lights, gNonWorkRelatedLights, gDoStamp, Kitchen]) values of the object?

Simiular to ir.getItem("My_Item").state? like item.group?

The background was my question in Design Pattern: Groups in Rules Thread

I have no idea how this relates to the tuple that gets printed when you log the Item itself, but I know you can get the list of Group names using ir.getItem("MyItem").groupNames and you can get the list of tags using ir.getItem("MyItem").tags. I suspect that what you are seeing is not a tuple at all but just how the Java Object’s toString prints.


Accessing the attributes and methods of an Item is the same as in the DSL, you just need to get the Item first. Use…

item = itemRegistry.getItem("my_item_name")

…to get the Item. To see your options, use…


You aren’t showing how you logged the Item, but as Rich said, it is the string interpretation of the SwitchItem instance.

Check out this doc too…


Unfortunately neither groupNames nor tags are mentioned in the “How Do I” page. I just knew how to do it based on experience.

I tried not to duplicate everything… my hint was for the use of dir

1 Like

Thanks! This did the Trick!
Also, the label is just item.label - when I tried it I only used it with every imaginable form group/s.

Yes, I figured it is not a tuple but rather the eclipse object string.



Thanks to you too! I did not think of dir(item) ^^ outside of a shell enviroment… my bad.
Uff thats a lot of goodies! Nice!

I just loged them with:

def getfromgroup(locationgroup, fuctionalgroup):

    locationgroup = itemRegistry.getItem(locationgroup).members
    fuctionalgroup = itemRegistry.getItem(fuctionalgroup).members

    return list(set(locationgroup).intersection(fuctionalgroup))

for item in t.getfromgroup("Kitchen","gMaster_Lights"):

Well, first of all, nice work on the Docs! But yea that was unfortunately not mentioned directly (or not obvious enough?).

Thanks for the fast help!

BTW is there a better way to get Shared group items than with my little helper function?

This may be helpful for you…

I don’t know about better, but a list comprehension will work too…

def getfromgroup(locationgroup, functionalgroup):
    return [item for item in itemRegistry.getItem(locationgroup).members if item in itemRegistry.getItem(functionalgroup).members]

Thank you… contributions are always welcome! There are 54 attributes and methods for a GroupItem. The helper library repo is not the proper place for them to be documented, since they do not have anything to do with the helper libraries. Javadoc has been written for them, but we still do not have a means for displaying it. However, some of the older Javadoc from ESH is still available.

Thanks This is indeed helpful i saw it in the Docs but was a little overwelmed since i just got into JSR. But this close to what i had in mind.

Yes thats good to know and im always happy to Help out :wink: The only thing for now, Holding me back is that im not fully got my had around how everything works together (JSR, Jython and the Java core?). I for example never found the source of the “itemRegistry”. So is this just a Wrapper around the Eclipse Code? Like Micropython for C?

Even better… Jython lets you use Java objects directly. You also currently have access to all of the non-internal OH packages, and any other Java or compatible Python 2 library you’d Iike to import.

The itemRegistry is made available in the default script scope for all languages. It’s located in openHAB core.