Help On Metadata

Tags: #<Tag:0x00007f61700d9c78> #<Tag:0x00007f61700d9b88> #<Tag:0x00007f61700d9a98>

I am migrating my heavy lambda based DSL light control rules.
Done 90% so far.
Currently, I have some generic definitions done by JSON data inside modules disjoined from Item definitions. I would like to move the data to items file as metadata of the particular items.

I was looking and trying for 2-3h with no luck. The documentation gave me some hints, though I was not able to read any valuable data back from metadata.

My JSON test data looks as follows:

LIGHT_SETTINGS= '''
{
    "testGU10L":
        {
            "ONOF" : 1,
            "MIDI" : 7,
            "ALLD" : 1,
            "ILUT" : 50,
            "ITLI" : "testGU10L",
            "ITIL" : "iluminationTest",
            "ITMO" : "motionTest"
        },
    "testGU10M":
        {
            "ONOF" : 0,
            "MIDI" : 7,
            "ITLI" : "testGU10M",
            "ITIL" : "iluminationTest",
            "ITMO" : "motionTest"
        }
}
'''

LIGHT_TRIGGERS='''
{
    "testGU10L":
        {
                "TOG" : [
                    ["CET", "deconz:switch:d6dfbf93:ccccccfffe51c077011000:buttoneven", "2002", ""],
                ],
               "DIM" : [
                    ["CET", "deconz:switch:d6dfbf93:ccccccfffe51c077011000:buttoneven", "2001", ""],
                ],
               "MOV" : [
                    ["ITC", "motionTest", "OFF", "ON"],
                ]
        },
    "testGU10M":
        {
                "TOG" : [
                    ["CET", "deconz:switch:d6dfbf93:ccccccfffe51c077011000:buttoneven", "1002", ""]
                ],
               "DIM" : [
                     ["CET", "deconz:switch:d6dfbf93:ccccccfffe51c077011000:buttoneven", "1001", ""]
                ],
               "MOV" : [
                    ["ITC", "motionTest", "OFF", "ON"]
                ]
        }
}
'''

this should be attached to following test items:

Dimmer testGU10L "Test Lamp L [%d %%]"  { channel="hue:0100:00212E00C488:6:brightness" } 
Dimmer testGU10M "Test Lamp M [%d %%]"  { channel="hue:0100:00212E00C488:2:brightness" } 

some basic questions:

  • Does it make sense to have such huge data as meta data attached to items?
  • Is it feasible?
  • and at last, is it readable when put in the items file?

I started with a simple meaningless example:

Dimmer testGU10L "Test Lamp L [%d %%]"  { channel="hue:0100:00212E00C488:6:brightness" , alexa="Fan" [ type="oscillating", speedSteps=3 ] } 

tried:

core.metadata.get_all_namespaces("testGU10L")

which delivers 2 namespaces:

[u'channel', u'alexa']

what now?

core.metadata.get_value("testGU10L", "alexa")

delivers:

Fan

and then

core.metadata.get_key_value("testGU10L", "alexa", "Fan")

gives me:

{}

tried all possible combination getting always {}

I don’t see a problem with it. Though I don’t think you can keep it formatted as JSON like it is in your example. You will need to follow the format for metadata.

I use Item metadata for a number of situations and even wrote a design pattern about it. My [Scripted Automation] Multi-day Time of Day Library example uses complex metadata, though not as complex as you will need.

Not so much I find. Simple metadata is pretty readable but something as complex as the above will become a little hard to follow I think. But YMMV.

The following is explained at https://openhab-scripters.github.io/openhab-helper-libraries/Guides/Metadata.html#metadata

But to quote the DP above, Metadata has three main parts.

  • Namespace: the root category, can contain multiple Values
  • Value: Single value for the namespace
  • Key/value pairs: an array of keys and their values

In your example above, “alexa” is the namespace, “Fan” is a value and [ type="oscellating", speedSteps=3 ] is the Key/value array.

If you want to access the type value you need to call

get_key_value("testGU10L", "alexa", "type")

You’ve already shown how to get the value “Fan”.

worked, ok :+1:

but when I change the item to:

Dimmer testGU10L "Test Lamp L [%d %%]"  { channel="hue:0100:00212E00C488:6:brightness" , alexa="Fan" [ type={Subkey={Subsubkey="nested value"}}, speedSteps=3 ] } 

and run again I would expect some result, but I am gettin {}

Pay attention to what I said above.

I don’t think you can keep it formatted as JSON like it is in your example.

Unfortunately, there are limitations to the metadata used in .items files. I submitted an feature request to change this…

You will need to add/change the metadata through your scripts, as details in the documentation and this example, which uses the detailed metadata structure you are looking to implement.

this info is misleading:
https://openhab-scripters.github.io/openhab-helper-libraries/Guides/Metadata.html#metadata

I wrote it… how so?

I’ll give it up, it’s my limited intelligence :slight_smile:

or too much wine, I’ll try it again tomorrow.
Thanks for your support

:beers:

In a script, try something like this, replacing the Item name with one of yours…

from core.metadata import set_metadata

set_metadata("DS_Kitchen_Sink_Switch", "area_triggers_and_actions", 
    {
        "modes": {
            "Morning": {
                "low_lux_trigger":55, 
                "brightness":98
            }, 
            "Day": {
                "low_lux_trigger":55, 
                "brightness":98
            }, 
            "Evening": {
                "low_lux_trigger":90, 
                "brightness":98
            }, 
            "Night": {
                "low_lux_trigger":90, 
                "brightness":98
            }, 
            "Late": {
                "low_lux_trigger":90, 
                "brightness":0
            }
        }
    }, 
    overwrite=True
)

sober now :slight_smile:

This does not help to support my intention of a marriage of item definition and metadata a happy life in the *.items house and living there happily ever after.

The JSON file is good enough for now.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.