Reuse Blockly function

  • Platform information:

    • Hardware: RPi 3b
    • OS: openhabian
    • openHAB version:3.3
  • Issue of the topic: I begin to define rules with blocky . I have multiple cases where I have a push button toggling some light
    So I created a function to check the state and send command ON or OFF depending on it.

Is there a an easy way to just reuse a function in another rule?

The only way I found is to copy the entire rule containing the function and then edit it.
In that case, the function is define multiple times and I cannot edit the code globally.

I saw the possibility to define a block library but from scratch… but no way to save a bloclky function in a library

Thanks for any help.

Regarding the toggle function, i finally found it already done on marketplace among other nice functions, Collection of common blocks , bu my quetion is still pending for other function I would like to create and share

There is no way to save and reuse a Blockly function across multiple rules right now.

In OH 4 it might be possible to save a function to the new sharedCache and it would be accessible to multiple rules that way. But today there’s no way short of creating the new blocks from scratch that you already found.

Thanks for the feedback

Alternatively you can also create your blockly code as script and then call this script (inclusive custom parameters) from your rule

Thanks for the tip