[SOLVED]Jruby group error

openHAB version 4.0.1
Jruby installed through UI, all rules written in UI

I’ve been having a problem with any of my Jruby rules that use groups. I finally figured out how to fix it but I can’t tell if it is a bug or intended behavior. The issue seems to come for group names needing to have an upper case letter as the first character in the name.

Most of my group items have names starting with a ‘g’ to indicate that it is a group. To test this behavior, I created a very simple script and run it using the ‘Run Now’ button. Here is the script:

gBathLights << OFF

results in:

2023-08-12 10:51:34.297 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'rubytestscript' failed: Error during evaluation of Ruby in <script> at line 1: (NameError) undefined local variable or method `gBathLights' for main:Object

So I created a new group with all the same members called GBathLights and run the same simple script and it works, no errors and the lights all switch. What is really hilarious is that after all the lights switch, I see the other group get updated by the members switching

2023-08-12 10:56:46.301 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'gBathLights' changed from 100 to 0

Are items or groups only supposed to start with uppercase letters?

I name (almost) all my groups the same as you (with a lower case “g”), and don’t have any problems. But I also don’t create them in the UI, only file-based. So I’ll check that out when I have time. But one thing to check in the meantime… in the JRuby config, you have a default require of “openhab/dsl”, right?

Thanks for looking Cody, I didn’t want to ping you directly

I have a file /etc/openhab/services/jruby.cfg
here is contents:

org.openhab.automation.jrubyscripting:gems=openhab-scripting=~>5.0.0
org.openhab.automation.jrubyscripting:require=openhab/dsl

crazy thing is… in the old version I know under Settings → Other Services → JRuby Scripting there was Jruby now look???


I’m I blind???

Um, no, you’re not blind. Mine doesn’t show it either?! I can still go directly to /settings/services/org.openhab.automation.jrubyscripting though.

Change that version number in the config from 5.0.0 to 5.0,

Or better yet, delete jruby.cfg so you’ll use the default values.

oh thank god… I thought I was losing it

That works Cody thanks

OK… got it, had to log into directory as root but file deleted

Edit to include Big thanks for help :+1: :+1: :+1:

Might provide more clues… when I was dorking around figuring out the upper case work around, I was getting a bunch of crazy error messages about Error evaluating `require ‘openhab/dsl’
Example

==> /var/log/openhab/openhab.log <==
2023-08-12 13:57:42.793 [WARN ] [ernal.JRubyScriptEngineConfiguration] - Error evaluating `require 'openhab/dsl'`
org.jruby.exceptions.NameError: (NameError) missing class name org.openhab.core.semantics.model.point.Points
	at org.jruby.javasupport.JavaPackage.method_missing(org/jruby/javasupport/JavaPackage.java:253) ~[?:?]
	at RUBY.<module:Semantics>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:192) ~[?:?]
	at RUBY.<module:Items>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:160) ~[?:?]
	at RUBY.<module:Core>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:11) ~[?:?]
	at RUBY.<module:OpenHAB>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:10) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:9) ~[?:?]
	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1057) ~[?:?]
	at uri_3a_classloader_3a_.META_minus_INF.jruby_dot_home.lib.ruby.stdlib.rubygems.core_ext.kernel_require.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items.rb:6) ~[?:?]
	at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1987) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items.rb:5) ~[?:?]
	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1057) ~[?:?]
	at RUBY.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core.rb:97) ~[?:?]
	at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1987) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core.rb:96) ~[?:?]
	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1057) ~[?:?]
	at org.jruby.RubyKernel.require_relative(org/jruby/RubyKernel.java:1084) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/dsl.rb:10) ~[?:?]
	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1057) ~[?:?]
	at RUBY.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:160) ~[?:?]
	at RUBY.<main>(<script>:1) ~[?:?]
2023-08-12 13:57:42.798 [ERROR] [ore.internal.events.OSGiEventManager] - bundle org.openhab.core:4.0.1 (149)[org.openhab.core.internal.events.OSGiEventManager(7)] : The addEventSubscriber method has thrown an exception
org.jruby.exceptions.NoMethodError: (NoMethodError) undefined method `to_set' for ["ItemAddedEvent", "ItemUpdatedEvent", "ItemRemovedEvent"]:Array
Did you mean?  to_s
	at RUBY.getSubscribedEventTypes(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/proxy.rb:56) ~[?:?]
	at RUBY.register_service(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/osgi.rb:48) ~[?:?]
	at RUBY.initialize(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/proxy.rb:47) ~[?:?]
	at org.jruby.RubyClass.new(org/jruby/RubyClass.java:897) ~[?:?]
	at RUBY.instance(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/singleton.rb:127) ~[?:?]
	at org.jruby.ext.thread.Mutex.synchronize(org/jruby/ext/thread/Mutex.java:171) ~[?:?]
	at RUBY.instance(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/singleton.rb:125) ~[?:?]
	at RUBY.new(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/proxy.rb:113) ~[?:?]
	at RUBY.lookup_item(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/entity_lookup.rb:170) ~[?:?]
	at RUBY.lookup_entity(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/entity_lookup.rb:111) ~[?:?]
	at RUBY.const_missing(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/entity_lookup.rb:185) ~[?:?]
	at RUBY.<main>(<script>:1) ~[?:?]

I can upload the whole log from when I was working on this if it will help but was not set to debug only warn

Try restarting openhab first, so you get the latest jruby helper library (version 5.5.x). There were some changes in openhab semantics and correspondingly adapted to the later versions of the helper library.

I restarted openHAB and the host a couple times as I thrashed about this morning but I’ll restart the host right now just to make sure. I tried a line out of a script you wrote to confirm which version of the library was running but it tossed an error. Let me know how to confirm latest
Bouncing host now… see ya’ll in a few :slightly_smiling_face:
Thanks for all your help Cody, I love ruby in openHAB

We are currently working on redesigning the settings page of Main UI, in the mean time, the addon settings can only be accessed though the blue gear icon from the addon page in the addon store.

1 Like

@Andrew_Rowe: did you get it resolved yet? I’m not able to reproduce. I’ve created a script in the UI:

And when I press “Run Now”, I get this in my openhab.log:

2023-08-15 08:07:58.908 [INFO ] [hab.automation.jrubyscripting.script] - #<OpenHAB::Core::Items::GroupItem gAllOff nil state=NULL>

My jrubyscripting config:

And if I do a script of this:

logger.info(OpenHAB::DSL::VERSION)

I get this in the log:

2023-08-15 08:13:43.399 [INFO ] [hab.automation.jrubyscripting.script] - 5.5.0

@florian-h05 Hmm, but that sends me to /settings/addons/automation-jrubyscripting/config, which just allows setting some log level (I’m not sure for which logger), not to /settings/services/org.openhab.automation.jrubyscripting.

EDIT: Holy crap Cody
I noticed you had

openhab-scripting=~>5.0

and I had

openhab-scripting=~>5.0.0

I changed it to match yours and error gone!!!
Woohoo :+1: :+1: :+1:
(found a group that still had lower case first character)
image
results in:

2023-08-15 18:16:19.441 [INFO ] [openhab.event.RuleUpdatedEvent      ] - Rule 'rubytestscript' has been updated.
2023-08-15 18:16:21.735 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'gEdisonBulbs' received command 0
2023-08-15 18:16:21.735 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Huefilamentbulb2_Brightness' received command 0
2023-08-15 18:16:21.735 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Huefilamentbulb1_Brightness' received command 0
2023-08-15 18:16:21.735 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Huefilamentbulb3_Brightness' received command 0
2023-08-15 18:16:21.736 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Huefilamentbulb2_Brightness' predicted to become 0
2023-08-15 18:16:21.736 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Huefilamentbulb1_Brightness' predicted to become 0
2023-08-15 18:16:21.736 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'Huefilamentbulb3_Brightness' predicted to become 0
2023-08-15 18:16:21.736 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Huefilamentbulb2_Brightness' changed from 100 to 0
2023-08-15 18:16:21.736 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Huefilamentbulb1_Brightness' changed from 100 to 0
2023-08-15 18:16:21.736 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Huefilamentbulb3_Brightness' changed from 100 to 0
2023-08-15 18:16:21.736 [INFO ] [hab.event.GroupItemStateChangedEvent] - Item 'gEdisonBulbs' changed from 100 to 0 through Huefilamentbulb2_Brightness

==> /var/log/openhab/openhab.log <==
2023-08-15 18:16:21.737 [INFO ] [hab.automation.jrubyscripting.script] - 5.5.0

you are a rockstar… THANK YOU for help and sorry for noise
now what really baffles me is why it worked with an upper case first letter

IGNORE ALL THIS BELOW
I deleted all my groups that had lower case characters for the first character but I found an item that has lowercase and it throws an error as well
here is script
image
Here is script being saved

2023-08-15 17:50:50.334 [INFO ] [openhab.event.RuleUpdatedEvent      ] - Rule 'rubytestscript' has been updated.

here is error

==> /var/log/openhab/openhab.log <==
2023-08-15 17:51:02.395 [WARN ] [ernal.JRubyScriptEngineConfiguration] - Error evaluating `require 'openhab/dsl'`
org.jruby.exceptions.NameError: (NameError) missing class name org.openhab.core.semantics.model.point.Points
	at org.jruby.javasupport.JavaPackage.method_missing(org/jruby/javasupport/JavaPackage.java:253) ~[?:?]
	at RUBY.<module:Semantics>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:192) ~[?:?]
	at RUBY.<module:Items>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:160) ~[?:?]
	at RUBY.<module:Core>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:11) ~[?:?]
	at RUBY.<module:OpenHAB>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:10) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:9) ~[?:?]
	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1057) ~[?:?]
	at uri_3a_classloader_3a_.META_minus_INF.jruby_dot_home.lib.ruby.stdlib.rubygems.core_ext.kernel_require.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items.rb:6) ~[?:?]
	at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1987) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items.rb:5) ~[?:?]
	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1057) ~[?:?]
	at RUBY.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core.rb:97) ~[?:?]
	at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1987) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core.rb:96) ~[?:?]
	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1057) ~[?:?]
	at org.jruby.RubyKernel.require_relative(org/jruby/RubyKernel.java:1084) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/dsl.rb:10) ~[?:?]
	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1057) ~[?:?]
	at RUBY.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:160) ~[?:?]
	at RUBY.<main>(<script>:1) ~[?:?]
2023-08-15 17:51:02.415 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'rubytestscript' failed: Error during evaluation of Ruby in <script> at line 1: (NameError) undefined local variable or method `lighthuewhitedesk_Brightness' for main:Object

Edit script to be only your log line above and result is

==> /var/log/openhab/openhab.log <==
2023-08-15 17:59:04.804 [WARN ] [ernal.JRubyScriptEngineConfiguration] - Error evaluating `require 'openhab/dsl'`
org.jruby.exceptions.NameError: (NameError) missing class name org.openhab.core.semantics.model.point.Points
	at org.jruby.javasupport.JavaPackage.method_missing(org/jruby/javasupport/JavaPackage.java:253) ~[?:?]
	at RUBY.<module:Semantics>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:192) ~[?:?]
	at RUBY.<module:Items>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:160) ~[?:?]
	at RUBY.<module:Core>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:11) ~[?:?]
	at RUBY.<module:OpenHAB>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:10) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items/semantics.rb:9) ~[?:?]
	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1057) ~[?:?]
	at uri_3a_classloader_3a_.META_minus_INF.jruby_dot_home.lib.ruby.stdlib.rubygems.core_ext.kernel_require.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items.rb:6) ~[?:?]
	at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1987) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core/items.rb:5) ~[?:?]
	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1057) ~[?:?]
	at RUBY.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core.rb:97) ~[?:?]
	at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1987) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/core.rb:96) ~[?:?]
	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1057) ~[?:?]
	at org.jruby.RubyKernel.require_relative(org/jruby/RubyKernel.java:1084) ~[?:?]
	at RUBY.<main>(/etc/openhab/automation/ruby/.gem/9.4.2.0/gems/openhab-scripting-5.0.1/lib/openhab/dsl.rb:10) ~[?:?]
	at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1057) ~[?:?]
	at RUBY.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:160) ~[?:?]
	at RUBY.<main>(<script>:1) ~[?:?]
2023-08-15 17:59:04.822 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'rubytestscript' failed: Error during evaluation of Ruby in org/jruby/RubyModule.java at line 4309: (NameError) uninitialized constant OpenHAB::DSL::VERSION

what am I doing wrong?
I don’t know if this will be readable but here is my config

An upper case first letter is a constant in Ruby, so goes through const_missing instead of method_missing in the library, and those two hooks have slightly different semantics. I feel like I remember fixing a bug like this in some cases, but I can’t find a commit for it between 5.0.1 and now.

I kinda thought that might have something to do with it after reading the variables documentation. From the error messages I also suspected I had the wrong library loaded. I really appreciate your help.

I’ve also edited my post in the Consistent 100% CPU use of safeCall-queue thread where I mistakenly accused Jruby of having a bug

The add-on config page allows to set the log level for the addon package logger (org.openhab.automation.jrubyscripting).

I have created [jrubyscripting] Allow configuration from add-on page by florian-h05 · Pull Request #15438 · openhab/openhab-addons · GitHub to make the service settings appear in the addon settings.