Perhaps I just can’t see the forest for the trees, but is there a tutorial somewhere on how to use the new rules with scripts? I never used scripted rules except some JS-transformations, so I don’t seem to get, how I can use variables like channels or variables in jython or JS - and how I start the rules and whatnot…
I’m lost and need some intro to using UI-based OH3 script rules which not only change items’ states but use complex logic to achieve something like shutters or the likes!
To be honest we’re a bit behind with those docs.
I am trying to collect the informations where they are available.
Probably there is already some content in the documentation area.
Currently we are finishing the beginner tutorials which are getting moved from the documentation area too.
If github is the problem don’t mind to start here in the docs area with a wiki post.
Copy/paste at a later state to get it in the website is done quick and easy.
Note that the above is all focused on creating rules through the UI. If you will be writing rules in text files the Helper Libraries docs, in particular the But How Do I… page is great. Note that I don’t think the Helper Libraries are ready for OH 3 yet.
There are Python versions of all of the Design Pattern posts (those not written by me have them in a reply) and I’m in the process of rewriting them using JavaScript UI based rules as well (TimeOfDay and Debounce are the only two I’ve posted so far). You can see what I’ve written and reuse the code itself from https://github.com/rkoshak/openhab-rules-tools. The Python versions depend on the Helper Libraries so are OH 2.5 only for now. The JabaScript libraries do not but are coded assuming OH 3 so are not backwards compatible. Rules (like Time of Day and Debounce) are posted as YAML and can be pasted into a UI rule’s code tab.
A last (maybe stupid) question
When I want to write my own rules where is the entry point for the documention? An example:
The “Example rules for a first impression” example.
where can I find TypeUID definition (timer.GenericCronTrigger) for GenericCronTrigger and the regarding configuration object, the Syntax “cronExpression” string itself and its parameter, for example when I want to create a channel trigger, without deep diving into the Java Source code.
API parameter for the Configuration constructor is just a map/Hashtable in case of the timer.GenericCronTrigger two strings for key and value. Where I have to look for the correct parameters…
Update: Found this is defined in the trigger handler. Is this the only way to determine those parameters?
That stuff is why I strongly recommend using the Helper Library. Then defining a rule is as simple as:
from core.rules import rule
from core.triggers import when
@rule("My rule name")
@when("Item MyItem changed")
def myFunction(event):
# your rule's code goes here
If you don’t want to use the Helper Libraries, than at least look at the library code for how it does various things like this.
There is already a PR that makes it work with OH 3.
I believe the plan is to make it available as an add-on.
There is also plans to (just in the discussion stage at this point) to have marketplace where add-ons, rules libraries, and widgets could be distributed. But that’s long term.