OH3: adding metadata to thing-created items

My usecase is as follows:

  1. I switched to openHAB3 and dropped my file-based configuration from OH2
  2. I used the GUI to add my bindings, configured my things
  3. I used “add Equipment to Model” and now have a bunch of “raw” items
  4. Now I want to add metadata to my items like:
    3.1. force auto-updates
    3.2. alexa-API attributes
    3.3. expires

what I am missing now is a bulk update mechanism, so that I can find “all dimmer items” and apply the alexa attributes or use “auto-update” on all my KNX-items, etc.

What would be nice is to have an item export and I can use an editor to filter my items, add my metadata and re-import the items - to have a mass editor in the GUI would be nice, but from what I see with that different item-definitions I’m afraid, that’s a very big issue to get a mass editor in the GUI to work.

I tried to “openhab-cli backup”, but it won’t export item definitions, which I could edit in use the developer tools “import/update items from text” functionality… or did I miss something?
I did not test to edit the JSONDB and restore it… I don’t know how to mass edit the JSONDB-itemfile

1 Like

You did have the opportunity to set a lot of the parameters on those items though: name, category, label, semantic tags, etc.

Anyway, to answer your question, if you stop openHAB, it’s possible to edit the JSONDB fingers by hand. There is a separate file for metadata that you’ll need to create new entries in.

However, I would suggest adding the metadata you want to an Item, query for that metadata in the REST API Explorer, copy that JSON, page it into the set metadata firm, modify as needed to apply it to another Item and submit. I don’t know if you have to do that Item by Item or if you can batch a bunch up in a JSON array to apply it all in one submittal. That way you can’t mess up the syntax and you can do it with OH still running.

1 Like

That’s true - and I did set them. But you can’t (presently) add e.g. metadata to the items you create by adding equipment to the model.
btw: the REST API does not give me access to the metadata of items:

{"link":"http://192.168.78.225:8080/rest/items/KNXOGSchlafzimmer_LichtSchlafzimmer",
"state":"UNDEF",
"editable":true,
"type":"Dimmer",
"name":"KNXOGSchlafzimmer_LichtSchlafzimmer",
"label":"Licht Schlafzimmer","category":"",
"tags":["Point"],
"groupNames":["KNXOGSchlafzimmer"]}

whereas the item has metadata (can only screenshot it):

That’s exactly what I thought. I have at least 146 devices exposed via openHAB to alexa (lights, states, temperatures, …) and it’s a pain in the ass to add all those metadate manually in the UI without a bulk edit mode or something. And I purposedly switched from text-based config to UI-config, because I don’t want to mess with typos and stuffsigh

metadata only exists for Items. The metadata rest endpoints is how the Uis set and get Item metadata. That result is from querying for the Item.

But it’s a different endpoint from the Item’s endpoint. Scoll down the list a bit further to the metadata section. As with Links, metadata is stored separately from the Item’s.

1 Like

Now I’m at a computer so here are some screen shots because things are not where I thought they were.

Once you add metadata to an Item, go to the “Get a single Item” REST API endpoint and put in the Item and the namespace for the metadata you want to have it return. The API doesn’t support just showing you all the metadata. :frowning:

Which returned:

{
  "members": [
    {
      "link": "http://huginn:8080/rest/items/RichPresence",
      "state": "ON",
      "stateDescription": {
        "pattern": " ",
        "readOnly": true,
        "options": []
      },
      "type": "Switch",
      "name": "vRichPhone",
      "label": "Rich's Phone Network",
      "category": "presence",
      "tags": [
        ""
      ],
      "groupNames": [
        "RichPresence"
      ]
    }
  ],
  "groupType": "Switch",
  "function": {
    "name": "EQUALITY"
  },
  "link": "http://huginn:8080/rest/items/RichPresence",
  "state": "ON",
  "stateDescription": {
    "pattern": " ",
    "readOnly": true,
    "options": []
  },
  "metadata": {
    "debounce": {
      "value": "vRichPresence",
      "config": {
        "state": "OFF",
        "timeout": "30s",
        "command": "True"
      }
    }
  },
  "editable": true,
  "type": "Group",
  "name": "RichPresence",
  "label": "Raw Rich's Presence",
  "category": "",
  "tags": [
    ""
  ],
  "groupNames": [
    "Debounce"
  ]
}

Notice how the response included a metadata section showing the “debounce” metadata on that Item. Copy the metadata JSON.

Now scroll down a bit to the “add metadata to an Item” and paste in that metadata you queried for before. Set the Item and make any edits required and execute. You’ve just added metadata to that Item. If the metadata is the same you just need to update the Item name and click execute. If the metadata is slightly different, you just need to change the Item name and make your minor edits.

You should be able to add the same or similar Item metadata to Items super fast this way. If you need help remembering the Item’s names, bring up the developer sidebar (alt-shitf-d) and search for the Items there to remind yourself.

Of course, the metadata JSON is simple enough, you could probably skip the first step and just type in the metadata yourself.

3 Likes

Thanks Rich, for that sweet explanation!