try this in karaf console
log:set INFO jsr223.jruby
try this in karaf console
log:set INFO jsr223.jruby
That works! Thanks
4.25.0 is now released
Biggest changes since 4.13.01:
As always, for more details on the changes go here and latest docs are always here
A very special thanks to all of the contributors this past year! We just rounded the 1 year anniversary of this library.
4.30.0 is now released
Biggest changes since 4.25.0:
As always, for more details on the changes go here and latest docs are always here
4.37.1 is no released
There has been a lot of work since the last post - apologies for not updating more frequently here!
@JimT has been pushing regular updates to the library and driving many improvements.
Some changes since 4.30.0:
1.Triggers support ranges with string quantity. e.g. from: '0 W'..'10 W
2. received_command now supports ranges and procs
3. Cron style trigges now support month-day e.g. every '02-14', at: '2pm'
4. Lots of fixes and other enhancements
The biggest update is the work @JimT did on creating a very comprehensive âhow do I?â document.
As always, for more details on the changes go here and latest docs are always here
4.39.1 is now released. This version introduced support for openHABâs semantic model with complementary methods to augment the semantic model. Thanks to @ccutrer for this great new feature.
This is very useful in finding associated items in rules instead of relying on item naming pattern.
Links:
Example:
This script closes the curtains in the room when the TV is turned on
// to create triggers
Group gTVs
Group LivingRoom ["Livingroom"]
Group LivingRoom_TV (LivingRoom) ["Television"]
Switch LivingRoom_TV_Power (LivingRoom_TV, gTVs) ["Control", "Power"]
Group LivingRoom_Curtain1 (LivingRoom) ["Blinds"]
Rollershutter LivingRoom_Curtain1_Position (LivingRoom_Curtain1) ["Control", "Opening"]
Group LivingRoom_Curtain2 (LivingRoom) ["Blinds"]
Rollershutter LivingRoom_Curtain2_Position (LivingRoom_Curtain1) ["Control", "Opening"]
rule 'Automatically close all the curtains in the room when the TV turns on' do
changed gTVs.members, to: ON
triggered do |item|
# All the following can be done in a single chained method calls
curtains = item.location # This returns the semantic Location for the TV
.equipments(Semantics::Blinds) # This returns the matching Equipments within the location
.members # Return the members of the matching equipments
.points(Semantics::Opening) # Select all the Points that are of Opening class
# `ensure` here will only send the command when necessary
curtains.ensure.command DOWN
end
end
For more info, see: Semantics documentation
I am trying to get JRuby and this script library going on OpenHAB, but I am pulling a blank here.
Iâve installed the JRuby Scripting addon, and configured openhab-scripting=~>4.0
as Ruby Gem to install in the configuration. However when I try to write a script, and require 'openhab'
it errors out with:
[ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/ruby/personal/WasherStateMachine.rb': Error during evaluation of Ruby in org/jruby/RubyKernel.java at line 1017: (LoadError) no such file to load -- openhab
I suspect the ruby gem hasnât properly been installed, as a search through the filesystem doesnât reveal any either. But I canât find the right starting point to troubleshoot.
The system is running openhab-3.2.0-1 installed via apt, on a Armbian armv7l machine.
Marcus
try this to figure out if jruby is installed
go here if you donât know how to run he openHAB console
The error message indicates that jruby addon is installed. It is just not installing the openhab-scripting
gem for some reason.
@mvandamn could you please paste your configuration here?
Also try restarting openhab if you havenât already done that.
Hi @JimT and @Andrew_Rowe,
JRuby is indeed installed, just to confirm:
openhab> bundle:list -s | grep jruby
305 â Active â 80 â 3.2.0 â org.openhab.automation.jrubyscripting
OpenHAB (and the machine) have been restarted.
I have configured it via the web-interface, leaving everything to its defaults, except the gems.
I do see that the parameter is ending up in a slightly different pid then it it would if configured by files.
----------------------------------------------------------------
Pid: org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory
BundleLocation: null
Properties:
gems = openhab-scripting=~>4.0 service.pid = org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory ----------------------------------------------------------------
Which made me suspicious, and created the config file by hand.
/etc/openhab # cat services/jruby.cfg
org.openhab.automation.jrubyscripting:gems=openhab-scripting=~>4.0
Which shows up at the correct pid:
---------------------------------------------------------------- Pid: org.openhab.automation.jrubyscripting BundleLocation: null Properties: gems = openhab-scripting=~>4.0 service.pid = org.openhab.automation.jrubyscripting ----------------------------------------------------------------
This seems to have solved the issue, I now see gems show up in the OpenHAB lib folder, and the script loads successfully.
Is it safe to say I ran into a bug with the JRuby Scripting bundle?
@mvandamn What command did you use to see this pid?
In the OpenHAB console you can get all config settings using config:list
, and look for the JRuby ones.
openhab> config:list | grep -B 5 -A 1 automation.jruby
Properties:
defaultSink = enhancedjavasound
felix.fileinstall.filename = file:/var/lib/openhab/etc/org.openhab.audio.cfg
service.pid = org.openhab.audio
----------------------------------------------------------------
Pid: org.openhab.automation.jrubyscripting
BundleLocation: null
Properties:
gems = openhab-scripting=~>4.0
service.pid = org.openhab.automation.jrubyscripting
----------------------------------------------------------------
Pid: org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory
BundleLocation: null
Properties:
gems = openhab-scripting=~>4.0
service.pid = org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory
----------------------------------------------------------------
Thanks!
EDIT: Sorry I was mistaken. I encountered the same issue as you reported. Iâll look into this more, thank you for the report.
@mvandamn Would you mind testing the fixed addon from here:
The jar should work on your openhab 3.2.0 installation, I think. Youâd need to uninstall the built in one first, and drop this jar in your /addons directory.
An openhab restart will be necessary.
Thank you!
Hi @JimT,
Iâve done the following to test:
/etc/openhab/scripts/ruby
folderjruby.cfg
fileThis didnât clear out the configuration so I deleted those per console
openhab> config:delete org.openhab.automation.jrubyscripting
openhab> config:delete org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory
/usr/share/openhab/addons
)(LoadError) no such file to load -- openhab
openhab-scripting=~>4.0
to the gems parameter via the web-interfaceThis seems to end up at the right pid.
Pid: org.openhab.automation.jrubyscripting
BundleLocation: null
Properties:
gems = openhab-scripting=~>4.0
service.pid = org.openhab.automation.jrubyscripting
After a couple of seconds the gems have reappeared in the scripts
folder, and the automation script loads without errors.
@mvandamn Thank you again for the excellent test and feedback. It sounds like it had solved the problem.
The PR has been merged to be included in the upcoming 3.3.0.M4
You are welcome to continue using the new jar until youâve upgraded to 3.3 (although youâd need to remember to swap it back with the release build then).
There have been several fixes since 3.2.
Thanks @JimT and youâre welcome
JRuby combined with the library is a real joy to write automatons in!
I donât know if Iâm being blind or stupid, but where am I supposed to put the actual rules files written in ruby?
Simply changing existing rules in conf/rules/some_rule.rules
to the jruby syntax complains about do
. If putting them into conf/automation/lib/ruby/personal
(the path referred by âorg.openhab.automation.jrubyscripting:rubylibâ in jruby.cfg
also isnât doing anything.
jruby scripting is definitely working as evident by dropping hello world into conf/automation/jsr223/ruby/personal/test.rb'
which is triggering.
Your scripts should be in conf/automation/jsr223/ruby/personal/
So just to make this completely clear:
conf/automation/jsr223/ruby/personal
This is for:
conf/automation/lib/ruby
This is for:
conf/rules
This is only for rules written in the openHAB rule DSL
Is this correct?