I created a rule to turn on a light when motion is detected and turn off when no motion detected for 3 minutes.
The rule is triggered by the motion sensor changing to ON:
the issue is that when the “else if” condition is met for the first time the timer is rescheduled, but the second time it’s not.
Is this a “feature” of the reschedule block or there is an issue?
thanks
rlkoshak
(Rich Koshak)
November 25, 2021, 2:59pm
2
Errors in the log?
Add some logging blocks to see what the states of those two items are every time the timer block runs. Are you sure the else if it’s running?
Hi Rich,
the behavior I experience is the following:
If I stay in the room for less than 5 minutes (I tested 4.5 minutes) and the I exit, the light turns off.
If I stay in the room for more than 5 minutes and then exit, the light never turns off.
Consider also that the motion sensor has a 60 seconds “cooldown” after being triggered, and if motion is detected when it’s already ON, there is no change in the item state.
I will add some logging blocks to try to pinpoint the issue and post them here.
I modified the script as follows:
the relevant logs:
2021-11-25 18:53:12.398 [INFO ] [org.openhab.rule.b7323e80df ] - timer start
2021-11-25 18:56:12.413 [INFO ] [org.openhab.rule.b7323e80df ] - Timer finished
2021-11-25 18:56:12.527 [INFO ] [org.openhab.rule.b7323e80df ] - Else if condition met > reschedule
2021-11-25 18:59:12.502 [INFO ] [org.openhab.rule.b7323e80df ] - Timer finished
2021-11-25 18:59:12.551 [INFO ] [org.openhab.rule.b7323e80df ] - Else if condition met > reschedule
After these nothing else is logged and the light is still on.
To me it seems that the reschedule block works only once, but I’m open to better ideas
rlkoshak
(Rich Koshak)
November 27, 2021, 3:59pm
5
IT does look like it should be rescheduling. My recommendation is to file an issue on the openhab-webui repo where more information will be requested and further trouble shooting steps can be taken.
Hi Rich,
I opened an issue here:
opened 08:58AM - 28 Nov 21 UTC
bug
main ui
## The problem
when using the "reschedule" block in a rule (script), the fir… st time the rule is triggered the timer is properly rescheduled, but the second time it’s not.
## Expected behavior
every time that the rule is triggered, it should reschedule the timer
## Steps to reproduce
Example:
I created a rule to turn on a light when motion is detected and turn off when no motion detected for 3 minutes.
The rule is triggered by the motion sensor changing to ON:
![image](https://user-images.githubusercontent.com/38229078/143735983-ce307f51-55c8-42d9-82fb-1caeb79d8dfb.png)
the behavior I experience is the following:
If I stay in the room for less than 5 minutes (I tested 4.5 minutes) and the I exit, the light turns off.
If I stay in the room for more than 5 minutes and then exit, the light never turns off.
Consider also that the motion sensor has a 60 seconds “cooldown” after being triggered, and if motion is detected when it’s already ON, there is no change in the item state.
Logs:
2021-11-25 18:53:12.398 [INFO ] [org.openhab.rule.b7323e80df ] - timer start
2021-11-25 18:56:12.413 [INFO ] [org.openhab.rule.b7323e80df ] - Timer finished
2021-11-25 18:56:12.527 [INFO ] [org.openhab.rule.b7323e80df ] - Else if condition met > reschedule
2021-11-25 18:59:12.502 [INFO ] [org.openhab.rule.b7323e80df ] - Timer finished
2021-11-25 18:59:12.551 [INFO ] [org.openhab.rule.b7323e80df ] - Else if condition met > reschedule
## Your environment
runtimeInfo:
version: 3.2.0.M4
buildString: Milestone Build
locale: en-IT
systemInfo:
configFolder: /etc/openhab
userdataFolder: /var/lib/openhab
logFolder: /var/log/openhab
javaVersion: 11.0.13
javaVendor: Azul Systems, Inc.
javaVendorVersion: Zulu11.52+13-CA
osName: Linux
osVersion: 5.10.63-v7+
osArchitecture: arm
availableProcessors: 4
freeMemory: 73255232
totalMemory: 195035136
bindings:
- airquality
- astro
- avmfritz
- chromecast
- mail
- mihome
- miio
- mqtt
- network
- openweathermap
- openwebnet
- sonoff
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.25
prefersColorScheme: light
isSecureContext: false
locationbarVisible: true
menubarVisible: true
navigator:
cookieEnabled: true
deviceMemory: N/A
hardwareConcurrency: 8
language: en-US
languages:
- en-US
- it-IT
- it
- en
onLine: true
platform: Win32
screen:
width: 1536
height: 864
colorDepth: 24
support:
touch: false
pointerEvents: true
observer: true
passiveListener: true
gestures: false
intersectionObserver: true
themeOptions:
dark: light
filled: true
pageTransitionAnimation: default
bars: filled
homeNavbar: default
homeBackground: default
expandableCardAnimation: default
userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/96.0.4664.27 Safari/537.36
timestamp: 2021-11-28T08:54:36.070Z
## Browser console
N/A
## Browser network traffic
N/A
## Additional information
Openhab thread:
https://community.openhab.org/t/script-with-blocky-reschedule-block-triggers-only-once/129190/4
hope it’s the right place
@enrico.mcc The issue has been fixed with 3.2.0. Do you mind adding [SOLVED] to the title here?
Sure, thanks for the fix!
alaub81
(Andreas)
August 18, 2023, 6:11pm
9
I think the problem is back again in openHAB 4. I tried to build the same rule as it is described in the documentation: Rules Blockly
here is my code:
var WarningRetry;
WarningRetry = 4;
console.warn('StarteTESTretry');
if (cache.private.exists('TESTTIMER') === false || cache.private.get('TESTTIMER').hasTerminated()) {
cache.private.put('TESTTIMER', actions.ScriptExecution.createTimer('TESTTIMER', time.ZonedDateTime.now().plusSeconds(5), function () {
console.warn((['Nach 5s ','Starting Retry: ',WarningRetry,''].join('')));
if (WarningRetry > 1) {
console.warn('in retry');
WarningRetry = (typeof WarningRetry === 'number' ? WarningRetry : 0) + -1;
if (cache.private.exists('TESTTIMER')) { cache.private.get('TESTTIMER').reschedule(time.ZonedDateTime.now().plusSeconds(5)); };
}
cache.private.remove('TESTTIMER');
}));
};
can someone verify, that it is not belonging to my Blockly rule? I am using openHAB 4.0.2
cheers
Andreas
rlkoshak
(Rich Koshak)
August 18, 2023, 6:19pm
10
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.private.exists('TESTTIMER') === false || cache.private.get('TESTTIMER').hasTerminated()) {
cache.private.put('TESTTIMER', actions.ScriptExecution.createTimer('TESTTIMER', time.ZonedDateTime.now().plusSeconds(5), function () {
console.warn((['Nach 5s ','Starting Retry: ',WarningRetry,''].join('')));
if (WarningRetry > 1) {
console.warn('in retry');
WarningRetry = (typeof WarningRetry === 'number' ? WarningRetry : 0) + -1;
if (cache.private.exists('TESTTIMER')) { cache.private.get('TESTTIMER').reschedule(time.ZonedDateTime.now().plusSeconds(5)); }
else { cache.private.remove('TESTTIMER');};
}
}));
};
1 Like
Rich, I yesterday browsed all issues with Blockly and I couldn’t find this issue. Do you know which one that is and ping @florian-h05 to assign this to me?
I unfortunately hadn’t had too much time to work on issues but I hope I can catch up shortly.
rlkoshak
(Rich Koshak)
August 20, 2023, 7:55pm
12
it’s poorly named but this is the one.
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:.
![image](https://github.com/openhab/openhab-webui/assets/75612866/f7fd0e1b-ec41-4e66-be86-fbf1f044ad07)
```
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.
-->
Any time the looping timer block is created the line to remove it from the cache gets added so that there isn’t a timer to reschedule the first time it runs.
1 Like
@florian-h05 can you assign it to me, pls?
Update: fixed, you may have a look at it and merge it.
thanks! will this fix be included in the next release/milestone?
Depends on when this being reviewed and merged but, yes, that’s the intention
1 Like