JRuby Scripting Official Helper Library

The JRuby helper library is a comprehensive Ruby gem designed to enhance automation in openHAB. It is installed by default by the official JRubyScripting add-on.

It offers a streamlined syntax for writing file-based and UI-based rules, making it easier and more intuitive than RulesDSL, while delivering the full features of the Ruby language.

Changelog

Installation Instructions
Documentation
CHANGELOG
GitHub Repository
Converting JS / RulesDSL / Jython rules to JRuby
Examples

Background & History

The JRuby Scripting Helper Library has now been included as an official part of the openHAB repository.

The official library starts at version 5.0 which includes major new features, fixes and some breaking changes from version 4.x. For more details, see the changelog for version 5.0.0.

The helper library will be installed automatically by the jrubyscripting addon in openHAB 4.0. For openHAB 3.4.x it can be installed by following the installation instructions. For convenience, an alternative version of the addon that performs the automatic installation is available from the marketplace.

Thanks to @broconne for creating this library and to @ccutrer for his major contributions.

Example file-based rules:

rule "Turn on light when sensor changed to open" do
  changed Door_Sensor # a Contact item
  run do |event|
    if event.open?
      Cupboard_Light.on for: 3.minutes # Automatically turn it off after 3 minutes
    else
      Cupboard_Light.off # This will automatically cancel the timer set above
    end
  end
end
rule "Door open reminder" do
  changed Doors.members, to: OPEN
  run do |event|
    # Create a timer using the triggering item as the timer id
    # If a timer with the given id already exists, it will be rescheduled
    after 5.minutes, id: event.item do |timer|
      next if timer.cancelled? || event.item.closed?

      Voice.say "The #{event.item} is open"

      timer.reschedule # Use the original duration by default
    end
  end
end

Example UI-based rules:

only_every(2.minutes) do # apply rate-limiting
  Audio.play_sound("doorbell.mp3")
  Notification.send("Someone pressed the doorbell")
end

Discussion thread: JRuby OpenHAB Rules System

5 Likes