in a script i would like to get the item or itemname of the item linked to a named channel. is that possible ?
Description:
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!
e.g.
Thing:
Battery (Sunspec)
Items:
Number PowerOutLimit_Battery
Thing:
Optimsation_Battery (mqtt)
Channel: Out
LinkedItem PowerOutLimit
Item: LoadProfile
Rule:
every 15min
check setpoint from Loadprofile, write Setpoint to Item linked to Out-Channel
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.
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.
Freds_meter_voltage
Freds_meter_current
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
Freds_meter_kw
Is that the concept you are looking for?
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 ā¦
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("org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry")
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.
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 ā¦
yes iām familiar with groups more or less 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 solaredge:generic:PV:live#consumption
and automatically creates and links an Item named solaredge_generic_PV_live_consumption
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
@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.