Skip to content

Commit

Permalink
Added documantation about Semantics features in Rules (openhab#1500)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Weitkamp <[email protected]>
  • Loading branch information
cweitkamp authored Feb 28, 2021
1 parent 364b2dd commit de47ad7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions addons/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ val headers = newHashMap("Cache-control" -> "no-cache")
val output = sendHttpGetRequest("https://example.com/?id=1", headers, 1000)
```

### Semantics

One can use Semantics features in Rules.
E.g. determine the location of an Item.
Regardless if it is a Point, an Equipment or a Location itself.
Therefore openHAB provides a bunch methods to be used in Rules.

#### Rules DSL

- `boolean isLocation(Item)` - checks if the given Item is is a Location
- `boolean isEquipment(Item)` - checks if the given Item is is an Equipment
- `boolean isPoint(Item)` - checks if the given Item is is a Point
- `Item getLocation(Item)` - gets the Location Item of the Item, returns the related Location Item of the Item or `null`
- `Class<? extends Location> getLocationType(Item)` - gets the Location type of the Item, returns the related Location type of the Item or `null`
- `Item getEquipment(Item)` - gets the Equipment Item an Item belongs to, returns the related Equipment Item of the Item or `null`
- `Class<? extends Equipment> getEquipmentType(Item)` - gets the Equipment type an Item belongs to, returns the related Equipment type of the Item or `null`
- `Class<? extends Point> getPointType(Item)` - gets the Point type of an Item, returns the related Point type of the Item or `null`
- `Class<? extends Property> getPropertyType(Item)` - gets the Property type an Item relates to, returns the related Property type of the Item or `null`
- `Class<? extends Tag> getSemanticType(Item)` - gets the semantic type of an Item (i.e. a sub-type of Location, Equipment or Point)

#### Scripted Automation

One must import the Semantics Action and then call the above functions using `Semantics.<function>`, for example `Semantics.getLocation(Item)`.

### Timers

`createTimer(AbstractInstant instant, Procedure procedure)`: schedules a block of code to execute at a future time
Expand Down
4 changes: 3 additions & 1 deletion tutorials/getting_started/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ There are a fixed set of Item types representing all the different ways that a s
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".

Items are the main entities that the rest of openHAB works with including Pages, sitemaps, rules, and persistence.
Items are the main entities that the rest of openHAB works with including Pages, Sitemaps, Rules, and persistence.

There are many ways to organize your items, one of which is to make use of the semantic model (descriptions for location, type of equipment and more).
openHAB 3 makes extensive use of the semantic model to automatically create Pages (see next section) and to provide natural language interaction.
Expand All @@ -23,6 +23,8 @@ Taking the time to understand and choose a logical structure for your home will

This section gives a good 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.

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

Expand Down

0 comments on commit de47ad7

Please sign in to comment.