Dash
(Dash)
August 19, 2023, 10:18pm
1
I’m on 4.0.2 and getting funny problems with my timers, they simply stop being rescheduled, which is a problem. I have a lot of movement scripts that will use timers for checking the current state and rescheduling to poll again later. It seems they will loop twice, and then without error, just stop.
Produces:
2023-08-19 23:15:38.373 [INFO ] [nhab.automation.script.ui.e9b04ffe62] - 0
2023-08-19 23:15:38.373 [INFO ] [nhab.automation.script.ui.e9b04ffe62] - Looping
2023-08-19 23:15:43.373 [INFO ] [nhab.automation.script.ui.e9b04ffe62] - 1
2023-08-19 23:15:43.374 [INFO ] [nhab.automation.script.ui.e9b04ffe62] - Looping
And then nothing. The timer simply doesn’t trigger the 3rd time. I’m flicking through the reams of docs, but I’m not seeing anything obvious saying this is now how it works. What’s the workaround? I’ve got a lot of scripts that use this approach.
JustinG
(JustinG)
August 19, 2023, 10:32pm
2
Probably the same as this:
It is almost always better to open a new thread than to reopen a years old thread. In this case Blockly has received a nearly complete overhaul for OH 4 so anything in the thread above isn’t going to apply.
But in a short answer, an issue has already been filed for this. It’s a bug. The work around is to create a new Timer instead of rescheduling. Or use an inline script block with the code above with the line cache.private.remove('TESTTIMER') moved into an else after the last if:
if (cache.pr…
opened 06:39PM - 02 Aug 23 UTC
bug
main ui
## The problem
A script that should count up from 0 to 10 every second aborts… after the second run with ECMAScript 262 edition 11:.

```
var count;
console.info('SCRIPT count');
count = 0;
if (cache.private.exists('MyTimer') === false || cache.private.get('MyTimer').hasTerminated()) {
cache.private.put('MyTimer', actions.ScriptExecution.createTimer('MyTimer', time.ZonedDateTime.now().plusSeconds(1), function () {
if (count <= 10) {
count = (typeof count === 'number' ? count : 0) + 1;
console.info(count);
if (cache.private.exists('MyTimer')) { cache.private.get('MyTimer').reschedule(time.ZonedDateTime.now().plusSeconds(1)); };
}
cache.private.remove('MyTimer');
}));
};
```
## Expected behavior
The output ends after the 2nd pass but should count to 10:
```
==> /var/log/openhab/openhab.log <==
2023-07-31 13:08:01.617 [INFO ] [nhab.automation.script.ui.a08104671c] - SCRIPT count
2023-07-31 13:08:02.619 [INFO ] [nhab.automation.script.ui.a08104671c] - 1
2023-07-31 13:08:03.620 [INFO ] [nhab.automation.script.ui.a08104671c] - 2
```
## Steps to reproduce
See Screenshot and code above.
## Your environment
runtimeInfo:
version: 4.0.0
buildString: Release Build
locale: de-DE
systemInfo:
configFolder: /etc/openhab
userdataFolder: /var/lib/openhab
logFolder: /var/log/openhab
javaVersion: 17.0.7
javaVendor: Raspbian
osName: Linux
osVersion: 6.1.21-v8+
osArchitecture: arm
availableProcessors: 4
freeMemory: 273486896
totalMemory: 766193664
startLevel: 100
bindings: null
clientInfo:
device:
ios: false
android: false
androidChrome: false
desktop: true
iphone: false
ipod: false
ipad: false
edge: false
ie: false
firefox: false
macos: false
windows: true
cordova: false
phonegap: false
electron: false
nwjs: false
webView: false
webview: false
standalone: false
os: windows
pixelRatio: 1.100000023841858
prefersColorScheme: dark
isSecureContext: false
locationbarVisible: true
menubarVisible: true
navigator:
cookieEnabled: true
deviceMemory: N/A
hardwareConcurrency: 16
language: de
languages:
- de
onLine: true
platform: Win32
screen:
width: 1920
height: 1080
colorDepth: 24
support:
touch: false
pointerEvents: true
observer: true
passiveListener: true
gestures: false
intersectionObserver: true
themeOptions:
dark: dark
filled: true
pageTransitionAnimation: default
bars: light
homeNavbar: default
homeBackground: default
expandableCardAnimation: default
userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/115.0.0.0 Safari/537.36
timestamp: 2023-08-02T18:36:14.830Z
<!--
Provide any information not pertinent to the above sections that you'd still like to share.
-->
Dash
(Dash)
August 19, 2023, 10:38pm
3
First post is different as it’s OH3, which this worked fine for. But github issue looks bang on. Surprised this isn’t a common complaint.
JustinG
(JustinG)
August 19, 2023, 11:46pm
4
The last two posts in that thread are for OH4, including a workaround you can use until the fix is available.
2 Likes
Dash
(Dash)
August 20, 2023, 1:53pm
5
For anybody else stumbling, this is the fudge until it is fixed:
Create a function and drop your timer into that. Every time you use a reschedule, call the function instead.