PS The other way is :
actions("pushover", "pushover:pushover-account:Pushover").sendMessage(result, "Openhab 3 - Front door Lock")
PS The other way is :
actions("pushover", "pushover:pushover-account:Pushover").sendMessage(result, "Openhab 3 - Front door Lock")
I have been severely delinquent in announcing new releases here as we are up to 4.8!
Lots of changes to go over, but I think the biggest one is that these rules has moved from alpha status to beta and are ready to be used in production systems.
Biggest changes since 3.9:
Special shout out to @ccutrer who came in with his Ruby experience and highly simplified a lot of code and completed adding all types to the language.
The ensure feature performs a check and only sends a command if the item is not already in that state.
For example:
Switch.ensure.on
is now valid and will only send the ON command if the Switch is not in the ON state, this replaces having to do Switch.on unless Switch.on?
throughout the code. See the docs for more details.
One thing this rules system seeks to do is make everything easier. I, personally, have always found timers in the OpenHAB to complex, error prone and require a lot of boilerplate to accomplish very simple tasks. A couple of changes were introduced in the latest release to address that:
Timers are now reentrant (meaning self resettable) if they are assigned an âidâ and are currently running rather than create a new timer they will reschedule. See the docs for more details.
Related to the reentrant timers, all items now have an implicit timer associated with commands. This is modeled by how some automation panels (Leviton OmniPro and others) enable simple timers without the complex logic needed to cancel, reschedule, etc. These âtimed commandsâ automatically cancel the timers if the state of the item is updated in anyway. For ON and OFF commands at the expiration of the timer they change to their inverse state, for other commands they revert to the state they were in when the command was issued.
For example, to turn a light on for 10 minutes:
light.on for: 10.minutes
This will turn the light on for 10 minutes and then turn it off after 10.minutes, if that command is issued again, the 10 minute timer will be reset.
For example, if you have some closet lights you want to turn on for 10 minutes and then turn off if they closet door is closed or if 10 minutes expire, you can do this:
rule 'Closet Door Lights' do
changed ClosetDoors.members
run do |event|
light = items["#{event.item.name}_Light"]
case event.state
when OPEN then light.on for: 10.minutes
when CLOSED then light.off
end
end
not_if { |event| items["#{event.item.name}_Light"].nil? }
otherwise { |event| logger.error "No matching light found for closet door #{event.item.name}" }
end
No need for complex timer logic, no creating virtual items with the expire bindingâŠ
More information is located in the docs.
4.10.1 is now released.
Biggest changes since 4.8:
Trigger attachments let you attach any object to trigger and retrieve them in the run block. This lets you reuse rules that have mostly the same logic with only a change in how they are triggered. For example:
rule 'Set Dark switch at sunrise and sunset' do
channel 'astro:sun:home:rise#event', attach: OFF
channel 'astro:sun:home:set#event', attach: ON
run { |event| Dark << event.attachment }
end
Attach the OFF command to the sunrise event and the on command to the sunset event. The run block then just sends the attached command to the Dark item.
More details available here.
4.13.01 is now released!
Changes since 4.10.1:
New between guard examples:
rule 'Log an entry if started between March 9th and April 10ths' do
on_start
run { logger.info ("Started at #{Time.now}")}
between '03-09'..'04-10'
end
new to_byte and scale examples:
HueBulb.red.to_byte # => 255
Volume.scale(-80..20) # Decibel scale
This blog post has a good review of the new features in ruby 2.6 now available in this binding.
As always big thanks to @ccutrer and @jimtng for all of their fixes and contributions!
Other big news - a PR has been submitted to the OpenHAB add-ons repository to merge in the JRuby binding!
Nice!!!
Iâm trying to run the binding from the internal addons repo that is shipped with OH 3.2.0.M5 and getting following errors:
[ERROR] [ng.internal.JRubyScriptEngineFactory] - bundle org.openhab.automation.jrubyscripting:3.2.0.M5 (244)[org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory(446)] : The activate method has thrown an exception
java.lang.BootstrapMethodError: bootstrap method initialization exception
at uri_3a_classloader_3a_.META_minus_INF.jruby_dot_home.lib.ruby.stdlib.rubygems.stub_specification.RUBY$block$data$1(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/stub_specification.rb:118) ~[?:?]
at org.jruby.runtime.CompiledIRBlockBody.yieldDirect(CompiledIRBlockBody.java:151) ~[?:?]
...
2021-12-15 21:38:02.311 [WARN ] [ipt.internal.ScriptEngineManagerImpl] - bundle org.openhab.core.automation.module.script:3.2.0.M5 (161)[org.openhab.core.automation.module.script.internal.ScriptEngineManagerImpl(173)] : Could not get service from ref {org.openhab.core.automation.module.script.ScriptEngineFactory}={service.id=702, service.bundleid=244, service.scope=bundle, rubylib=/etc/openhab/automation/lib/ruby/personal, component.name=org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory, gem_home=/etc/openhab/automation/lib/ruby/gem_home, service.config.label=JRuby Scripting, component.id=446, service.config.factory=false, service.config.category=automation, gems=openhab-scripting=~>4.0, service.config.description.uri=automation:jruby, service.pid=org.openhab.automation.jrubyscripting}
2021-12-15 21:38:02.313 [WARN ] [ipt.internal.ScriptEngineManagerImpl] - bundle org.openhab.core.automation.module.script:3.2.0.M5 (161)[org.openhab.core.automation.module.script.internal.ScriptEngineManagerImpl(173)] : DependencyManager : invokeBindMethod : Service not available from service registry for ServiceReference {org.openhab.core.automation.module.script.ScriptEngineFactory}={service.id=702, service.bundleid=244, service.scope=bundle, rubylib=/etc/openhab/automation/lib/ruby/personal, component.name=org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory, gem_home=/etc/openhab/automation/lib/ruby/gem_home, service.config.label=JRuby Scripting, component.id=446, service.config.factory=false, service.config.category=automation, gems=openhab-scripting=~>4.0, service.config.description.uri=automation:jruby, service.pid=org.openhab.automation.jrubyscripting} for reference ScriptEngineFactory
2021-12-15 21:38:12.265 [ERROR] [ng.internal.JRubyScriptEngineFactory] - bundle org.openhab.automation.jrubyscripting:3.2.0.M5 (244)[org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory(446)] : The activate method has thrown an exception
java.lang.BootstrapMethodError: bootstrap method initialization exception
at java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:194) ~[?:?]
at java.lang.invoke.CallSite.makeSite(CallSite.java:307) ~[?:?]
...
Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: no such method: org.jruby.runtime.Helpers.constructRubyStringArray(RubyString,RubyString,RubyString)RubyString[]/invokeStatic
at org.jruby.runtime.Helpers.constructRubyStringArrayHandle(Helpers.java:1510) ~[?:?]
Caused by: java.lang.IllegalAccessException: no such method: org.jruby.runtime.Helpers.constructRubyStringArray(RubyString,RubyString,RubyString)RubyString[]/invokeStatic
at java.lang.invoke.MemberName.makeAccessException(MemberName.java:959) ~[?:?]
at java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:1101) ~[?:?]
...
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method 'org.jruby.RubyString[] org.jruby.runtime.Helpers.constructRubyStringArray(org.jruby.RubyString, org.jruby.RubyString, org.jruby.RubyString)' the class loader 'bootstrap' of the current class, java/lang/Object, and the class loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @6116f3 for the method's defining class, org/jruby/runtime/Helpers, have different Class objects for the type org/jruby/RubyString used in the signature (java.lang.Object is in module java.base of loader 'bootstrap'; org.jruby.runtime.Helpers is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @6116f3, parent loader java.net.URLClassLoader @153b3e6)
at java.lang.invoke.MethodHandleNatives.resolve(Native Method) ~[?:?]
...
2021-12-15 21:38:12.360 [WARN ] [al.provider.ScriptModuleTypeProvider] - bundle org.openhab.core.automation.module.script:3.2.0.M5 (161)[org.openhab.core.automation.module.script.internal.provider.ScriptModuleTypeProvider(177)] : Could not get service from ref {org.openhab.core.automation.module.script.ScriptEngineFactory}={service.id=702, service.bundleid=244, service.scope=bundle, rubylib=/etc/openhab/automation/lib/ruby/personal, component.name=org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory, gem_home=/etc/openhab/automation/lib/ruby/gem_home, service.config.label=JRuby Scripting, component.id=446, service.config.factory=false, service.config.category=automation, gems=openhab-scripting=~>4.0, service.config.description.uri=automation:jruby, service.pid=org.openhab.automation.jrubyscripting}
2021-12-15 21:38:12.361 [WARN ] [al.provider.ScriptModuleTypeProvider] - bundle org.openhab.core.automation.module.script:3.2.0.M5 (161)[org.openhab.core.automation.module.script.internal.provider.ScriptModuleTypeProvider(177)] : DependencyManager : invokeBindMethod : Service not available from service registry for ServiceReference {org.openhab.core.automation.module.script.ScriptEngineFactory}={service.id=702, service.bundleid=244, service.scope=bundle, rubylib=/etc/openhab/automation/lib/ruby/personal, component.name=org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory, gem_home=/etc/openhab/automation/lib/ruby/gem_home, service.config.label=JRuby Scripting, component.id=446, service.config.factory=false, service.config.category=automation, gems=openhab-scripting=~>4.0, service.config.description.uri=automation:jruby, service.pid=org.openhab.automation.jrubyscripting} for reference ScriptEngineFactory
I was able to install and run the external binding version under OH 3.2.0-M4 without any issues, and tried to delete any binding installation artefacts (cleared cache, anything under /conf/automation/âŠ).
Any idea whatâs going wrong here and how to fix it?
Happy to provide more details if this helpsâŠ
BTW: Many thanks to the authors of this great binding which for me has made scripting under OH more a fun than a pain.
I see this error on M5 and possibly before M5. My rules still work though.
I am wondering if itâs related to the Java classes injected by scopeValues and the gem installation (which is evaluated in Ruby) during the bundle @Activate then tripped over the Java Classes. I was going to put a trace in the scopeValues to see if it occurred before @Activate, but I havenât got around to it yet.
Does it go away on restart?
@broconne I updated my post above⊠itâs just a hunch.
Iâm on a snapshot as of a day or two ago (so I think newer than M5?). I havenât noticed any errors in the logs, but that doesnât mean there werenât any. My rules are all working fine.
I had these errors as well when I first installed the bundle, but they went away after a restart. I deleted the old jar file from the addons-directory, and made sure is wasnât listed as installed in karaf, but perhaps there were still some remnants of the old bundle left causing conflicts?
Iâve tried to restart the bundle from the console and by restarting OH without success.
The diag for the bundle is:
openhab> bundle:diag 271
openHAB Add-ons :: Bundles :: Automation :: JRuby Scripting (271)
-----------------------------------------------------------------
Status: Waiting
Declarative Services
org.openhab.automation.jrubyscripting.internal.JRubyScriptEngineFactory (576)
Can you share more about how you installed it?
I did a clean install, downloaded m5, downloaded the kar file, put the kar file in addons, then I added âjrubyscriptingâ to the automation section of the services.cfg and I didnât have any errors in the logs.
On M5+ there should be no need to download the jar. jrubyscripting can be installed from the GUI, OR using text configuration by adding this inside conf/services/addons.cfg
automation = jrubyscripting
Can you try this in the console:
bundle:list -s | grep jruby
There should be just one listed.
It seems that my issue has disappeared after a further restart with cache deletion. The only thing I changed compared to my previous attemps was that I additionally deleted my ruby script from /automation/jsr223/ruby/personal
.
Is the documentation still current for openhab 3.2?
The binding could be installed from the UI, but logging does not seem to work.
rule 'Log the rule name every minute' do |rule|
description 'This rule will create a log every minute'
every :minute
run { logger.info "Rule '#{rule.name}' executed" }
end
Yes it is valid/current for 3.2. Iâm running the 3.2 release right now and tested the code above. It worked. You do need require âopenhabâ at the top of your script.
Whatâs the error message that you saw?
I dont get the logged message. the only way to get a logged message is to import
java_import org.slf4j.LoggerFactory
and use
run { LoggerFactory.getLogger(âorg.openhab.core.automation.examplesâ).info(âHello world!â) } -
This works as shown on the documentation JRuby Scripting - Automation | openHAB
⊠Am not sure as to there would be any additional settings that am missing.