Hamlet
(Hamid Shoja)
July 31, 2023, 11:14am
1
after updating to OH4 the following script does not work 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');
}));
};
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
have I missed something?
rlkoshak
(Rich Koshak)
July 31, 2023, 3:11pm
2
This may be a regression. The problem is that last line cache.private.remove('MyTimer');
. Definitely file an issue. It might be tricky to fix though. It might require creating a separate looping timer block.
In the mean time, you can make this work through a slight adjustment.
Instead of a reschedule, create a new timer at the end of the if statement
Append the count
to the name of the timer
This will convert it from trying to reschdule to creating a new timer each time.
Hamlet
(Hamid Shoja)
August 2, 2023, 6:44pm
3
Thank you, I created an issue:
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.
-->
but i have not yet understood how to call the new timer with the count in the name. Can you please show me an example in blockly?
rlkoshak
(Rich Koshak)
August 2, 2023, 7:47pm
4
It’s just a string concatenation, nothing complicated.
I
system
(system)
Closed
September 13, 2023, 11:48am
5
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.