Navigate to the Item you want to set the metadata for. Click on “Add Metadata”. Select “State Description” from the list of well known metadata. Populate the Pattern field with your state formatting options.
Wow! Very fast response!!!
Good news, I found it, bad news, I didn’t get the syntax working.
What I want: item channel (Name of the channel: lastseen ) should be formatted.
I did several tries, but nothing happens. One of them is:
value: " "
config:
pattern: "[YYYY-MM-DD]"
I also put the channel name behind value. But, again, nothing happens.
Are you sure it’s stateDescription? This doesn’t give me anything (undefined). I use displayState, although this is not working when I loop through my items (with oh-repeater)
Any idea where we can find all possibile parameters for items which can be use in widgets?
Both of them does not change anything
I am lost, I thought, formatting should be done with dayjs(), but anyway:
Putting the code in stateDescription or displayState ( this is a new Namespace ) does not change anything.
And, in the GUI, there is no other option possible.
You seem to live in a different time zone (I’live in Germany and am awake again - nice to see such a lively thread.
However, I didn’t get your solution to work, Rich.
I went to settings / item (Equipment Gaming PC) / metadata /pattern and added %te.%tm.-%tH:%tM . I also tried %1$tY-%1$tm-%1$td. And just to be on the safe side, I tried HH:mm. None of these changed the format in the item.
Here’s the code I get in “edit item metadata”
value: " "
config:
pattern: “%te.%tm.-%tH:%tM”
That makes sense, now it basically works.
“Just” one more problem: When I enter “%tM” I get the correct minute, same with hour. But when I try to combine more than one (e.g. %tH:%tM or what I’d really like %te.%tm.-%tH:%tM) I get ERR.
There is way more available in a loop in an oh-repreater element. Everywhere else all you have is the state and displayState. I don’t know what isRootInsert is either.
I just happened to select an Item at random. The fact that it’s a Group is just a coincidence.
But, assuming that the Group Item has a state it works exactly the same.
I have seen cases where the page needs to be refreshed before changes to that sort of metadata gets picked up. There is no other event generated to tell the web page that the metadata has changed.
Here is a state description (in YAML) from a Number:Time Item which takes the same formatting as a DateTime.
value: " "
config:
pattern: "%1$tH:%1$tM:%1$tS"
You cannot set this on a component. It’s completely separate from the widgets. It’s never going to work that way.
well, thank you all, now it works like it should!
Looking at Formatter (Java SE 11 & JDK 11 ) I’d never have guessed the format. Didn’t see anything about “%1$” or what it means but I’ll remember now.
I’m trying to achive the similiar thing for an large numer of datetime Items that has been generated in the text file.
They have a display formating embeded and that works for displaying single item in the
But when I try to do that in the oh-repeater loop I only display loop.item.state that will have default time formating.
The above solution is not working me as metadata are locked for bulk generated items.
is there a way to access proper formated datetime from within the loop for my case?
You mean for Items defined in .items files? Well yes, if you have the defined in text files you cannot change them in the UI. But you can add the metadata in your .items files. It will be something like
Ok, thank for pointing me in the right direction so I did setup of the state description in the items file
The correct syntax accoring to some other post I found is (just pattern without “”) DateTime SAIP_004_Temperature_LastUpdate "Temperature LastUpdate [%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS]" (modbus_LastUpdate) { channel="mqtt:topic:eui-oh3:moxa:temperature_1" [profile="system:timestamp-update"] , stateDescription=" " [pattern="%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS"] }
and it now shows up in the UI
but it looks like at the display in the widget it is ignored as I still get generic timestamp when I use =loop.item.state
.displayState does not exist when you try to use it within the the oh-repeater component.
from the whole this tread I understood you can only use when accessing single item not in the loop.
loop.<var> in expressions within a oh-repeater context contains an array of EnrichedItemDTO (openHAB Core 3.2.0-SNAPSHOT API) which has a state but it isn’t updated dynamically (it’s what the REST API returned at the time of retrieval), so you shouldn’t use it; items on the other hand is a map of Strings - the item name - to StateDTO which is updated.
So your loop.i.state should rather be items[loop.i.name].state (or items[loop.i.name].displayState).