Custom Widget Item Properties

hi,

for my custom widget i need to acces the persistence values of an item like “previousState()” or “lastUpdate”.

is there a way to access them within the widget or do i have to define seperate items which hold this states.

During search i found that

=items[ITEM]

has

=items[ITEM].state
and
=items[ITEM].state.displayState

is there a documentation where this properties are defined or a posibility to see them in the browser development mode?

Greets

You have to use separate Items.

It only has a displayState when you’ve configure the State Description metadata on the Item.

Those are the only two properties on items[ITEM], and the only one guaranteed to be there is state.

This is documented at Building Pages - Components & Widgets | openHAB.

You can see the result of any expression using the Expression Tester in the Developer Sidebar (alt-shift-d in MainUI or in the Developer Tools menu).

1 Like

Indeed the objects in the items expression object have at most 2 properties, state (always) and displayState (only if there’s a format pattern or transformation involved).
If you want to display the state somewhere but are unsure of whether the item has a displayState or not you can use the logical OR operator since it can be used with non-boolean operands i.e.:
=items.MyItem.displayState || items.MyItem.state will return the displayState if it exists, or the state otherwise.

2 Likes