How to disable a rule from a Blockly script?

Could it be that the problem is that the rule is disabling itself? Has something changed in how this is handled? It worked earlier, i.e. rule turns itself off, waits x seconds (via a timer) and then turns itself on again. It does not seem to work now, but I’m not sure whether it’s because of this self-referential logic or something else.

I just stumbled over this topic, i created a block a few weeks ago.

uid: rulesenabledisable
tags: []
props:
  parameters: []
  parameterGroups: []
timestamp: Apr 29, 2025, 8:28:10 PM
component: BlockLibrary
config:
  name: Rules
slots:
  blocks:
    - component: BlockType
      config:
        args0:
          - name: ruleID
            type: input_value
          - name: bolean
            type: input_value
        colour: 0
        helpUrl: ""
        inputsInline: true
        message0: rule with id %1 set enable %2
        nextStatement: ">"
        previousStatement: ""
        tooltip: Will enable or disable a Rule
        type: ruleEnableDisable
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: |
                rules.setEnabled({{input:ruleID}}, {{input:bolean}});
        toolbox:
          - component: PresetInput
            config:
              name: bolean
              type: logic_boolean
          - component: PresetInput
            config:
              fields:
                TEXT: rule ID
              name: ruleID
              shadow: true
              type: text

Just create a new block in your block libraries and put this code in.

2 Likes

Oh, wow! I wasn’t even aware that you could create own blocks. And that block of yours looks very useful. Thank you for sharing it. I added it to my library.

I solved my particular problem by changing the setup so that I no longer have the rule deactivate itself, but the time will come, when it will come to good use.