Skip to content

Commit

Permalink
Added emphasis that not all Items and Groups belong in the model and …
Browse files Browse the repository at this point in the history
…how to manage Items outside the model.

Signed-off-by: Rich Koshak <rlkoshak@gmail.com>
  • Loading branch information
rkoshak committed Mar 22, 2021
1 parent 36cb424 commit a14c1a6
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 6 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/getting_started/images/create_link.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 98 additions & 6 deletions tutorials/getting_started/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Things represent devices and the sensors and actuators of those devices.
But one of the purposes of openHAB is to abstract away the specifics of each of the hundreds of supported technologies and APIs so that a light switch is a light switch whether it's controlling a Hue light bulb, a KNX wall switch, or a custom DIY relay that speaks MQTT.
To provide that abstraction openHAB uses Items.

There are a fixed set of Item types representing all the different ways that a sensor reading can be represented or a device can be interacted with.
There are a fixed set of Item types representing all the different ways that a sensor reading can be represented or a device can be controlled.
The configuration of your Items is where meaning is applied to your devices.
For example, instead of dealing with `zwave:1231242:node12:switch` we can deal with "Livingroom_Lamp".

Expand All @@ -21,10 +21,17 @@ Therefore we recommend creating the semantic model right from the start and stic
This will make your life easier in the long run.
Taking the time to understand and choose a logical structure for your home will save you from needing to re-do the work in the future.

This section gives a good example of one way to model your home with locations and equipment descriptions.
However, the model is not intended to represent all your Groups and Items.
The model only represents the physical layout of your home automation.
Consequently it has some contsraints discussed below.
But that does not mean that other ways of organizing and grouping Items are not supported.
For example, one can create a cross cutting functional based Group like `AllLights`.
Just don't put `AllLights` into your model.

This section gives an example of one way to model your home with locations and equipment descriptions.
The semantic model, when set up correctly, will allow openHAB to turn all lights off in the kitchen when asked, as the framework can understand the kitchen location and what items are lights in that location.
Once you created a model you additionally are able to use [Semantics Actions]({{base}}/configuration/actions.html#semantics) in Rules to e.g. determine the Location of an Item or the related Equipment.
This will help you to create, generalize and simplify Rules based on patterns and purpose.
Once created, a model allows one to use [Semantics Actions]({{base}}/configuration/actions.html#semantics) in Rules to e.g. determine the Location of an Item or the related Equipment.
This will help one create, generalize, and simplify Rules based on patterns and purpose.

{::options toc_levels="2..4"/}

Expand All @@ -42,6 +49,16 @@ The above drawing shows the relationship between the four main concepts in the m
- A Point is not a Group, but represents any other type of Item and is usually linked to a Channel.
- A Property is an additional tag on a Point Item that indicates what sort of point it is. For example, a thermometer might be a Point of type Measurement with a Property of type Temperature.

In addition to these relationships, there are restrictions.

- A Location can only be the direct member of zero or one Location Group.
- An Equipment can only be the direct member of zero or one Location, or the direct member of zero or one Equipment. Put another way, an Equipment can only be the direct member of one Group that has a semantic tag.
- A Point can only be the direct member of zero or one Location, or the direct member of zero of one Equipment. Put another way, a Point can only be the direct member of one Group that has a Location or Equipment tag.

Because the model represents the physical, it makes no sense to deviate from these restrictions.
An Equipment or Point cannot be in more than one location at the same time.
A Point cannot be a part of more than one Equipment at the same time.

Example of an advanced model:

![example model](images/example_model.png)
Expand All @@ -52,9 +69,12 @@ The House has a Ground Floor and the Ground Floor has rooms including a Living R
The Living Room has a Rollershutter equipment which in turn has a Control and Power point Item.
The locations and equipment are Group Items and Control and Power are other types of Items.

One key feature of this example model is that you are not required to *only* use the semantic model.
As discussed, one is not required to *only* use the semantic model.
It is possible and encouraged to create Groups and Items that are outside of the model where necessary.
In this example, the Rollershutter in the Living Room is a member of the AllRollershutters Group which could be used to determine if any are OPEN and send commands to all the rollershutters in the house at once.
In this example, the Rollershutter in the Living Room is a member of the `AllRollershutters` Group which could be used to determine if any are OPEN and send commands to all the rollershutters in the house at once.
But this functional cross cutting Group is not an Equipment nor is it a Location and it violates the restrictions of the model.
A typical installation may only have 60%-80% of all the Items in the model.
More about creating Items and Groups outside of the model is below.

You can use as few or as many layers of Locations as you wish to model your home.
For instance if you live in a flat (apartment) your root Locations might just be the rooms.
Expand Down Expand Up @@ -212,3 +232,75 @@ This table is based off the sources:

- <https://github.com/openhab/openhab-webui/blob/main/bundles/org.openhab.ui/web/src/components/cards/glance/location/status-badge.vue#L63>
- <https://github.com/openhab/openhab-webui/blob/main/bundles/org.openhab.ui/web/src/components/cards/glance/location/measurement-badge.vue#L48>

# Non-semantic Items and Groups

As discussed above, many Items and Groups are expected to be outside of the semantic model.
Perhaps they are only supporting Items only used for Rules.
Maybe they are the raw Items that feed a proxy Item or summarizing Group.
If they are a Group, perhaps they are functionally based instead of physically based, e.g. `AllLights`.

As discussed above, existing Items can be added to the model.
The reverse is also true, an Item can be removed from the model simply by removing their semantic tags by setting them to "None".
Note, when removing a Point/Property pair of tags, remove the Property first or else the Property tag will remain on the Item.

## Creating Non-semantic Items

Note that a Group is a special type of Item.
It can only be created from the Items Settings Page (when not created from the model), but the process to create a Group is the same as any other Item.

### From the Model Page

Selecting an existing Item and remove the sematic tags by clicking on "Edit" and setting the semantic tags to "None"..
This is particularly useful if one has created an Equipment from a Thing but only some of the Items created are to be a part of the model.

![Remove Item from Model](images/remove_from_model.png)

### From the Things's Page

Select a Things and click on the "Channels" tab.
Click on the Channel from which the Item is to be created.
Click on "Add Link to Item..." and select "Create new Item".
Fill out the information about the Item to be created, omitting the semantic tags.
Finally click on "Create Link".

![Create Item from Channel](images/create_link.png)

### From the Items Settings Page

Under "Administration" click on "Settings" and then on "Items".
All the Items defined in the system are listed.
The list of Items can be filtered by using the search box at the top of the list.
One can search by Item name, Item Label, or Item type (e.g. show all the Switch Items).

At the bottom of this page there is a blue "+" icon which when clicked allows the creation of an Item.
Clicking on this offers two options: "Add Items from textual definition" which allows one to import one or more Items based on the [textual configuration syntax]({{base}}/configuration/items.html), and "Add Item" which allows the creation of the UI by filling in a form.

![Create Item Form](images/create_item.png)

Again, leave out the semantic tags and the Item will not become a part of the model.

## Group Membership

Once a Group is created, other Items can be added as members of the Group.
Note that this process also works for semantically tagged Groups.
Navigate to or search for the Group on the Items Settings page and select the Group.
In the middle of the page will be a field labeled "Direct Group Members".
Click on "Change" and then "Members".

![Change Group Members](images/add_members_change.png)

This brings up a searchable list of your Items.
Find and add a check next to those that should be a member of this Group.
Remove the check for those that should not be a member of the Group.

![Select Group Members](images/select_members.png)

Click "close" when done and then click "Apply" to change the Group's members.

# Items Best Practices

- Only include Items in the model that make sense. Not all Items can nor should they be in the model.
- Use meaningful and unique labels for Items. If all the Temperature Items are just labeled "Temperature" there will be no way to tell which one is which when using the search on the Items settings page or in the UI.
- Use manually created Groups that are outside the model to create functional capabilities such as a way to send a command to all the lights in the house with one tap or see the maximum temperature in the house.
- Groups have the option to apply an aggregation function. One can semantically tag these Groups using a Point/Property tag and put the Group into an Equipment or Location. This can be useful in cases where a number of Items are logically controllable as one device, such as three smart bulbs in one lamp.

0 comments on commit a14c1a6

Please sign in to comment.