Inherit state description from group?

  • Platform information:
    • openHAB version: 3.3.0

I have several Contact Items from the contact_state channels from avmfritz HAN_FUN_CONTACT. For one of these Items I set a State Description, so the values are translated in the sitemap. All Contact Items are in one group.

Is it somehow possible to set the state description for all of these contact items? Or do I have to copy+paste it to every item?

By design, Groups do not influence members - only the other way round.
Not least because Items may be members of several Groups, and Groups may be in a hierarchy.

'Fraid so.
You might write some script to identify and individually update members, but probably quicker to do it by hand.

Unfortunately you have to copy/paste. However, there are some more efficient ways to do that than clicking through the Items menu to each Item to make the change.

One option is:

  1. Make the changes desired to one of your Items
  2. Make a list of the remaining Item names you need to update you can copy/paste from
  3. Go to Developer Tools → API Explorer
  4. Go down to Items and open the “GET items/{itemname}” endpoint and click “Try it out”
  5. Put in the name of the Item you updated for the item name and “stateDescription” for the metadata.
  6. You’ll find some JSON for the metadata in the result. Copy that.
        "stateDescription": {
          "value": " ",
          "config": {
            "pattern": "%.0f %%"
          }
        }
  1. Now go to “PUT items/{itemname}/metadata/{namespace}” endpoint, open it up and click “Try it out”
  2. Put one of the Item names you haven’t updated into the item name field and “stateDescription” into the namespace field. Copy the JSON you got from step 6, excluding the "stateDescription : " part and paste that into the metadata field. I’ll look like:
{
          "value": " ",
          "config": {
            "pattern": "%.0f %%"
          }
}
  1. Hit submit and verify you didn’t get an error code.
  2. Replace the item name with another Item and hit submit and repeat until all the Items are updated.

It sounds like a long and involved process, but it’s really quick once you do it. If you know how to write the JSON in the first place (e.g. you’ll see it if you click on the “code” tab when editing the metadata) or you just know the syntax, you can skip steps 3-5.

The more Items you have to update, the more efficient this approach becomes.