You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: bundles/org.openhab.automation.jrubyscripting/README.md
+31-8
Original file line number
Diff line number
Diff line change
@@ -60,6 +60,7 @@ If you're new to Ruby, you may want to check out [Ruby Basics](https://openhab.g
60
60
-[Terse Rules](#terse-rules)
61
61
-[Early Exit From a Rule](#early-exit-from-a-rule)
62
62
-[Dynamic Generation of Rules](#dynamic-generation-of-rules)
63
+
-[Scenes and Scripts](#scenes-and-scripts)
63
64
-[Hooks](#hooks)
64
65
-[Calling Java From JRuby](#calling-java-from-jruby)
65
66
-[Full Documentation](#full-documentation)
@@ -99,7 +100,7 @@ Additional [example rules are available](https://openhab.github.io/openhab-jruby
99
100
100
101
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).
101
102
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`:
103
104
-**Ruby Gems**: `openhab-scripting=~>5.0`
104
105
-**Require Scripts**: `openhab/dsl` (not required, but recommended)
105
106
@@ -118,7 +119,7 @@ Additional [example rules are available](https://openhab.github.io/openhab-jruby
118
119
119
120
## Configuration
120
121
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_.
122
123
Alternatively, JRuby configuration parameters may be set by creating a `jruby.cfg` file in `conf/services/`.
123
124
124
125
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]
262
263
This tables gives an overview of the `event` object for most common trigger types.
263
264
For full details, explore [OpenHAB::Core::Events](https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Events.html).
264
265
265
-
| Property Name | Type | Trigger Types | Description | Rules DSL Equivalent |
| `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 |
| `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` |
271
273
272
274
```ruby
273
275
logger.info(event.state == ON)
@@ -473,6 +475,9 @@ My_Item.ensure << ON
473
475
logger.info("Turning off the light") ifMy_Item.ensure.off
474
476
```
475
477
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),
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|
1740
1745
end
1741
1746
```
1742
1747
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
+
1743
1766
### Hooks
1744
1767
1745
1768
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