Skip to content

Commit

Permalink
[Rules] Add chapters on thing status in actions and rules (#463)
Browse files Browse the repository at this point in the history
The change of the code is at eclipse-archived/smarthome#3001
After this commit, the end user can find the documentation about how to react
to thing status change in the rule.

Bug: #517

Incorporate more pull request feedback.

Signed-off-by: Maoliang Huang <hellomao@outlook.com>
  • Loading branch information
kceiw authored and ThomDietrich committed Sep 26, 2017
1 parent ff4d9c7 commit a080441
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
23 changes: 23 additions & 0 deletions addons/actions.md
Expand Up @@ -95,6 +95,29 @@ The Timer object supports the following methods:
* `hasTerminated`: returns true if the code has run and completed
* `reschedule(AbstractInstant instant)`: reschedules the timer to execute at the new time. If the Timer has terminated this method does nothing.

### Thing Status Action

`getThingStatusInfo(String thingUID)`: Gets status information of the given thing identified by `thingUID`.

The result is of type `ThingStatusInfo`.
It contains [Thing Status]({{base}}/concepts/things.html), [Status Details]({{base}}/concepts/things.html) and [Status Description]({{base}}/concepts/things.html).
Refer to [Thing Status API]({{base}}/concepts/things.html) for how to get those information.
If you just want to know the status, you can use `thingStatusInfo.getStatus().toString()` and the result will be one of the values in [Thing Status]({{base}}/concepts/things.html).

> If the thing is removed or it's not added yet, it'll return null.
For example:

```java
var thingStatusInfo = getThingStatusInfo("zwave:device:c5155aa4:node2")

if ((thingStatusInfo != null) && (thingStatusInfo.getStatus().toString() == "ONLINE")) {
logInfo("ThingStatus", "The thing is online.")
} else {
logError("ThingStatus", "The thing is offline or doesn't exist.")
}
```

## Installable Actions

<table id="actions-select" class="striped">
Expand Down
24 changes: 24 additions & 0 deletions configuration/rules-dsl.md
Expand Up @@ -114,6 +114,7 @@ There are different categories of rule triggers:
- **Item**(-Event)-based triggers: They react on events on the openHAB event bus, i.e. commands and status updates for items
- **Time**-based triggers: They react at special times, e.g. at midnight, every hour, etc.
- **System**-based triggers: They react on certain system statuses.
- **Thing**-based triggers: They react on thing status, i.e. change from ONLINE to OFFLINE.

Here are the details for each category:

Expand Down Expand Up @@ -182,6 +183,29 @@ then
end
```

{: #thing-based-triggers}
### Thing-based Triggers

You can listen for status updates or status changes (an update might leave the status unchanged).
You can decide whether you want to catch only a specific status or any.
Here is the syntax for all these cases (parts in square brackets are optional):

```java
Thing <thingUID> received update [<status>]
Thing <thingUID> changed [from <status>] [to <status>]
```

The status used in the trigger and the script is a string (no quotes).
You can find all the possible values for status from [Thing Status]({{base}}/concepts/things.html).
And refer to [Thing Status Action]({{base}}/addons/actions.html) to find how to get thing status in the script.

The `thingUID` is the identifier assigned to the Thing, manually in your configuration or automatically during auto discovery.
You can find it from PaperUI or from Karaf remote console.
For example, one z-wave device can be "zwave:device:c5155aa4:node14".

> Note: You need to use quotes around `thingUID` if it contains special characters such as ':'.
> The parser will not recognize the whole text correctly without quotes.
{: #scripts}
## Scripts

Expand Down

0 comments on commit a080441

Please sign in to comment.