Skip to content

Commit

Permalink
Fix JRuby examples
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
  • Loading branch information
jimtng committed Aug 27, 2023
1 parent b4ae138 commit 3d2a96c
Showing 1 changed file with 30 additions and 46 deletions.
76 changes: 30 additions & 46 deletions concepts/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,12 @@ end
::: tab JRuby

```ruby
require 'openhab'

rule 'Raise the blinds & adjust temperature on sunrise' do
channel 'astro:sun:home:rise#event'
run {
gBlinds << up
gThermostat << increase
}
rule "Raise the blinds & adjust temperature on sunrise" do
channel "astro:sun:home:rise#event", triggered: "START"
run do
gBlinds.up
gThermostat.increase
end
end
```

Expand Down Expand Up @@ -433,14 +431,12 @@ end
::: tab JRuby

```ruby
require 'openhab'

rule 'Turn off the lights & adjust temperature on leaving' do
received_command Presence, command: off
run {
gLights << off
gThermostat << decrease
}
rule "Turn off the lights & adjust temperature on leaving" do
received_command Presence, command: OFF
run do
gLights.off
gThermostat.decrease
end
end
```

Expand Down Expand Up @@ -522,14 +518,10 @@ end
::: tab JRuby

```ruby
require 'openhab'

rule 'Play music on arrival, but only on afternoon' do
received_command Presence, command: on
run {
Soundbar >> on
}
only_if { TimeOfDay.now.between? ‘1pm’..’6pm’ }
rule "Play music on arrival, but only on afternoon" do
received_command Presence, command: ON
only_if { LocalTime.now.between? "1pm".."6pm" }
run { Soundbar.on }
end
```

Expand Down Expand Up @@ -629,17 +621,12 @@ end
::: tab JRuby

```ruby
require 'openhab'

rule 'Window open reminder' do
changed: gWindows, to: open
run {
after 1.hour do
if item.state.open?
notify("#{item.label} is open for an hour!")
end
end
}
rule "Window open reminder" do
changed gWindows.members, to: OPEN, for: 1.hour
run do |event|
# Item guaranteed to be OPEN here, no need to check
notify("#{event.item.label} is open for an hour!")
end
end
```

Expand Down Expand Up @@ -755,18 +742,15 @@ end
::: tab JRuby

```ruby
require 'openhab'

rule 'Movie Scene' do
rule "Movie Scene" do
received_command MovieScene, command: ON
run {
LivingRoom_Blinds >> '90%'
LivingRoom_MainLight >> off
LivingRoom_LEDStripe >> '50%'
Soundbar >> on
TV >> on
Soundbar >> ON
}
run do
LivingRoom_Blinds.command(90)
LivingRoom_MainLight.off
LivingRoom_LEDStripe.command(50)
Soundbar.on
TV.on
end
end
```

Expand Down

0 comments on commit 3d2a96c

Please sign in to comment.