This bundle provides the same JRuby scripting automation add-on for OpenHAB 3.4.x as in the official add-on. The differences are:
- Compiled with JRuby 9.4.x., which offers Ruby 3.1 compatibility.
- The default
gems
setting isopenhab-scripting=~>5.0
- The default
require
setting isopenhab/dsl
This makes the addon ready to use with the latest official helper library pre-configured. Just install the addon and start writing rules!
Examples
Quick examples of scripting with JRuby, with the help of the pre-configured helper library:
rule 'Turn on light when sensor changed to open' do
changed Door_Sensor, to: OPEN
run { Cupboard_Light.on for: 3.minutes } # Automatically turn it off after 3 minutes
end
Trigger on changes to member of group:
# Assumption: Motion sensor items are named using the pattern RoomName_Motion
# and Light switch items are named with the pattern RoomName_Light
rule 'Generic motion rule' do
changed Motion_Sensors.members, to: ON
run do |event|
light = items[event.item.name.sub('_Motion', '_Light')] # Lookup item name from a string
light&.on
end
end
rule 'Turn off watering system after 5 minutes' do
changed Watering_System, to: ON, for: 5.minutes
run do
Watering_System.off
end
end
# Turn on My_Light item 3 minutes from now
after 3.minutes do
My_Light.on
end
max = Solar_Power.maximum_since(24.hours.ago)
if max.timestamp < LocalTime::NOON
logger.info 'Max solar power #{max} happened before noon'
end
For more examples, see openhab-scripting
Changelog
Version 0.0.4 - 2023-03-09
- Upgraded to jruby 9.4.2.0
- Use the official openhab-scripting gem version 5.0
Version 0.0.3 - 2022-12-05 (3.4.0.202212051035)
-
[jrubyscripting] Implement dependency tracking
Note the new default for script location as described above.
Version 0.0.2 - 2022-11-29 (3.4.0.202211290009)
- [jrubyscripting] Allow multiple version specifiers for gems
- [jrubyscripting] log Ruby stacktrace on exception from JRuby
- Fixed the openhab-jrubyscripting gem version requirement so it loads the latest 5.x version including the rc versions.
Version 0.0.1
- initial release