Skip to main content Link Search Menu Expand Document (external link)

Shared Code

If you would like to easily share code among multiple rules files, you can place it in <OPENHAB_CONF>/automation/lib/ruby/personal. Assuming $RUBYLIB is set up correctly in jruby.conf (see Installation), you can then simply require the file from your rules files. Because the library files aren’t in the jsr223 directory, they won’t be automatically loaded individually by OpenHAB, only when you require them.

automation/jsr223/ruby/personal/myrule.rb

require "openhab"
require "my_lib"

logger.info(my_lib_version)

automation/lib/ruby/personal/my_lib.rb

def my_lib_version
  "1.0"
end