Rule always fires despite Condition Script in Place

Hey all,

I am on OpenHab 5.1.1 and have a JavaScript Condition Script for one of my rules in place to ensure that the rule is only triggered between dusk and dawn. I’m using ECMA 262 Edition 11.

var dusk = items.getItem('LocalSun_CivilDusk_Start');
var dawn = items.getItem('LocalSun_CivilDawn_End');
var runRule = time.toZDT().isBetweenTimes(dusk, dawn);
console.log('Is now between dusk and dawn? ' + runRule);
runRule

I see the correct log lines, yet the rule fires. Any ideas why?

2026-01-13 11:30:19.168 [INFO ] [tomation.jsscripting.rule.85e2839641] - Is now between dusk and dawn? false

It seems this stopped working upgrading from OpenHab 4 to 5, cause the rule did not cause any issues before.

Thanks,
Flo

5.1 JS introduced a wrapper around Script conditions. This lets you use const, let, and return in script actions and script conditions.

There is a setting under Settings → JavaScript Scripting to disable the wrapper for script actions. But by default the wrapper is always enabled for script conditions. So you have two options:

  1. use return runRule;
  2. add a directive to the top of the script condition to disable the wrapper.

See JavaScript Scripting - Automation | openHAB for details.

Thanks, I’ll try the explicit method then. However, as far as I understand, implicit should still work, correct? (Despite not being recommended anymore.)

Yes but only if you add the directive to turn off the wrapper. One-way-or-the-other you’ll have to edit the script condition. May as well just add the return

Got it, I assumed that the wrapper is disabled by default. So yeah, let’s make it explicit anyways.