Blockly loop and timer behavior changed from 3.4 ot 4.0? Loops do not work anymore

My timer loops that used to work in 3.4 get stuck in infinite loops in 4.0. Is this intentional, or is it a bug?


The script above used to work in 3.4, but does no more, now it ends up in an infinite loop.

A quick search will find similar issue and workaround:

Any ideas if the fix will be included in the next dot release?

Yes, it has been fixed but waits for the “merge”:

Update: Merged finally

1 Like

I see the fix did not make it to 4.0.3 :worried:

I am sorry to hear that. @florian-h05 , any idea why?

I did not backport the PR in time for the release because I was away from home. It is now backported, so it at least will be in the next release.

1 Like

Is this fix now in 4.0.4?

Yes, the fix has been backported and is in 4.0.4.

It was just missing in the release notes, but meanwhile release notes were corrected.

Blockly loops still don’t work :worried:

Have you opened the Blocklies and saved them? Blockly needs to regenerate the code.

1 Like

I did open and save, still no success. The script worked in 3.4, but no more.

To test, I wrote the script below. It never exits.

Is the problem in my code or is this a bug?

Some questions and a proposal:

Why do you do a repeat loop around a timer??? What is the intent here?
This creates the same time three times which may have unexpected results.

Can we simplify the topic and just create the one timer only and remove the repeat loop?

What code is it creating?

if (cache.private.exists('MyTimer') === false || cache.private.get('MyTimer').hasTerminated()) {
  cache.private.put('MyTimer', actions.ScriptExecution.createTimer('MyTimer',, function () {'abc');

Do you want the timer to run only three times and then stop? Because then the right way to do it is as follows:

Update note: As mentioned by Rich, there is a small mistake in the above image as it needs to be “cnt >=0”. Sorry for the confusion.

1 Like

Hello, thanks for the answer.

The idea is to test and confirm that loops work as they should in OpenHAB 4.0.4. Blockly loops stopped working with the 4.0.0. release and should now work again. Hence, I wrote a short code just to confirm that the loops now work.

Understood, thanks, though the use with the repeat does not make sense for me as a legit usecase as it recreates the timer several times. So, if the one I posted works for you, I would say we are good. agreed?


I tried this, the loop executes 2 times and exits regardless of the value of cnt.

Can you confirm this behavior?

There’s an off by one error in @stefan.hoehn’s code. It should be “if cnt >= 0”. With just > the timer will only reschedule itself twice instead of three times.

30 years of programming and I still don’t get loops right :rofl: Thanks Rich.

1 Like

This is the whole wakeup light blockly code, after I changed the loop. For some reason the second loop, that should start with the “Dawn ended, sunrise starts” log info is never reached. It seems the code never exits the previous loop.

Please pray the full rule by clicking the code grab and pasting the YAML you find there into a reply. Use code fences.

code goes here