I had a strange issue with a number of my rules, after upgrading to OH 5.1.3. I upgraded on 25 Feb, and everything ran fine for a few days, but on Feb 27th, I started getting a errors for some JS Scripts (Main UI based) - 3 different rules.
- No changes were made to the rules
- They did work prior to the 5.1.3 upgrade (have scanned older logs, and no related errors)
- They also did work for 2 days following the 5.1.3 upgrade/restart of OpenHAB
- Also checked APT logs - No updates made to system (e.g. Java version), since 5.1.3 upgrade
A restart of OpenHAB has resolved the issue, but as it appears to be transient, am posting here in case anyone else sees a similar issue, and a pattern is emerging.
I only could find one similar error mentioned back in 2022 ECMAScript 2021+ rule-based scripts fail when using cache.get(): The Context is already closed , where the user resolved by re-saving rules (And perhaps my restart did the same effect).
First, the environment:
runtimeInfo:
version: 5.1.3
buildString: Release Build
locale: en-NZ
systemInfo:
configFolder: /etc/openhab
userdataFolder: /var/lib/openhab
logFolder: /var/log/openhab
javaVersion: 21.0.10
javaVendor: Azul Systems, Inc.
javaVendorVersion: Zulu21.48+17-CA
osName: Linux
osVersion: 6.17.0-14-generic
osArchitecture: amd64
availableProcessors: 16
freeMemory: 1753354080
totalMemory: 2147483648
uptime: 399
startLevel: 100
addons:
- automation-jsscripting
- binding-amazonechocontrol
- binding-astro
- binding-cbus
- binding-chromecast
- binding-daikin
- binding-denonmarantz
- binding-exec
- binding-fineoffsetweatherstation
- binding-gpstracker
- binding-heos
- binding-http
- binding-icalendar
- binding-ipcamera
- binding-ipobserver
- binding-logreader
- binding-modbus
- binding-mqtt
- binding-network
- binding-ntp
- binding-onkyo
- binding-opensprinkler
- binding-openweathermap
- binding-samsungtv
- binding-serial
- binding-snmp
- binding-solarforecast
- binding-spotify
- binding-systeminfo
- binding-tuya
- binding-unifi
- misc-openhabcloud
- persistence-influxdb
- transformation-bin2json
- transformation-exec
- transformation-jsonpath
- transformation-map
- transformation-regex
- transformation-rollershutterposition
- transformation-scale
- transformation-xpath
- transformation-xslt
- ui-basic
- ui-habpanel
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: false
cordova: false
electron: false
capacitor: false
nwjs: false
webView: false
webview: false
standalone: false
pixelRatio: 1.25
prefersColorScheme: dark
isSecureContext: true
locationbarVisible: true
menubarVisible: true
navigator:
cookieEnabled: true
deviceMemory: 8
hardwareConcurrency: 16
language: en-NZ
languages:
- en-NZ
- en-GB
- en-US
- en
onLine: true
platform: Linux x86_64
screen:
width: 3072
height: 1728
colorDepth: 24
support:
touch: false
pointerEvents: true
passiveListener: true
intersectionObserver: true
themeOptions:
dark: dark
autoDarkMode: true
bars: light
homeNavBar: default
homeBackground: default
disableExpandableCardAnimation: false
blocklyRenderer: null
disablePageTransitionAnimation: false
hideChatInput: false
webAudio: false
visibleBreakpointDisabled: true
userAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/145.0.0.0 Safari/537.36
timestamp: 2026-03-03T18:34:58.177Z
And it looks like I am running OpenHAB Rules Tools 2.0.3 (Using TimerMgr)
Secondly the errors:
2026-02-27 10:01:56.971 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'depart_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 15:52:25.314 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 15:52:25.316 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 15:52:25.317 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 20:29:42.000 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'depart_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 20:29:42.003 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'depart_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 20:29:42.006 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'depart_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 21:52:39.050 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 21:53:34.235 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 21:53:34.237 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 21:53:34.238 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 21:54:35.275 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 21:54:36.540 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 21:54:45.741 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-27 21:54:47.003 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-28 17:30:46.589 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-02-28 17:31:37.965 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-01 00:52:20.094 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-01 01:03:31.273 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-01 15:05:00.100 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-01 15:09:34.720 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-01 17:45:19.992 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-01 17:46:58.214 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-02 07:13:25.482 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'depart_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-02 07:13:25.484 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'depart_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-02 07:13:25.487 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'depart_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-02 17:36:59.972 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-02 17:36:59.974 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-02 17:36:59.975 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-02 19:21:17.086 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 07:00:19.609 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'depart_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 07:00:19.611 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'depart_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 07:00:19.613 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'depart_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 17:39:05.086 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 17:39:05.087 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 17:39:05.088 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 19:15:02.287 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 19:28:56.456 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 19:28:58.429 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 19:49:24.015 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'depart_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 22:28:48.143 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 22:28:48.145 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 22:28:48.146 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'arrive_house_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 22:54:58.218 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 23:20:46.460 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-03 23:20:46.461 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-04 07:27:28.036 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
2026-03-04 07:27:30.796 [ERROR] [.handler.AbstractScriptModuleHandler] - Script execution of rule with UID 'gate_force_control' failed: java.lang.IllegalStateException: The Context is already closed.
And lastly, the scripts called out in the above errors:
gate_force_control:
configuration: {}
triggers:
- id: "1"
configuration:
itemName: Gate_Open_force
type: core.ItemStateChangeTrigger
- id: "3"
configuration:
itemName: Gate_ButtonLights_force
type: core.ItemStateChangeTrigger
- id: "4"
configuration:
itemName: Gate_Lights_force
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: >-
if(event.itemName != undefined)
{
//Stops script from running if triggered via OpenHAB console - Event
would be undefined, and fail
var {TimerMgr} = require('openhab_rules_tools');
var timers = cache.shared.get('gate_tm', () => TimerMgr());
triggeringItem = items[event.itemName].name
if(triggeringItem.indexOf("_force") === (triggeringItem.length()-6))
{
otherItem = triggeringItem.substring(0,triggeringItem.length()-6)
}
else
{
otherItem = triggeringItem + "_force"
}
if (items[otherItem].state != items[triggeringItem].state) {
console.log("Gate Force Rule Running - Triggered by",triggeringItem,"- Changing item state for",otherItem,"to",items[triggeringItem].state);
items[otherItem].sendCommand(items[triggeringItem].state);
timers.check(otherItem+"_off_tm",0,null,false,null,otherItem+"_off_tm");
}
if((triggeringItem === "Gate_Open_force") && (items["Daylight"].state === "OFF") && (items["Gate_Open_force"].state === "ON"))
{
items["Gate_Lights_force"].sendCommandIfDifferent("ON");
items["Gate_ButtonLights_force"].sendCommandIfDifferent("ON");
console.log("Gate Force Rule - Turning on force lights");
}
if((triggeringItem === "Gate_Open_force") && (items["Gate_Open_force"].state === "OFF"))
{
items["Gate_Lights_force"].sendCommandIfDifferent("OFF");
items["Gate_ButtonLights_force"].sendCommandIfDifferent("OFF");
console.log("Gate Force Rule - Turning off force lights");
}
}
type: script.ScriptAction
arrive_house_control:
configuration: {}
triggers:
- id: "1"
configuration:
itemName: ZelioAlarmArmed
previousState: ON
state: OFF
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
label: PIR Enable Scene
description: Run Arrive House - PIR Enable Scene
configuration:
considerConditions: false
ruleUIDs:
- arrive_house_PIR_enable
type: core.RunRuleAction
- inputs: {}
id: "3"
label: Un-Dim cBUS Key Switches Scene
description: Run Arrive House = UnDim CBUS Key Switches Scene
configuration:
considerConditions: false
ruleUIDs:
- arriveHouse_unDimCBUSKeySwitches
type: core.RunRuleAction
- inputs: {}
id: "4"
label: Arrive House - Close Gate
description: Set a timer for auto-closure of the gate
configuration:
type: application/javascript
script: |-
// This rule is used to set a timer to auto close the gate, when Arriving at the house (Alarm is Unset)
// Remember that the Gate Controller itself has a Open timer, so unless its configured open duration has already been exceeded, releasing
// the gate item may not result in immediate closure of the gate
// The gate 'force' item is also set to off
var {TimerMgr} = require('openhab_rules_tools');
var timers = cache.shared.get('gate_tm', () => TimerMgr());
itemName = "Gate_Open";
force_itemName = "Gate_Open_force";
duration_itemName = "ArriveHouse_GateCloseDuration";
duration = Number(items[duration_itemName].state);
var tmexpire = function(iname,forceiname) {
return () => {
items[iname].sendCommandIfDifferent("OFF");
items[forceiname].sendCommandIfDifferent("OFF");
};
}
schedtime = time.ZonedDateTime.now().plusSeconds(duration);
timers.check(itemName+"_off_tm",schedtime.toString(),tmexpire(itemName,force_itemName),true,null,itemName+"_off_tm");
type: script.ScriptAction
- inputs: {}
id: "5"
label: Arrive House - Gate Garden Lights
description: Turn off Gate Garden Lights if not Daylight, when arriving at house
(Alarm Un-Set)
configuration:
type: application/javascript
script: |-
// This rule is used to set a timer to auto turn off the Gate Garden Lights, when Arriving at the house (Alarm is Unset)
// The gate garden light 'force' item is also set to off
// Just bear in mind the Gate Force Rule may also turn off the lights when the Gate force is released
var {TimerMgr} = require('openhab_rules_tools');
var timers = cache.shared.get('gate_tm', () => TimerMgr());
itemName = "Gate_Lights";
force_itemName = "Gate_Lights_force";
duration_itemName = "ArriveHouse_GateGardenLightDuration";
duration = Number(items[duration_itemName].state);
var tmexpire = function(iname,forceiname) {
return () => {
items[iname].sendCommandIfDifferent("OFF");
items[forceiname].sendCommandIfDifferent("OFF");
};
}
schedtime = time.ZonedDateTime.now().plusSeconds(duration);
timers.check(itemName+"_off_tm",schedtime.toString(),tmexpire(itemName,force_itemName),true,null,itemName+"_off_tm");
type: script.ScriptAction
- inputs: {}
id: "6"
label: Arrive House - Gate Button Lights
description: Turn off Gate Button Lights if not Daylight, when arriving at house
(Alarm Un-Set)
configuration:
type: application/javascript
script: |-
// This rule is used to set a timer to auto turn off the Gate Button Lights, when Arriving at the house (Alarm is Unset)
// The gate button light 'force' item is also set to off
// Just bear in mind the Gate Force Rule may also turn off the lights when the Gate force is released
var {TimerMgr} = require('openhab_rules_tools');
var timers = cache.shared.get('gate_tm', () => TimerMgr());
itemName = "Gate_ButtonLights";
force_itemName = "Gate_ButtonLights_force";
duration_itemName = "ArriveHouse_GateButtonLightDuration";
duration = Number(items[duration_itemName].state);
var tmexpire = function(iname,forceiname) {
return () => {
items[iname].sendCommandIfDifferent("OFF");
items[forceiname].sendCommandIfDifferent("OFF");
};
}
schedtime = time.ZonedDateTime.now().plusSeconds(duration);
timers.check(itemName+"_off_tm",schedtime.toString(),tmexpire(itemName,force_itemName),true,null,itemName+"_off_tm");
type: script.ScriptAction
depart_house_control:
configuration: {}
triggers:
- id: "1"
configuration:
itemName: ZelioAlarmArmed
previousState: OFF
state: ON
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
label: Dim cBUS Key Switches Scene
description: Run Depart House - Dim cBUS Key Switches Scene
configuration:
considerConditions: false
ruleUIDs:
- departHouse_DimCBUSKeySwitches
type: core.RunRuleAction
- inputs: {}
id: "3"
label: Turn off loads Scene
description: Run Depart House - Turn off loads Scene
configuration:
considerConditions: false
ruleUIDs:
- depart_house_loads
type: core.RunRuleAction
- inputs: {}
id: "4"
label: PIR Disable Scene
description: Run Depart House - PIR Disable Scene
configuration:
considerConditions: false
ruleUIDs:
- depart_house_PIR_disable
type: core.RunRuleAction
- inputs: {}
id: "5"
label: Depart House - Gate Button Lights
description: Turn on Gate Button Lights if not Daylight, when departing house
(Alarm Set)
configuration:
type: application/javascript
script: >-
// This rule is used to turn on the Gate Button Lights and set a timer
// This will only turn on the button lights if night time (Astro managed
item)
// This version runs upon Departing the house (Alarm Set)
var {TimerMgr} = require('openhab_rules_tools');
var timers = cache.shared.get('gate_tm', () => TimerMgr());
itemName = "Gate_ButtonLights";
force_itemName = "Gate_ButtonLights_force";
duration_itemName = "DepartHouse_GateButtonLightDuration";
duration = Number(items[duration_itemName].state);
var tmexpire = function(iname,forceiname) {
return () => {
items[iname].sendCommandIfDifferent("OFF");
};
}
if(items["Daylight"].state === "OFF")
{
schedtime = time.ZonedDateTime.now().plusSeconds(duration);
items[itemName].sendCommandIfDifferent("ON");
timers.check(itemName+"_off_tm",schedtime.toString(),tmexpire(itemName,force_itemName),true,null,itemName+"_off_tm");
}
type: script.ScriptAction
- inputs: {}
id: "6"
label: Depart House - Gate Garden Lights
description: Turn on Gate Garden Lights if not Daylight, when departing house
(Alarm Set)
configuration:
type: application/javascript
script: >-
// This rule is used to turn on the Gate Garden Lights and set a timer
// This will only turn on the garden lights if night time (Astro managed
item)
// This version runs upon Departing the house (Alarm Set)
var {TimerMgr} = require('openhab_rules_tools');
var timers = cache.shared.get('gate_tm', () => TimerMgr());
itemName = "Gate_Lights";
force_itemName = "Gate_Lights_force";
duration_itemName = "DepartHouse_GateGardenLightDuration";
duration = Number(items[duration_itemName].state);
var tmexpire = function(iname,forceiname) {
return () => {
items[iname].sendCommandIfDifferent("OFF");
};
}
if(items["Daylight"].state === "OFF")
{
schedtime = time.ZonedDateTime.now().plusSeconds(duration);
items[itemName].sendCommandIfDifferent("ON");
timers.check(itemName+"_off_tm",schedtime.toString(),tmexpire(itemName,force_itemName),true,null,itemName+"_off_tm");
}
type: script.ScriptAction
- inputs: {}
id: "7"
label: Depart House - Gate Open
description: Open the gate when departing the house, and set a timer for auto-closure
configuration:
type: application/javascript
script: |-
// This rule is used to turn open the Gate and set a timer to auto close the gate, when the house is 'Departed' (Alarm is Set)
// Remember that the Gate Controller itself has a Open timer, so unless its configured open duration has already been exceeded, releasing
// the gate item may not result in immediate closure of the gate
// The gate 'force' item is also set to off
var {TimerMgr} = require('openhab_rules_tools');
var timers = cache.shared.get('gate_tm', () => TimerMgr());
console.info("Opening Gate Rule running")
itemName = "Gate_Open";
force_itemName = "Gate_Open_force";
duration_itemName = "DepartHouse_GateCloseDuration";
duration = Number(items[duration_itemName].state);
var tmexpire = function(iname,forceiname) {
return () => {
items[iname].sendCommandIfDifferent("OFF");
items[forceiname].sendCommandIfDifferent("OFF");
};
}
schedtime = time.ZonedDateTime.now().plusSeconds(duration);
items[itemName].sendCommandIfDifferent("ON");
timers.check(itemName+"_off_tm",schedtime.toString(),tmexpire(itemName,force_itemName),true,null,itemName+"_off_tm");
type: script.ScriptAction
Again, for now, a restart resolved the issue, but just keen to see if anyone has experienced a similar issue recently (Or maybe I am doing something dumb in the above scripts, which I ‘got away’ with’ in previous versions, and less so now !!)
Cheers