Access item category in custom widget

I use the widget-icon tag in a custom widget as follows:

<widget-icon iconset="'eclipse-smarthome-classic'" icon="'mycan'" size="config.icon_size" state="itemValue(config.item_name)">

I like to show a custom icon added to /etc/openhab2/icons/classic. For that I configured my item definition with category “mycan”. Is it possible to retrieve the item category in a custom tag like the item value (itemValue), so I do not need to hard code the icon name?

As far as I can tell, items do not have any “category” attribute.

If I well undestand you may want to include the icon name in the widget configuration, isnt it?
If so, just replace ‘myscan’ with config.icon_name and include icon_name in the configuration widget.

See here: HABPanel Development & Advanced Features: Start Here!

  • getItem(itemname): retrieves the complete structure of the item as formatted by openHAB’s /rest/items API;

The structure in question is documented here: http://demo.openhab.org:8080/doc/index.html#!/items/getItemData (or your own instance if you installed the REST API documentation bundle)

Therefore this expression will likely work: getItem('Your_Item').category

Tip: you can use for instance <div>{{getItem('Your_Item') | json}}</div> to have a look at the whole JSON object.

1 Like

Your solution works like charm.

Thank you for pointing to the rest API that was exactly the information I was looking for! It shows you all the possibilities you have to access items in template or custom widgets.