How to add item pattern format via "Add items via textual definition"? (migrate from .items files)

Dear all, during migrating from OH2.5 to OH3 I had some issues to maintain the patterns via “Add items via textual definition”. After longer searching and playing and shouting and playing again, I found a solution, I’d like to share. Maybe it is helpful for someone else.

In short

I’d like to import all items from *.items-files OH2.5 to OH3.0 via “Add items from textual definition”. But patterns have been ignored.

What I tried and how I solved it

Keeping the *.item files under OH3 works fine. Items are available in UI but I can’t change via UI, which is correct. Changes must be done via *.items files. So far so good.

So, I tried to import the items via the developer function “Add items from textual definition”. Copy the content from item-files is working and I’ve got the items migrated into the database.

The only thing I recognized, the value pattern/format was not taken over. In the item files it was defined as part of item description (e.g. DateTime vOS_Astro_Sunrise_Start "Begin Sunrise **[%1$tH:%1$tM]**". But the pattern-information at the end of the description was not converted into a pattern in the database. The item label was imported as “Begin Sunrise [%1$tH:%1$tM]”.

Therefore I tried to find a possibility to add the pattern information somewhere else. In UI you can add the metadata category “State Description” and there you can easily add the pattern like [%1$tH:%1$tM].

But how to give this informatin via “Add items from textual definition”? After playing around almost a day, I found the right syntax, I’d like to share. Maybe someone else had similar obsticles or a better solution.

The trick is, to add the pattern as metadata in the textual definition. E.g. , stateDescription=" "[ pattern="%1$tR" ] (Make sure you have a space or some other text in stateDescription=" " / Empty does not work)

Or here a full sample which works for OH3:
DateTime vOS_Astro_Sunrise_Start "Beginn Sonnenaufgang " <sunrise> (gOS_Astro) ["Point"] { channel="astro:sun:local:rise#start", stateDescription=" "[ pattern="%1$tR" ] }

Under /var/lib/openhab/jsondb/*metadata.json it looks like the following:

  "stateDescription:vOS_Astro_Sunrise_Start": {
    "class": "org.openhab.core.items.Metadata",
    "value": {
      "key": {
        "segments": [
        "uid": "stateDescription:vOS_Astro_Sunrise_Start"
      "value": "meta",
      "configuration": {
        "pattern": "%1$tR"

Developer tool “Add items from textual definition”

Item definition via UI and where to add metadata State Description for a different pattern/format.

Merry Christmas thefechner


So this means you need to manually modify all your items files with the new “[pattern” … ] before the import?

Thank you very much for sharing and to benefit from your experience / efforts.
This might be handy for me in the next days (I just started to migrate from 2.5-x to 3.0.

As usual, it depends :wink:

If you want to migrate your “classic” items-files into openHAB, then the answer would be yes. Please consider also to add [“Equipment”], ["Points] and so on. Potentially also synonyms (e.g. {synonyms=“Warm water”} for HabBot.

But there are other options. You might consider to create them via UI. Here you have all options immediately and there is no need to check how to convert all options into the item-file. Or you can create them via the API. But here I don’t have any experience.

Thanks, Steffen.

Because I have about 1200 items I would like to avoid creating them one by one using the new UI. :wink:

I think I will go then for keeping the items in files, because I still like the way to handle changes remotely using VSC and copy them over via WinSCP.