OH3: get item or group from standard widget

Dear, i am not find the approach about:

I build item comparable groups with same items like string, switch, shutter etc. (item_grp_1, item_gpr_2, etc.) and in the page I use only the standard widget to view all items in this groups.
One of this item (like string) start a rule (DSL/Javascript) if the user pushed on this item. Now I need to identify the item or the group item within this rule.

But: I did not know the item name, which is pushed from user!

Could you get me a little help?

Not sure, but within JS you get the item with

var eventItem = ir.getItem(event.itemName);

Hope, this helps.

Thanks, but: I did not know the item name (itemName), which is pushed from user!

How is your rule triggered? You’re probably looking for ‘Member of’ features.

Rule is Triggered by Label-list-item, action

do you mean member from group item? Or where i am find „member of“ features?

Ah, I was talking about rules. You’re talking about UI widgets.

Yes, you are right;

I have about 50 items within ui, so that „dummy“ solution is for all items copy and paste the rule😠

Anybody a generic solution - i need always the value of the item that triggered by user via ui!

There’s no way to directly send a value to rule that you call with the UI. Fortunately, there is a very simple workaround. You just need a single proxy string item. When the UI component is triggered, you don’t want to use the rule action, you want to use the command action to set the value of your proxy item to the full name of the real item you want utilize. Then you just need to set your rule to run when that proxy item changes and process the string in the proxy item however you need to get item name and group information. You can see a similar example here: OH3 Widget: Dynamic Favorites Bar.

Hi hobaka,

I think I did not get your scenario, maybe some code would be helpful. But I try in my words:

  • You have items in a standard widget which are starting a rule
  • Within this rule you need to know which item executed the rule

If these assumptions are right, you can get it with

var eventItem = ir.getItem(event.itemName);

event.itemName is a fixed variable which contains the name of the executing item. You can also get the group(s) with

var eventItemGroups = eventItem.getGroupNames();

It is an array with indexes. But you need the eventItem (the other code line).

If this not what you are searching for, I need more information about your code.


Dear, thanks for your support - Now i have a Solution with two Proxy Items, like JustinG.

The idea from HFM did not work … sorry

But I think it must go easier?!

First i have a address number item in UI and with this number i am look within XML file for an eMail address and send an eMail via JavaScript.

Therefore i am using a rule with dsl and JavaScript: First dsl-Rule select via Command Action the address number (First Proxy) and via xpath transform in XML file i am save the email address in the Second Proxy item;

in the JavaScript rule i am using the eMail Proxy item and send an eMail…,