[SOLVED] How to get thinguid of an item in jython?

Thing lgwebos:WebOSTV:living [ host="192.168.1.x", key="xxxx" ]
Switch LivingRoom_TV_Power { channel="lgwebos:WebOSTV:living:power", autoupdate="false" }

In my jython script, how do I get the ThingUID of the item “LivingRoom_TV_Power” ?

OK I’ve found the answer:

from core import osgi

ItemChannelLinkRegistry = osgi.get_service(
        "org.openhab.core.thing.link.ItemChannelLinkRegistry"
    ) or osgi.get_service(
        "org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry"
    )

for thing in ItemChannelLinkRegistry.getBoundThings("Item_Name"):
       thing_uid = thing.getUID().toString()

1 Like

Don’t do that… I actually have a pending change (__all__ = ["add_link", "remove_link"]) that will prevent this.

Thanks for the heads up! I’ve edited my post above.

1 Like

PS I have items bound to multiple things / channels. A very handy ability that one. Hence why I’m looping through getBoundThings instead of just getting the first thing.