Rule to turn OFF the charger relay the when the battery voltage reaches 395V

Also what’s your openhab version?

If you’re still using openhab 3.x, you need to set some configurations, especially step 2 in
the Installation steps

If you’re using openhab 4.x you don’t need to do this step 2.

Doesn’t the newly created file have to be put in the rules folder?

in my addons.cfg i need just to uncomment automation= ???
they need to be `automation=jrubyscripting’ ?

my jruby.cfg

No. The conf/rules/ folder is strictly for RulesDSL scripting language. It is not for Ruby rules.

Ruby rules should be saved inside the conf/automation/ruby/ folder with a .rb extension.

No, if you did that, you’ll be telling openhab to install NO automation addons.

it needs to be:

automation = jrubyscripting

Then give it 1-2 minutes to install. You can confirm that it’s installed by looking in the MainUI Add-ons Store → Automation.

I thought you had already installed jrubyscripting based on your screenshot a few posts earlier!

Your jruby.cfg looks fine.

Yes, I installed it but I thought that I enter the UI and after installation I can already create a rule

In openhab 4.x indeed you can. You don’t need to create jruby.cfg or uncomment that automation = line in addons.cfg. You can install it through the UI. But doing it from addons.cfg is fine too. In any case it seems to be installed?

Next we need to figure out why the file isn’t loaded or isn’t executed.

Do you know how to get to Karaf console to view openhab’s log, or to view the userdata/logs/openhab.log file?

If so, inside your turn_off_ch_relay.rb file, add this line at the very top of the file (line 1) "Hello, #{__FILE__} has been loaded"

then save the file. You should see an entry in openhab’s log like this:

02:00:44.633 [INFO ] [enhab.automation.jrubyscripting.test2] - Hello /openhab/conf/automation/ruby/turn_off_ch_relay.rb is loaded

The file is not loaded - i do not see this in logs.
I gave a restart but the rule is not visible in the Rules
I have OpenHab installed on Proxmox, I will test your instructions there as well.
It could be that something is not good here on Truenas
Thank you for your help

I’d love to know why it didn’t load.

I hate not knowing, so we make a good team :slight_smile:

To test if jrubyscripting itself is working:

  • Go to the “Script” section (the one we talked about earlier)
  • Create a script with one line "Hello, today is #{}"
  • Run it

You should see it in the log if it’s working

Ok, I install add on JRuby Scripting and after installation I receive this warning message.

2024-02-11 17:58:51.431 [WARN ] [ernal.JRubyScriptEngineConfiguration] - Error creating gem_home directory

I put the script you suggested above and ran it and got the errors below

2024-02-11 18:00:17.963 [WARN ] [ernal.JRubyScriptEngineConfiguration] - Error evaluating `require 'openhab/dsl'`
org.jruby.exceptions.LoadError: (LoadError) no such file to load -- openhab/dsl
	at org.jruby.RubyKernel.require(org/jruby/ ~[?:?]
	at RUBY.require(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85) ~[?:?]
	at RUBY.<main>(<script>:1) ~[?:?]
2024-02-11 18:00:18.019 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '5b642d9f6b' failed: Error during evaluation of Ruby in <script> at line 1: (NameError) undefined local variable or method `logger' for main:Object

That seems like a permission issue. The openhab user couldn’t create directories under conf/automation. Perhaps wrong directory ownership somewhere? Did you manually create some folders? If you did, perhaps you did that as root, so those folders are owned by root?

Fix the permissions and restart openhab.

Thank you very much teacher :slight_smile: