Copy of Blockly rules?

Hello community,

is there a way to copy a Blockly rule to use it as a template, for an identical rule with different triggers and actors?

Thanks, best regards and stay healthy

You should look at

Happy new year Rich,

an thanks for your hints. After taking for one hour a look inside the Tutorial … I think … well, for simple function I will be able to manage this but for my dimmer-template it will be much more harder and will not be done within a couple of hours.

The first problem is that the mentioned links to the Blockly playground (Blockly Demo: Blockly Developer Tools, Advanced Blockly Playground) include only basic Blockly toolboxes, but what I need for me Dimmer needs timers, things and all taht funny stuff we’ve got in openhab.

Even if it is unsporting, but for my purposes it seems to go faster if I “paint” the rule several times without any expierence in hard Blockl programming. The topic is very exciting, but it requires a lot of time to learn, which I can’t afford right now.

Best regards and stay healthy

This is what I wrote the Blockly Reference for: see Blockly Reference

Hello Stefan,

thanks for the link and the excelent job you did. I’ve discovered your reference some days befor an read some chapters. This was very helpfull.

Currently I try to write an own Bloclly block to use the HUE “.fadingLightCommand” … but I’m strugglink, because I have to use the getActions command and I’m not familare with java. So maybe you can support me by doing this job.

uid: HUE_fading
tags: []
  parameters: []
  parameterGroups: []
timestamp: Jan 2, 2022, 12:44:23 PM
component: BlockLibrary
  name: Block Library c107d09908
    - component: BlockType
        type: block1
        message0: HUE brightness [%] %1 within [ms] %2 with Thing %3
        lastDummyAlign0: right
          - type: input_value
            name: BRIGHTNESS
          - type: input_value
            name: FADIING_TIME
            text: some text
          - type: input_value
            name: THING_ID
        previousStatement: ""
        nextStatement: ""
        inputsInline: false
        colour: 0
        tooltip: ""
        helpUrl: ""
          - component: BlockCodeTemplate
              template: >
                var hueActions = getActions("hue",{{input:THING_ID}});
                hueActions.fadingLightCommand("color", new PercentType({{input:BRIGHTNESS}}), new DecimalType({{input:FADIING_TIME}}))
    - component: UtilityJavaType
        name: things
        javaClass: org.openhab.core.model.script.actions.Things

So this is the Blockly component I try to write … an it seems that Blockly ist not the problem because the parameter transfer works fine.

What will work not correctly ist the code. But I’m totaly confused of this because my research within the forum shows different solution that will not work for me an produce errors.

val hueActions = getActions("hue",{{input:THING_ID}})
hueActions.fadingLightCommand("color", new PercentType({{input:BRIGHTNESS}}), new DecimalType({{input:FADIING_TIME}}))

actions.get("hue",{{input:THING_ID}}).fadingLightCommand("color", PercentType({{input:BRIGHTNESS}}), DecimalType({{input:FADIING_TIME}}))

Here you can see two impementations that won’t work correctly. Do you have any idear how to fix this? Or do you think taht it should be better to create a new thread in this forum?

Best regards, an stay healthy

Nope, I can’t help you with the custom blocks. Sorry.

Create a new thread is best I think.

The best way to debug something like this is probably too write the JS code first, perhaps in the scratchpad and then teacher that to Blockly with the Townshend replacement springs.

First - maybe unrelated to your problem:

You should avoid declaring variables like that because if you add multiple instances of the block you would potentially redefine the variable - there is a special syntax {{temp_name:something}} to ensure you’ll get an unique name for each block instance.

But in this case this code will not work anyways because getActions is not defined on its own in JS scripts. Look at other examples for the proper way to call a thing action, for example MQTT Actions.
You have to call getActions from the “things” utility that you declared:

              template: >
                {{utility:things}}.getActions('hue', {{input:THING_ID}}).fadingLightCommand("color", new PercentType({{input:BRIGHTNESS}}), new DecimalType({{input:FADIING_TIME}}));

The next part I’m not sure, are you using this in a rule action (a “Then” script module)?
If so copy the whole contents of the Code tab in the rule page (YAML with triggers, conditions and actions) so we can try to reproduce it.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.