Skip to content

Commit 84eb97a

Browse files
authored
[jrubyscripting] Update README (openhab#16440)
Signed-off-by: Jimmy Tanagra <[email protected]>
1 parent a332adb commit 84eb97a

File tree

1 file changed

+31
-8
lines changed
  • bundles/org.openhab.automation.jrubyscripting

1 file changed

+31
-8
lines changed

bundles/org.openhab.automation.jrubyscripting/README.md

+31-8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ If you're new to Ruby, you may want to check out [Ruby Basics](https://openhab.g
6060
- [Terse Rules](#terse-rules)
6161
- [Early Exit From a Rule](#early-exit-from-a-rule)
6262
- [Dynamic Generation of Rules](#dynamic-generation-of-rules)
63+
- [Scenes and Scripts](#scenes-and-scripts)
6364
- [Hooks](#hooks)
6465
- [Calling Java From JRuby](#calling-java-from-jruby)
6566
- [Full Documentation](#full-documentation)
@@ -99,7 +100,7 @@ Additional [example rules are available](https://openhab.github.io/openhab-jruby
99100

100101
1. Go to `Settings -> Add-ons -> Automation` and install the jrubyscripting automation addon following the [openHAB instructions](https://www.openhab.org/docs/configuration/addons.html).
101102
In openHAB 4.0+ the defaults are set so the next step can be skipped.
102-
1. Go to `Settings -> Other Services -> JRuby Scripting`:
103+
1. Go to `Settings -> Add-on Settings -> JRuby Scripting`:
103104
- **Ruby Gems**: `openhab-scripting=~>5.0`
104105
- **Require Scripts**: `openhab/dsl` (not required, but recommended)
105106

@@ -118,7 +119,7 @@ Additional [example rules are available](https://openhab.github.io/openhab-jruby
118119

119120
## Configuration
120121

121-
After installing this add-on, you will find configuration options in the openHAB portal under _Settings -> Other Services -> JRuby Scripting_.
122+
After installing this add-on, you will find configuration options in the openHAB portal under _Settings -> Add-on Settings -> JRuby Scripting_.
122123
Alternatively, JRuby configuration parameters may be set by creating a `jruby.cfg` file in `conf/services/`.
123124

124125
By default this add-on includes the [openhab-scripting](https://github.com/openhab/openhab-jruby) Ruby gem and automatically `require`s it.
@@ -262,12 +263,13 @@ When you use "Item event" as trigger (i.e. "[item] received a command", "[item]
262263
This tables gives an overview of the `event` object for most common trigger types.
263264
For full details, explore [OpenHAB::Core::Events](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Events.html).
264265
265-
| Property Name | Type | Trigger Types | Description | Rules DSL Equivalent |
266-
| ------------- | -------------------------------------------------------------------------------------------- | -------------------------------------- | ---------------------------------------------------- | ---------------------- |
267-
| `state` | [State](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Types/State.html) or `nil` | `[item] changed`, `[item] was updated` | State that triggered event | `triggeringItem.state` |
268-
| `was` | [State](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Types/State.html) or `nil` | `[item] changed` | Previous state of Item or Group that triggered event | `previousState` |
269-
| `command` | [Command](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Types/Command.html) | `[item] received a command` | Command that triggered event | `receivedCommand` |
270-
| `item` | [Item](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Items/Item.html) | all | Item that triggered event | `triggeringItem` |
266+
| Property Name | Type | Trigger Types | Description | Rules DSL Equivalent |
267+
| ------------- | -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | ---------------------- |
268+
| `state` | [State](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Types/State.html) or `nil` | `[item] changed`, `[item] was updated` | State that triggered event | `triggeringItem.state` |
269+
| `was` | [State](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Types/State.html) or `nil` | `[item] changed` | Previous state of Item or Group that triggered event | `previousState` |
270+
| `command` | [Command](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Types/Command.html) | `[item] received a command` | Command that triggered event | `receivedCommand` |
271+
| `item` | [Item](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Items/Item.html) | All item related triggers | Item that triggered event | `triggeringItem` |
272+
| `group` | [GroupItem](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Items/Item.html) | `Member of [group] changed`, `Member of [group] was updated`, `Member of [group] received a command` | Group whose member triggered the event | `triggeringGroup` |
271273
272274
```ruby
273275
logger.info(event.state == ON)
@@ -473,6 +475,9 @@ My_Item.ensure << ON
473475
logger.info("Turning off the light") if My_Item.ensure.off
474476
```
475477

478+
See [ensure_states](https://openhab.github.io/openhab-jruby/main/OpenHAB/DSL.html#ensure_states-class_method), [ensure_states!](https://openhab.github.io/openhab-jruby/main/OpenHAB/DSL.html#ensure_states!-class_method),
479+
[ensure](https://openhab.github.io/openhab-jruby/main/OpenHAB/DSL/Items/Ensure/Ensurable.html#ensure-instance_method).
480+
476481
##### Timed Commands
477482

478483
A [Timed Command](https://openhab.github.io/openhab-jruby/main/OpenHAB/DSL/Items/TimedCommand.html) is similar to the openHAB Item's [expire parameter](https://www.openhab.org/docs/configuration/items.html#parameter-expire) but it offers more flexibility.
@@ -1740,6 +1745,24 @@ virtual_switches.each do |switch|
17401745
end
17411746
```
17421747
1748+
### Scenes and Scripts
1749+
1750+
A `scene` can be created using the [.scene](https://openhab.github.io/openhab-jruby/main/OpenHAB/DSL.html#scene-class_method) method.
1751+
1752+
```ruby
1753+
scene "Movie", id: "movie", description: "Set up the theatre for movie watching" do
1754+
Theatre_Window_Blinds.down
1755+
Theatre_Screen_Curtain.up
1756+
Theatre_Mood_Light.on
1757+
Theatre_Light.off
1758+
Theatre_Projector.on
1759+
Theatre_Receiver.on
1760+
end
1761+
```
1762+
1763+
To create a `script`, use the [.script](https://openhab.github.io/openhab-jruby/main/OpenHAB/DSL.html#script-class_method) method.
1764+
Note that scripts can be executed with additional contexts.
1765+
17431766
### Hooks
17441767
17451768
File based scripts can also register [hooks](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/ScriptHandling.html) that will be called when the script has completed loading (`script_loaded`) and when it gets unloaded (`script_unloaded`).

0 commit comments

Comments
 (0)