since the migration to OH3 I try to do the first steps with Blockly. For now I found only a few tutorials in connection with smart home. One was from iobroker but the options available there are slightly different from those available in OH. Therefore I was not really able to adopt it.
These are my bery first steps. Please don’t blame me if the questions are “stupid”.
What I want to do:
check if an Item (String) contains a specific text
I am aware that (1) is a script not a rule but OH only allows me to chose a rule name as a script… If I choose to run a script I cannot provide a script name but had to provide code which is not what I want:
You don’t have to. It’s already in a function that will be called when the rule gets triggered. You don’t need a function for this.
If you want a function, perhaps because you have something you want to encapsulate so you ca call it from more than one place in the Script Action, then when you create the function there will be a new block added to “Functions” with the name of the function. Drag that to the screen, set any arguments if necessary (I have a String argument named “foo” set to “Foo” in this screen shot).
In MainUI a Script is just a rule that doesn’t have the when and but only if sections. They are a place to experiment with code that you can run manually, or a place to put code that gets called from other rules. I use it as a library of examples for how to do things too. If I can’t remember how to create a Timer, I bring up my “createTime example” script and refresh my memory.
Correct. You need triggers to run a rule in response to an event. You can’t define triggers on a Script (at least through MainUI). But behind the scenes, the only difference between a Script and a Rule is that a Script lacks triggers, conditions, and only has one Script Action. You can actually create a Script from the Rules or Schedule pages. Just add a single Script Action and add “Script” as a tag and it will end up on the Script page.
a central library with such examples would be great! Especially for beginners to try around. Just your mentioned “create time” would be a good start for tinkering. For the masses perhaps in blockly most interesting to look at
Anyone who wants to create such a library and post is somewhere are welcome to. My “library” of examples are actually the sorts of things that most users who would use such a library would not/should not be doing like dynamically creating and calling a rule from another rules’s Script Action, setting and reading an Item’s metadata, dynamically creating and deleting Items, etc. These are not basic building blocks and to a large extent, they are already covered and made simpler to do in the Helper Libraries or my own openHAB Rules Tools which, at some point, I hope to merge at least some of into the Helper Libraries.