Collection of common blocks

No Problem, enjoy your trip! :slight_smile: And thanks for the link!

I tried myself, but I’m not a developer and I’m just puzzling here :smiley:

As writing it down might help, here is what I tried:

Generated code from the old script
var scriptExecution = Java.type('org.openhab.core.model.script.actions.ScriptExecution');

var zdt = Java.type('java.time.ZonedDateTime');


if (typeof this.timers === 'undefined') {
  this.timers = [];
}
if (typeof this.timers['MyTimer'] === 'undefined' || this.timers['MyTimer'].hasTerminated()) {
  this.timers['MyTimer'] = scriptExecution.createTimerWithArgument(zdt.now().plusSeconds(10),event, function (event) {



  })
}
Generated code from the new timers
if (cache.private.exists('MyTimer') === false || cache.private.get('MyTimer').hasTerminated()) {
  cache.private.put('MyTimer', actions.ScriptExecution.createTimer('MyTimer', time.ZonedDateTime.now().plusSeconds(10), function () {
    }));
};

Code from the rule template:

                if (typeof this.timers === 'undefined') {
                  this.timers = [];
                }

                if (typeof this.timers[{{input:timer_name}}] === 'undefined' || this.timers[{{input:timer_name}}].hasTerminated()) {
                  this.timers[{{input:timer_name}}] = {{utility:scriptExecution}}.createTimerWithArgument({{utility:zdt}}.now().{{field:duration_unit}}({{input:duration}}),event, function (event) {

                  {{statements:timer_statement}}

                  })
                }
My try to adapt, but without any idea how to integrate the selector for private or shared cache

                if (cache.private.exists[{{input:timer_name}}] === false) || cache.private.get[{{input:timer_name}}].hasTerminated()){
                    cache.private.put([{{input:timer_name}}] = {{utility:scriptExecution}}.createTimerWithArgument([{{input:timer_name}}] , ({{utility:zdt}}.now().{{field:duration_unit}}({{input:duration}}),event, function (event) {

                  {{statements:timer_statement}}

                  })
                }

It all is way more complicated than I thought. Seems like I can’t even understand the Tutorial

I tried to setup a library, to get things started, but this doesn't even compile
uid: blocklibrary_test
tags: []
props:
  parameters: []
  parameterGroups: []
timestamp: Nov 11, 2023, 3:45:48 PM
component: BlockLibrary
config:
  name: Block Library Reschedule with context test
slots:
  blocks:
    - component: BlockType
      config:
        args0:
          - check: Number
            name: duration
            type: input_value
          - name: duration_unit
            options:
              - - seconds
                - plusSeconds
              - - minutes
                - plusMinutes
              - - hours
                - plusHours
              - - days
                - plusDays
              - - weeks
                - plusWeeks
              - - months
                - plusMonths
            type: field_dropdown
          - check: String
            name: timer_name
            type: input_value
          - default: mail@demo
            name: timer_statement
            type: input_statement
        colour: 0
        helpUrl: https://openhab-scripters.github.io/openhab-helper-libraries/Guides/Event%20Object%20Attributes.html
        inputsInline: true
        message0: after %1 %2 do with %3 %4 and keep triggering event-context
        nextStatement: ""
        previousStatement: ""
        tooltip: Schedules a new timer and will pass the event variable as argument to the timer, that you can reuse the initial event during timer execution (e.g. event.itemName)
        type: timerWithInitialEvent
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: >
                if (cache.private.exists[{{input:timer_name}}] === false || cache.private.get[{{input:timer_name}}].hasTerminated()){
                    cache.private.put([{{input:timer_name}}] = {{utility:scriptExecution}}.createTimerWithArgument([{{input:timer_name}}] , ({{utility:zdt}}.now().{{field:duration_unit}}({{input:duration}}),event, function (event) {

                  {{statements:timer_statement}}

                  })
                }
        toolbox:
          - component: PresetInput
            config:
              fields:
                TEXT: MyTimer
              name: timer_name
              shadow: true
              type: text
          - component: PresetInput
            config:
              fields:
                NUM: 10
              name: duration
              shadow: true
              type: math_number

I’ll get some good rest and try another day.

Is there any place where I can see the setup from current timers blockly library to start with?
I only found that and it doesn’t look like a blockly library at all to me.