openhab-core icon indicating copy to clipboard operation
openhab-core copied to clipboard

Get physical location of an Item?

Open mueller-ma opened this issue 3 years ago • 7 comments

I want to improve the "device control" menu on Android 11. Google uses the location of an item as subtitle, but I don't know how to get the location of an item through the rest api.

There's the property "Location" that can be set for Things, but not for Items. Maybe add a location property to Items and inherit the value from the linked Thing? Then this property has to be added to /rest/items/foo.

Or should I utilize some other metadata here?

Related issue at openhab-android: https://github.com/openhab/openhab-android/issues/2904

mueller-ma avatar May 23 '22 11:05 mueller-ma

The location of an item is defined by his belonging to a group tagged as a location (search in community forum). The location of the thing is just an informational data, not much used.

clinique avatar May 23 '22 12:05 clinique

Just to elaborate a little bit.

An Item only has a location if it's configured into the semantic model. As @clinique indicates, placing an Item into a location is achieved by making the Item a descendent of a Group tagged with a location semantic tag.

I say descendent because it might not be the immediate parent Group of the Item because the Item might be a part of an equipment which is also represented by a Group membership. So you might have to navigate up the Group hierarchy several levels before you encounter the location.

There are some actions that can be used in rules that will give the location parent Group for any given Item but that doesn't appear to be exposed via the REST API. You'd have to navigate the Group hierarchy looking for the first one that has a location tag.

Even though this is ugly, it would be best from the end user's perspective to use the semantic model location instead of introducing a separate location metadata or property on an Item. That would become confusing pretty quickly.

rkoshak avatar May 23 '22 14:05 rkoshak

Thanks, @rkoshak. @mueller-ma, I think this issue can be closed, correct?

J-N-K avatar May 23 '22 16:05 J-N-K

Thanks for the answers.

There are some actions that can be used in rules that will give the location parent Group for any given Item

Can you send me a link to one of these actions?

mueller-ma avatar May 24 '22 09:05 mueller-ma

Here's the docs: https://next.openhab.org/docs/configuration/actions.html#semantics

Here's the JavaDocs: https://www.openhab.org/javadoc/latest/org/openhab/core/model/script/actions/semantics

And here's the code: https://github.com/openhab/openhab-core/blob/main/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Semantics.java

rkoshak avatar May 24 '22 13:05 rkoshak

When the code is already on the server, can the location be added to the rest API?

mueller-ma avatar May 24 '22 20:05 mueller-ma

I don't know but I think there has been an issue open for some time to expose script actions through the REST API. I don't know the full status of that though beyond that I'm pretty sure it hasn't been done yet. A couple of the relevant issues include #926 and #1745. But those are kind of specific to binding actions and I'm not sure if they reference core actions like these. But I'd see no reason for both types of actions not to be included in what ever happens to these issues.

rkoshak avatar May 24 '22 21:05 rkoshak