Added documantation about Semantics features in Rules (#1500)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
pull/1501/head
Christoph Weitkamp 2021-02-28 14:14:26 +01:00 committed by GitHub
parent 364b2ddfea
commit de47ad7adf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -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

View File

@ -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.
@ -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"/}