HABot Walkthrough (2/n): Semantic Tagging & Item Resolving

You can name the Group anything you want. But you have to tag the Group with the proper tag from the ontology listed in the OP. You can further refine the Group using synonyms. Here is an example from my configuration.

// Ontology Groups
Group Basement          <cellar>                        ["Basement"]
Group MainFloor         <groundfloor>                   ["GroundFloor"] { synonyms="Main Floor" }
Group TopFloor          <firstfloor>                    ["FirstFloor"]  { synonyms="Top Floor" }
Group Den               <video>         (Basement)      ["LivingRoom"]  { synonyms="Den" }
Group FamilyRoom        <video>         (MainFloor)     ["LivingRoom"]  { synonyms="Family Room" }
Group FrontRoom         <video>         (MainFloor)     ["LivingRoom"]  { synonyms="Front Room, Living Room" }
Group MasterBedroom     <bedroom>       (TopFloor)      ["Bedroom"]     { synonyms="Master Bedroom,MBR" }
Group NatesBedroom      <bedroom>       (TopFloor)      ["Bedroom"]     { synonyms="Nate's Room" }
Group Garage            <garage>        (MainFloor)     ["Carport"]     { synonyms="Garage" }
Group FrontPorch        <door>          (MainFloor)     ["Terrace"]     { synonyms="Entryway" }

Then you add your Item to the appropriate Group for the location and tag the Item as appropriate. For example, here is a light in the Front Room of the house.

Switch aFrontLamp "Front Room Lamp"
  (gLights_ALL, gLights_ON_MORNING, gLights_OFF_DAY, gLights_ON_AFTERNOON, gLights_ON_EVENING, gLights_OFF_NIGHT, gLights_OFF_BED, gLights_ON_WEATHER, FrontRoom) [ "Lighting", "Switch", "Light" ]
  { channel="zwave:device:dongle:node2:switch_binary" }
2 Likes

Ok, that´s the clue.
So i have to set the Right Location, that Habot is able to locate my items, but i can choose my own synonyms and Group names.

thx
vaillan

is it possible that the habot listen only to the synoyms?
The Problem is, only a few locations can be defined.
So i have many items in one Location, but this Locations have different synonyms.

So if i want to shut off the light in the Living room, all Lights with the Location ["LivingRoom "] shut down, although all this Groups have different synonyms.

Group EG_Wohnzimmer				"Wohnzimmer"			<sofa>		(gEG)   ["LivingRoom"] {synonyms="Wohnzimmer"}
Group EG_Wintergarten			"Wintergarten EG"					(gEG)   ["LivingRoom"] {synonyms="Wintergarten"}

if i just want to shut down the light in the Group EG_wintergarten, the synonym wintergarten also work.

How is it possible, that the Group EG_Wintergarten only listen on synonym wintergarten, and not also on [“LivingRoom”]?

Best regards
vaillan

Hi guys,

it is working now.
i didn´t know that it is also possible to use the top category Location.
So i used [“Room”] for each Location that doesn´t fit, and set a synonym for each Location, as i did before.

thx
vaillan

1 Like

Hi,

is there a way defining synonyms using the Rest API? I’ve defined 99% of my items via PaperUI and don’t use .item files anymore…

thx,

Christoph

It doesn’t appear to even be possible to retrieve the synonyms using the REST API. I think it’s metadata. If it is, you should be able to use the Add Metadata endpoint to add it to an Item. It’s worth a try.

1 Like

Any idea how it should look like, when i set the metadata and retrieve the item state via REST API?

Found it by try and error: It looks like reading metadata is not possible via REST API (at least using OH 2.4), but you can set it by using the “[put] /items/{itemname}/metadata/{namespace}” method and namespace “synonym” and a JSON like this:

{
“value”: “Synonym1, Synonym2”
}

This worked with a group which had the tag “Attic” and is now available with “Synonym1” and “Synonym2” as well… thanks for pointing me in the right direction!

kind regards,

Christoph

1 Like

If you have the REST API docs add-on installed, you can use it to discover the API and play around with it.

To add metadata:
http://ip:8080/doc/index.html#!/items/addMetadata

To get synonyms along with items:
http://ip:8080/doc/index.html#!/items/getItems
(put synonyms in the metadata parameter i.e. GET /rest/items?metadata=synonyms).
You can retrieve multiple namespaces by comma-separating them in the parameter e.g. GET /rest/items?metadata=synonyms,semantics.

But there doesn’t appear to be a REST endpoint to show all the metadata on an item and in my experiments if I don’t narrow the search using known metadata I do not get any metadata back from get Item.

I’ve started using metadata more since starting to transition my rules to Jython. It’s handy to be able to set and check metadata for things like flags or settings that otherwise would require a separate item or global variable.

You’re right - you have to know the namespace(s) you want, I’m not 100% sure but I’d guess it’s by design rather than an oversight, note that metadata is more than additional user-defined storage, it can be populated by different “providers”: for instance the semantics provider derives read-only metadata in the “semantics” namespace based on tags, group memberships and so on. So retrieving all metadata at once could potentially have a performance impact.

An interesting side-effect is you can have both textually-defined (in .items files) and “managed” (defined with REST or an UI and stored in JSONDB) metadata for the same item, in separate namespaces.

Moreover, the metadata consists for each namespace in a “main” (string) value and a dictionary of additional “config” (key-value pairs). You can therefore maybe take advantage of the dictionary to store several flags and statuses under a common known namespace.

Yep, I do that already. I put a nice human readable name for some item in the .items file metadata. And in a rule I apply a flag when something happens (e.g I’ve already alerted that a device has turned off). It works quite nicely.

When I developed my OH interface, I found the metadata API rather limiting to be honest. It accepts a regex as I found out later while refactoring the REST part, but the escaping is broken. So the “.*” (regular expression for “everything”) doesn’t work, to get all namespaces of an item.

Cheers, David

Maybe someone can help me out here… I have three z-wave motion sensors that are all set like this:

Switch      ZW_Alcove_Motion            "Alcove Motion [MAP(motion.map):%s]"                    <motion>            (gMotion, gPres_GroundFloor)    [ "MotionDetector", "GroundFloor" ] { channel="zwave:device:XXXXXXXX:node20:sensor_binary" }
Switch      ZW_GuestRoom_Motion         "Guest Room Motion [MAP(motion.map):%s]"                <motion>            (gMotion, gPres_1stFloor)       [ "MotionDetector", "Firstloor" ]   { channel="zwave:device:XXXXXXXX:node25:sensor_binary" }
Switch      ZW_Closet_Motion            "Master Closet Motion [MAP(motion.map):%s]"             <motion>            (gMotion, gPres_1stFloor)       [ "MotionDetector", "Firstloor" ]   { channel="zwave:device:XXXXXXXX:node26:sensor_binary" }

Which shows up fine in Habot, both in attributes as well as asking for their status. However, I have multiple cameras that detect motion, which I wrote a script that when motion is detected, it will turn on a proxy item in OpenHAB, such as:

Switch		Proxy_Porch_Motion          "Porch Motion [MAP(motion.map):%s]"					    <motion>		    (gMotion, gPres_Perimeter)               [ "MotionDetector", "Outdoor" ]     { expire="42s,state=OFF" }
Switch		Proxy_Garage_Motion 	    "Garage Motion [MAP(motion.map):%s]"                    <motion>			(gMotion, gPres_Garage)                  [ "MotionDetector", "Garage" ]      { expire="42s,state=OFF" }

But the attribute “MotionDetector” for any of my proxy motion items does not show up in Habot. Also, if I ask Habot the status of all motion detectors, it only shows the three z-wave sensors and none of the proxy ones.

Any help would be appreciated.

~John

Could you go the settings page and open the “View attributes” dialog, then search your proxy items, what do you see?

@ysc
When I click on the “view attributes” it shows the location tags, like basement, cellar, downstairs, ground floor, etc. It does not have the tiles for “Motion Detector” under the attributes.

~John

Right I see. The thing is, you can only have one class on an item at a time, so it’s either MotionDetector or a location (the only case where you can have 2 semantic tags is a Point along with a Property, like ["Measurement", "Temperature"].

What you’re supposed to do is define groups to represent the locations (such as gGF, gFF, gOutdoor, gGarage and so on), tag them with the location attribute, and add the equipments to these groups while only keeping the MotionDetector tag on the switches.

Group gGF "Ground Floor" ["GroundFloor"]
Switch ZW_Alcove_Motion (gGF) ["MotionDetector"]

The “real” proper way of defining your model (this is described in the OP), albeit a bit overkill maybe, is to have a Location > Equipment > Point+Property hierarchy, like this:

Group gGF "Ground Floor" ["GroundFloor"]
Group gGF_MotionDetector (GF) ["MotionDetector"]
Switch gGF_MotionDetector_Motion (gGF_MotionDetector) ["Status", "Presence"]

@ysc,

That seemed to work. I do have the proxy items in groups with a location tag, but they were not responding, which is why I added a location tag to the item itself. the “motion detector” attribute showed up once I got rid of the location. Thanks for the help!

~John

1 Like

hi, can u help me on this… im trying simply to switch on/off living room light using voice… but whatever i say it will turn on or off livingroom light, for example, if i say:

turn on living room light or
turn on bedroom light or
turn off test light

all these commands work for the same item, i want it only to work when i say “turn on/off
livingroom light” and so on for another item like bedroom light

Group gGF "Ground Floor" ["GroundFloor"]
Group gGF_Light (GF) ["LivingroomLight"]
Switch   LivingRoom_light1        "Livingroom light"  (gGF_Light) ["Switch", "Light"]

The best solution in your case would be to define a Group for your living room:

Group gGF_Living "Living Room" ["LivingRoom"]

And then make sure your lights are members of that group.
Then use a sentence like “turn on the lights in the living room” instead of “turn on the living room lights”, as it is more in line with the training.