[OH3] Add metadata to Items via configuration files

The warning also appears at full steps, my configuration with warning is:

Number			OG_Li_Schlafen_Spots_BWM_Tnach			"Schlafen Spots Tnach [%.1f min]"	<time>			(gOG_Schlafen_Spots)			["Setpoint"]			{channel="simatic:generic_device:S7-1500:OgSchlaf:OG_Li_Schlafen_Spots_BWM_Tnach", stateDescription=""[pattern="%.1f min", min="0", max="30", step="1"]}

If I don’t define “min, max and step” I get no warning. The configuration then looks like this:

Number			OG_Li_Schlafen_Spots_BWM_Tnach			"Schlafen Spots Tnach [%.1f min]"	<time>			(gOG_Schlafen_Spots)			["Setpoint"]			{channel="simatic:generic_device:S7-1500:OgSchlaf:OG_Li_Schlafen_Spots_BWM_Tnach", stateDescription=""[pattern="%.1f min"]}

Hi Elk,
I think you are merging two different options. First one is the Formatter/Pattern and the second is the new card-option.

Number			OG_Li_Schlafen_Spots_BWM_Tnach			"Schlafen Spots Tnach [%.1f min]"	<time>			(gOG_Schlafen_Spots)			["Setpoint"]			{channel="simatic:generic_device:S7-1500:OgSchlaf:OG_Li_Schlafen_Spots_BWM_Tnach", stateDescription=""[pattern="%.1f min"], listWidget="oh-stepper-item" [step="0.5", min=6, max=24], widget="oh-stepper-card" [step="0.5", min=6, max=24]}

Btw: you can also use the pattern only in item-description (I think there was a change)

1 Like

Hi fibu-freak,
I did it just like the example above. Or did i miss something?
Thanks for your suggestion, I will test it an tell you the result. But it will take some time, because I have other issues with my installation at the moment, which I have to fix first.

Is there possibility to add “nested” metadata in text configs?
For example item

  "metadata": {
    "listWidget": {
      "value": "oh-label-item",
      "config": {
        "action": "popup",
        "actionModal": "widget:test_widget",
      }
    }
  },
  "type": "Switch",
  "name": "TestItem",
  "label": "Test item",
  "category": "switch",
  "tags": [
    "Equipment"
  ],
}

can be described as

Switch TestItem "Test item" <switch> ["Equipment"] {listWidget="oh-label-item" [action="popup", actionModal="widget:test_widget"]}

But I need to add props to custom widget

  "metadata": {
    "listWidget": {
      "value": "oh-label-item",
      "config": {
        "action": "popup",
        "actionModal": "widget:test_widget",
        "actionModalConfig": {
          "widgetProp": "value"
        }
      }
    }
  }
}

How to add this part “actionModalConfig”: { “widgetProp”: “value”}" in .items file?

Yeah, this question has popped up a few times now in this forum, but no-one seems to know the answer. @ysc apologies for the ping but are you aware of this question, and have any guidance?

I’m afraid it’s not possible. While metadata config values may be objects with nested properties, the grammar used to parse .items files doesn’t support it.

For those cases you would have to use the UI.
(the metadata is decoupled from the item itself so you can have the item in a file and the metadata for a certain namespace in the JSONDB as long as it’s not conflicting).
For this UI widgets-related metadata it’s not that far fetched to want to use the UI since you’ll get a live WYSIWYG preview.

2 Likes

In OH2 for my items with more complex but static metadata I used a Jython script, it’s a method @openhab-5iver showed me. The script doesn’t contain any rules, just the calls to set_metadata (from the Helper Libraries). So when the file gets loaded it applies the metadata immediately, that means it happens at startup, but also any time you edit the file it gets reloaded too.

@Kaspars_Rocans you should be able use this method to get your nested structure using nested Python dicts inside the dict passed to set_metadata as the configuration parameter. I have not looked at the data in the JSONDB or used it outside Python, but I’m pretty sure the configuration parameter gets passed directly into openHAB and a Python dict turns into a Java Map and that’s what the metadata configuration is on the Java side.

Thanks for explanation! Possibility to configure metadata separately is better than nothing but anyway it’s “configuring one thing in two places” and that is bad thing in general. :frowning: Same about other workarounds like set_metadata scripts.

So here comes next question - are there any plans to extend .items format/parser, may be introduce some new possibility to configure items in YAML or something like that?

Hi folks,
how i can find out the syntax to populate the “read only” property of an item within the *.items conf-file? Options are working fine…
Thx, Sascha

Hi @shaselb, Hi Search User,

Summary

stateDescription=""[pattern="%d%%",min="0",max="100", readOnly=true]

I was looking for the same question because it is case sensive and I did not know that.

So the following stateDescription has to be configured for your item:
stateDescription=""[pattern="%d%%",min="0",max="100", readOnly=true]

Kind Regards

hi all!
is it somehow possible to use a range value in options? for example:

<980=stormy
980-1000=rainy

and so forth?

thanks

Probably not. Are you aware of the Scale Transformation Service?

1 Like

thx, that did the trick :slight_smile:

Thanks!

UPDATED: However… it does not work on openHAB 3.0.2. The language parser chokes on this format of stateDescription metadata. Maybe it’s the empty double quote portion that is the culprit, as also mentioned in:

More precisely:

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)

(The example successfully assigns and properly configures the custom temperature_list widget for list items, but skips the offending stateDescription metadata definition block.)

It however works when adding a single space between the pair of double quotes.

Bug report:

1 Like

Impossibility to set the “actionAnalyzerItems” in items file.

Let me highlight another limitation of items files concerning setting metadata for widgets.

I noticed that the oh-label-list widget does not offer the possibility to “analyze” the time behavior of the item, differently than the oh-label-card. This behavior can be modified by editing with the UI the metadata “Default List Widget”, in particular by filling the fields action with the value “analyzer” and the field actionAnalyzerItems with the name of the item (Question: why doesn’t it default to the item to which this widget is applied?).
The YAML is as follows

value: ""
config:
  action: analyzer
  actionAnalyzerItems:
    - Pres_Anna

With this manual modification of the configuration the widget expose the analyze button and everything works as I wish.
As I am wishing to apply this modification to a number of items, I am trying to set a metadata in the **items file **, following the informations in the OP, as follows

Switch Pres_Silvana    "Pres Silvana [%s]"   <presence>  (gEquip_PresPD) ["Status","Presence"] {channel="xxx",
         listWidget="oh-label-list"[action="analyzer",actionAnalyzerItems="Pres_Silvana" ]
         }

but this item does not appear in the list of items under the equipment. If I remove the metadata it obviously reappears. The item is, in both cases visible from the settings pages (both in the model and the items pages) and it also shows that metadata are modified. Probably it is discarded, because the metadata are not correct. In fact, by looking closely to the code section in the UI, in order to inspect the YAML, it is as follows:

value: ""
config:
  action: analyzer
  actionAnalyzerItems: Pres_Silvana

The line actionAnalyzerItems does not look the same as the one set manually. The same YAML appears also if I import from the UI with the option “import from .items file”.

When importing from the UI the YAML can be modified by inserting the missing newline, dash and indentation in order to make it look like the previous one. With this modification the item re-appears in the list under the equipment in the UI.

Workaround for the previous post limitation.

By using a custom list widget, slight modification of @rlkoshak example custom list widget for presence, setting the actionAnalyzerItems field is not required any more.

uid: listWidget-presence
tags:
  - list
  - presence
props:
  parameters:
    - description: The label for the widget
      label: Person
      name: title
      required: false
      type: TEXT
    - context: item
      description: The presence switch Item
      label: Item
      name: item
      required: false
      type: TEXT
  parameterGroups: []
timestamp: Aug 17, 2021, 10:37:02 PM
component: oh-list-item
config:
  icon: f7:person_circle
  iconColor: '=(items[props.item].state == "ON") ? "green" : "red"'
  color: '=(items[props.item].state == "ON") ? "yellow" : "gray"'
  title: =props.title
  item: =props.item
  badgeColor: '=(items[props.item].state === "ON") ? "green" : "red"'
  badge: '=(items[props.item].state === "ON") ? "IN CASA" : "FUORI"'
  action: analyzer
  actionAnalyzerItems: =[props.item]

The last line is tricky. I was naively trying

  actionAnalyzerItems: 
  -  =props.item

but it didn’t work. I found in another rlkosk example that the right syntax was the one that i showed in the working yaml.

Once this widget is saved under the developer tools , a simple items definition such as

Switch Pres_Silvana    "Pres Silvana [%s]"   <presence>  (gEquip_PresPD) ["Status","Presence"] {channel="xxx",
         listWidget="widget:listWidget-presence"[title="Silvana" ]
         }

allows me to define the widget in the items file

Dunno why it does not work for you but for me it does (without defining a widget).
Probably item: is required.

- component: oh-label-card
     config:
     item: PVNetzeinspeisung
     title: bla
     action: analyzer
     actionAnalyzerItems:
       - PVNetzeinspeisung

Thank you for reading my post and giving me the opportunity to clarify it.
The point of my post is the fact that the YAML line concerning the actionAnalyzerItems field is not correctly generated when the metadata is specified in items writen in items file. The value (i.e. the item name) is on the same line and not preceded by a new line, dash and indentation.

When using a custom widget, the parameters that need to be specified in the widget metadata are correctly generated when imported by items file, because values are in the same line as the the key.

The other problem I found with the custom widget always concerned the actionAnalyzerItems but this time it was in the YAML itself.
Using the inline syntax

actionAnalyzerItems: =[props.item]

The time history of the item is shown, while when using

actionAnalyzerItems:
  - =[props.item]

the popup window showing the time history is opened but empty. This also applies if I remove the square bracket. On the other hand, if I replace =[props.item] with an actual item name (as in your case) the the analyzer window do show the time history of the item. Clearly this makes the custom widget useless because it cannot be customized.

I hope that this is clearer now. I am not a programmer nor a native english speaker, so probably my previous posts were not sufficiently clear. I modified them in order to try to state the problem more clearly

I think you have a misunderstanding here:
The point is that actionAnalyzerItems is a UI property but it is NOT item metadata so you cannot specify it via .items.

It’s confusing that specifiying fields that way seems to work generically (i.e. even for properties that do not exist), but note that the fact that it works for non-metadata, too, is strictly speaking a bug.
It’s however always assuming the standard property: value format. But actionAnalyzerItems is a list and therefore requires a different format.

Actually, based on the fact that this property is set in the UI when I edit the item metadata and it is stored in org.openhab.core.items.Metadata.json I concluded that it was an item metadata.

Anyway, thank you for your comment: may I conclude that the workaround that I have found may not work in newer versions of openHAB when bugs will be removed? Maybe @rlkoshak can give some comment on this point.

Thank you