Item access in Python personal libraries

I am still somewhat new to the JSR223 scene and I’m getting a pretty good handle on most of it. I just ran into this one question I can’t seem to find the answer to in the documentation. What I’m attempting to do is write some personal libraries of functions I think I’m going to be using in multiple places. In those functions I’d like to be able to retrieve items and send commands. However when I use the command:


I get an error that states: “global name ir is not defined”

In my library file I included “from core.jsr223 import scope” but that doesn’t seem to help. Is there an import I’m missing? Can someone point me to how I can get an item and send commands from my own library functions?

You’re close! With what you have, you could use…

thisItem =

But it would be cleaner to use…

from core.jsr223.scope import it

thisItem = ir.getItem(item)

ok, thanks for pointing that out. I feel like I keep digging in documentation and just missing little things. Do you know which one has the type definitions? (i.e. HSBType, OnOffType, etc…)

Reading through the core and community libraries is helpful for hints with working with packages and modules. Everything in the default script scope is available with…

from core.jsr223.scope import HSBType, OnOffType

OK, yeah that’s making sense now. I will keep digging. The organizational structure is starting to make sense now. I really appreciate you taking the time to answer my newbie questions :slight_smile:

No problem… bring 'em on! The more questions that get asked and answered in the forum, the more the forum gets populated with info that will help others. It’s also good feedback for the documentation, which I polish up after answering questions in the forum.

1 Like