Today, following a rare memory issue (several OutOfMemoryErrors in the log), I did the typical stop/clean-cache/start/restart cycle to recover. I bet it has been over a year since I had a memory issue, so quite rare. That’s not the topic I’m posting about.
I’m posting because the JavaScript rule that reads metadata (code below) was coming back undefined. The metadata was right there in REST API, no apparent problem. Not knowing what else to try, I copied (ctrl-C copied) the metadata, deleted it, then recreated it all through REST API. Low and behold, my rules read the metadata just as before the memory error.
Thoughts about a better way to recover than deleting/recreating the metadata?
FWIW: I’m one of those who have to reinstall the NGRE binding every time I restart openHAB. Sure hope that is fixed when 3.0 rolls out!
Thanks.
- Platform information:
- Hardware: amd64/16G RAM/500G Storage
- OS: Debian GNU/Linux 10 (buster), Linux 4.19.0-6-amd64
- Java Runtime Environment: Zulu11.43+55-CA (build 11.0.9.1+1-LTS)
- openHAB version: openHAB 2.5.9-1
'use strict';
var OPENHAB_CONF = Java.type("java.lang.System").getenv("OPENHAB_CONF");
load(OPENHAB_CONF + '/automation/lib/javascript/core/osgi.js');
load(OPENHAB_CONF + '/automation/lib/javascript/core/rules.js');
load(OPENHAB_CONF + '/automation/lib/javascript/core/actions.js');
load(OPENHAB_CONF + '/automation/lib/javascript/core/utils.js');
var MetadataRegistry = get_service("org.eclipse.smarthome.core.items.MetadataRegistry");
var Metadata = Java.type("org.eclipse.smarthome.core.items.Metadata");
var MetadataKey = Java.type("org.eclipse.smarthome.core.items.MetadataKey");
JSRule({
name: "TOD_Lighting",
description: "Rule to update lighting based on TOD",
triggers: [
ItemStateChangeTrigger("vJSTimeOfDay")
],
execute: function(module, input){
//
var curTOD = getItem("vJSTimeOfDay").state;
// - cycle through gDimmers group and commands metadata for each TOD state
ir.getItem("gDimmers").members.forEach(function(dimmer) {
var testReadMetadata = MetadataRegistry.get(new MetadataKey("TOD",dimmer.name));
var metaToSend = testReadMetadata.configuration[curTOD];
// - skip if no metadata for the TOD
if (metaToSend==undefined) {
logInfo("JS Lighting: no metadata at " + curTOD + " for " + dimmer.name)
}
else {
logInfo("JS Lighting: sending metadata " + metaToSend + " to dimmer " + dimmer.name);
events.sendCommand(dimmer, metaToSend);
}
});
}
});