How do i get the linked item from channel

in a script i would like to get the item or itemname of the item linked to a named channel. is that possible ?

I would like to write w generic rule for my energy optimzation. there are different optimisation assets. for the optimisation. for abtraction from the real assets i would like to store the additional informations in a optimsation thing (mqtt). i just would like to link the item needed to be written to an existing channel of the optimisation thing, so the connection is done. how do i get the information from the linked object in rules ? that i may update them, or may i write to the channel from rule ?

any hints are very welcome!

Battery (Sunspec)
Number PowerOutLimit_Battery

Optimsation_Battery (mqtt)
Channel: Out
LinkedItem PowerOutLimit

Item: LoadProfile


  • every 15min
  • check setpoint from Loadprofile, write Setpoint to Item linked to Out-Channel

more or less somthing like this…

how to get linked Item

Thanks in advance


OpenHAB ( and any script) can only manage Items. It is recommended you name your Items intuitively.

Please study openHAB concepts.

is the problem … you may not be able for automated tasks anymore…

As long as you do not use the horrible Simple Mode you can do that.

Almost nobody here uses that mode.

There is some access to links and channels using REST API from rules.
It’s not really clear how you would be finding out or gussing a channel name, that you couldn’t also do for Item name?

Bear in mind channels may be linked to no Items or several Items also.

but still if i have pv-inverter, battery-inverter, pumps, i would like to have for each of the assets an loadprofile an 15 minutes basis, with mode, foreced mode and limits. i thought i hold the additional items in a special optimisation thing more or less related to the physical asset (thing) in the general rule i iterate over all optimsation things/item and do the neccesary tasks, depending on the loadprofile.i still need a way to connect energy managment assets linked with the physical assets… or tell the energy asset the relevant physical asset or item Out and In might be different datapoints on each energy asset.

what design do you prefer for such things ?

No idea what you are saying. Can you provide a sketchy example?

You can choose arbitrary names for your Items, but you can also choose names with meaning.
It is easy to create a rule triggered from a change in current that can “find” the correct voltage Item, do sums with them, and post the result to an Item
Is that the concept you are looking for?

no it’s more complicated…

i have think about energy prices on the market like epex, prices change each 15minutes. for that reason you need an optimzation of all energy assets for each specific 15 minutes…
depending on prices self generation, prices you may need to operate your energy assets… you self consumption might be not flexible over time but the pool pump or your ev might be. for each flexible assets it would like a specific logical layer for optimization calculations, the optimization calculations leeds into an load profile for each asset, with meta information about operating mode e.g. battery (on, off, auto, efficient, grid)
an optimzation thing should hold the optimization informations, switch, items …

like (first shot):

each 15 minutes load profile checked and related real asset controled …

Why do you think finding out which Item(s) are linked to a named channel will help? What associations are you trying to make/exploit? Are you familiar with the use of Item Groups in openHAB?

Bear in mind you can choose to name Items to reflect the name of a linked channel (like Simple mode does).
Thus you could derive an Item name from a channel name by simple string substitution.

It seems like an Item naming scheme is all you would need, although you may want to look into metadata too. Since you asked, you can get the Items linked to a Channel using…

from core import osgi
from org.eclipse.smarthome.core.thing import ChannelUID

ITEM_CHANNEL_LINK_REGISTRY = osgi.get_service("")

for item in ITEM_CHANNEL_LINK_REGISTRY.getLinkedItemNames(ChannelUID("kodi:kodi:familyroom:control")):
    # do stuff with Item

With OH 3.0, you’ll need to replace org.eclipse.smarthome with org.openhab.

1 Like

Hi Scott,

thank’s a lot, i alreaday have seen the metadata, but i need to think about, where to add the metadata…on the loadprofile item or somewhere else… i’m not clear at that point …

BR Lars

yes i’m familiar with groups more or less :wink: if i use the suggested simple mode on item linking, how do i get groups to automatic generated items ? is that possible ? maybe as default on the channel ?

I am not suggesting you use Simple Mode at all. It is a horror that will get in your way.

I was suggesting you copy its naming strategy only.
Simple Mode ‘sees’ a Thing channel like
and automatically creates and links an Item named

Simple Mode then hides this Item from you and prevents you editing it etc. which is why I do NOT suggest you actually use it.
But there is nothing stopping you naming your own editable Items using the same convention.

But you can see that if you have the channel name, it is very easy to work out the associated Item name.
I still have no idea why you want to do that, but there’s one way to do it.
There are others, using REST API

sry, i didn’t used the simple mode in the past … i thought for correct naming of items, it would be better … but as you told it isn’t … so i just will following the naming convention

You may find some hints here

@glhopital , thanks for posting those script snippets.
I’m especially interested in the discoverLinks function, but i’m running into problems immediately.

first this one:
failed: ImportError: No module named core in <script> at line number 1
and secondly, how would I call those functions from the the rule DSL?

What I’m trying to do is: retrieve a value from a channel, based on an item.
e.g. I have an item, which has channel links to two sensor values (temperature and moisture). How could I use the values from the linked channel in a rule script?


It may not work if you’re using OH3 because Jython Helper scripts are still not ported for this environment (see according post in the forum), so you may have to adapt it.
From a script point of view, you can never get values from a channel, they have to be hosted by an item to make the value accessible.