Access to "Google Assistant" Metadata from rules?

Is there a simple way to find all of the Items that have the Google Assistant Metadata set? in jython, I used get_value(Item, metadata) and it works for Custom Metadata but I doesnt seem to work for built-in metadata.

I am trying to find out which Items have “Google Assistant” set to confirm I have the right ones.

There is no reason why Google Assistant metadata would behave any differently from any other metadata. Are you using “ga” as the namespace?

It’s only “built-in” in that the UI is aware of it. But as far as the rest of OH is concerned, including rules, metadata is metadata whether it’s custom or a well-known namespace.

Using the Helper Library get_metadata in Python using list comprehension…

[i for i in items if get_metadata(i, "ga")]

should return a list of the names of the Items that have “ga” metadata.

Note that metadata has three parts: namespace=value[config1=1,config2=2]. Both the value and the config are optional. You are just trying to get the value but the metadata is not guaranteed to have a value perhaps.

1 Like

No, that was it. Thank you!

Where should I look for the internal names of the various metadata?

The docs usually tell you how to apply the metadata in a .items file.

To expose items (opens new window)to Google Assistent you will need to add metadata (opens new window)in the ga namespace.

Another place to look is the $OH_USERDATA/jsondb/org.openhab.core.items.Metadata.json file. That’s where the actual metadata is stored. You can search by Item name or by namespace to find the record.

1 Like

I’m looking in:
https://openhab-scripters.github.io/openhab-helper-libraries/Guides/But%20How%20Do%20I.html#items

But how do I get all the items in my entire Openhab instance?

https://www.openhab.org/javadoc/latest/org/openhab/core/items/itemregistry

But why do you want the actual Item Objects? getValue(), and all the rest of the metadata methods from the Helper Library require the Item names, not the actual Item Object. And you’ve got all the Item names already as the keys to the items dict. So

[i for i in items]

will give a list of all the Item names.

Note, the openhab-scripters repo is basically abandoned. Use GitHub - CrazyIvan359/openhab-helper-libraries: JSR223-Jython scripts and modules for use with ope for reference.

For the most part, the only time I find myself ever needing an actual Item’s Object is when I want to get the members of a Group or interact with Persistence. To sendCommand, postUpdate, extract Item metadata, get an Item’s state, etc only the name of the Item is needed and in most cases only the name of the Item is supported.

Got it thanks … I didn’t recognize “items” to be a variable … now I understand :man_facepalming:

Thank you … I’m trying to keep all this stuff straight :slight_smile:

To be specific, items is a dict that uses the Item names as the keys and the current Item’s state as the value. So to get the state of the Item Foo

items["Foo"]

It’s much nicer than pulling the Item from the registry

ir.getItem("Foo").state
1 Like