Hi, everyone.
I’m running OH 4.3.1 on a Raspberry Pi (CENTOS 9). I’m migrating my rules to JavaScript (ECMAScript 2022+), and I’m having an issue with my own library. I use text-based configuration.
I have created a library called “lights“ and installed it via npm under /etc/openhab/automation/js/node_modules/lights with the name index.js
This is the relevant part of the library’s code that I’m trying to test:
/*
Version: 1.0
*/
// remove namespaces that are not needed by your code
//const { actions, cache, items, things, time, triggers, utils, Quantity } = require('openhab');
const { items } = require('openhab');
const { HSBType, DecimalType, PercentType, ON, OFF} = require('@runtime');
/**
* @note Changes the color of the lights in the requested room to yellow light study mode
* @param roomName: The code of the room to be updated (e.g. LR, MBR, KT, etc.)
*/
function setYellowLightStudyScene(roomName) {
console.info("Lights Library > Set Yellow Light Study Scene > STARTING.")
var group_lights_color = items.getItem("group_%s_Lamp_1_Color", roomName)
if (group_lights_color != null) {
console.info("Lights Library > Set Yellow Light Study Scene > Color lights found.")
console.info("Lights Library > Set Yellow Light Study Scene > Updating light color")
group_lights_color.sendCommand(new HSBType(new DecimalType(38), new PercentType(54), new PercentType(100)))
} else {
console.info("Lights Library > Set Yellow Light Study Scene > Cannot find the group_%s_Lamp_1_Color. Trying with Ambiance lights.", roomName)
console.info("Lights Library > Searching for group_%s_Lamp_1_Brightness and group_%s_Lamp_1_ColorTemperature", roomName, roomName)
var group_lights_brightness = items.getItem("group_%s_Lamp_1__Brightness", roomName)
var group_lights_colorTemperature = items.getItem("group_%s_Lamp_1_ColorTemperature", roomName)
if (group_lights_brightness != null && group_lights_colorTemperature != null) {
console.info("Lights Library > Set Yellow Light Study Scene > Ambiance lights found. Updating the color of the lights to yellow")
group_lights_brightness.sendCommand(100)
group_lights_colorTemperature.sendCommand(100)
} else {
console.error("Lights Library > Set Yellow Light Study Scene > Cannot find the ambiance light items either. No lights were updated.")
}
}
console.info("Lights Library > Set Yellow Light Study Scene > ENDING.")
}
I’m testing it using the Scratchpad with the following code:
var Lights = require('lights')
Lights.setYellowLightStudyScene("MBR")
Here is the item configuration:
Group:Color group_MBR_Lamp_1_Color "Master Bedroom Lamp Color" <light> (group_MBR_Lamp_1, group_Lights_Color) ["Setpoint"]
Group:Dimmer group_MBR_Lamp_1_ColorTemperature "Master Bedroom Color Temperature" <light> (group_MBR_Lamp_1) ["Setpoint", "ColorTemperature"]
This is the outcome:
03/15/2026 07:57:55.632 [INFO ] [openhab.event.RuleUpdatedEvent ] - Rule 'scratchpad' has been updated.
03/15/2026 07:57:57.332 [WARN ] [tion.openhab-js.items.ItemPersistence] - RiemannType is not available on your openHAB version!
03/15/2026 07:58:02.487 [INFO ] [enhab.automation.script.ui.scratchpad] - 2026-03-15T07:58:02.485+01:00[Europe/Berlin]
03/15/2026 07:58:02.493 [INFO ] [enhab.automation.script.ui.scratchpad] - Lights Library > Set Yellow Light Study Scene > STARTING.
03/15/2026 07:58:02.498 [INFO ] [enhab.automation.script.ui.scratchpad] - Item: null
03/15/2026 07:58:02.503 [INFO ] [enhab.automation.script.ui.scratchpad] - Lights Library > Set Yellow Light Study Scene > Cannot find the group_MBR_Lamp_1_Color. Trying with Ambiance lights.
03/15/2026 07:58:02.508 [INFO ] [enhab.automation.script.ui.scratchpad] - Lights Library > Searching for group_MBR_Lamp_1_Brightness and group_MBR_Lamp_1_ColorTemperature
03/15/2026 07:58:02.513 [ERROR] [enhab.automation.script.ui.scratchpad] - Lights Library > Set Yellow Light Study Scene > Cannot find the ambiance light items either. No lights were updated.
03/15/2026 07:58:02.517 [INFO ] [enhab.automation.script.ui.scratchpad] - Lights Library > Set Yellow Light Study Scene > ENDING.
03/15/2026 07:58:02.521 [INFO ] [enhab.automation.script.ui.scratchpad] - Ending
Running the library’s code in the Scratchpad works, but calling the library with the same code doesn’t. It doesn’t work with or without the OH JS library call.
const { items } = require('openhab');
Am I missing something?







