But it’s possible as evidenced by the “publish MQTT” Action which was my main point.
Which is why I wasn’t surprised to see them listed. But if we want to ever get to a point where users can export their JSON Rules to Python (for example) there will need to be some sort of concept in the Helper Libraries I suspect.
Available doesn’t necessarily mean that they work. There was some significant work a couple years ago to try and get JRuby to work as a suitable JSR223 language. There was some fundamentally technical hurdle that they could not overcome. I’m sure many others on that list can work, but there is at least one that will not. Perhaps jRuby or openHAB has changed since then to the point where it would work.
It’d be fun to write Rules in Scheme though. I have an intuition that the functional paradigm would work quite well for Rules. I just don’t have the time right now to try it out and see if it works.
The list is built from the available ScriptEngines. When you setup Jython or Groovy, you’ll see them in the list.
Binding ThingActions are currently visible in the UI, but they will likely soon be hidden until this is fixed. However, you’ll find that you can’t configure a topic for the MQTT Action, or add an email address, subject, or message body in a Mail Action, etc.
The helper libraries are a filler for interacting directly with OH classes and interfaces until a Scripting API is put in place. There will still be some use for them though (utility functions, experimental functionality not yet implemented in the API, custom ModuleTypes and handlers, etc.). I expect the Scripting API will be around long before someone looks into migrating JSON rules to scripted automation. It would also be easy to migrate a Condition too, since they are just a simple ‘if’ statement.
They should all work. However, a language specific ScriptEngineFactory may be needed for special handling of the default script scope. I haven’t tried jRuby, but I believe the issues early on were with the OH1 implementation.
Funny – just a couple of days ago I needed to trigger a JSR223/Jython rule based on the online/offline status of an MQTT/Homie device.
I came up with this on my own:
@rule("ServerRoomLightsChanged", description="", tags=["utility"])
@when("Thing \"mqtt:homie300:srvrm-lightsense\" changed")
Am I just lucky to have started in JSR223 to begin with? Would the when thing xxx changed pattern not have worked in Rules DSL? Or is it a matter of ONLINE/OFFLINE status being different for Z-Wave and Homie devices? I’ve only used this with Homie and it works perfectly there.
The OP was looking for a generic rule to alert when any Thing went offline… like ‘Member of’ but for Things. In the helper libraries, you can use GenericEventTrigger (not included in the when decorator).
FYI the new UI will offer a better experience than PaperUI for building rules graphically (“JSON rules”), as well as a script editor that’s actually useable.
(this is an early mockup, the appearence and functionality are subject to change!)
I’m running build 1640. I’ll go through the install steps again just to make sure I’ve not messed something up. If I didn’t I’ll open the issue. No news is good news (i.e. I messed something up somewhere along the way).
I meant to include a link. Running Actions from JSON Rules was where I stopped with the documentation but I think I have enough to get someone started. The helper libraries do most of the work for you though and you just need to pull the Action from a list of discovered Actions. There is a little bit showing how to do it using Lewie’s JS library which has since been merged with the Helper Libraries and may have changed a bit. Experimental Next-Gen Rules Engine Documentation 5 of : Actions
It won’t do for my very particular case, because of the cron based rule needed.
I’m looking at Modbus which has fast (typically per-second) polling and a retry mechanism. In case of an error (device unplugged), retries pile up, and the timeout waits affect other device responses. The benefit I’m looking for comes when acting within seconds to re-arrange modbus polling. So really I need an update-as-it-happens Thing status trigger.
I would not want to run the tag-based checking rule every second over a great many Things.
It looks very useful for less time-critical health monitoring.
I have some Things that sometimes goes offline for communication error but I just need to disable and enable again and they just go online again.
I would like to check with DSL rules the things status and if != ONLINE I would disable and enable them again.
I can read the THings status but is there any command to disable and enable a particolar thing?