milo
(M)
October 6, 2026, 7:57am
1
Hi all,
I’m running openHAB 5.3M1 with the JavaScript Scripting add-on (openhab-js).
When I create a scene in Main UI, the code tab looks like this:
items:
Rollershutter_GF_Diningroom_WindowCoveringOne: "100"
Rollershutter_GF_Bedroom_WindowCoveringOne: "100"
triggers: []
conditions: []
I’d like to define the same scene in a file under /etc/openhab/automation/js/ instead. My attempt:
const { items, rules, log } = require('openhab');
rules.JSRule({
name: 'Szene Schlafen',
triggers: [],
tags: ['Scene'],
id: 'szene_schlafen',
execute: (event) => {
items.Rollershutter_GF_Diningroom_WindowCoveringOne.sendCommand('100');
items.Rollershutter_GF_Bedroom_WindowCoveringOne.sendCommand('100');
}
});
Result:
It looks like this
items:[]
triggers: []
conditions: []
Questions:
What is the correct syntax to create a scene from a JS file so it behaves like a UI scene (ideally with the item/state list visible in the scene editor)?
Thanks!
It’s not possible to do this from JSR223 languages without using a lot of openHAB Core Java APIs directly.
Scenes are just a standard rule with the Scene tag attached and several core.ItemCommandActions specified. JSR223 languages like JS use a single core.ScriptAction for code execution.
You should however be able to define a Scene from a YAML file like this:
version: 1
rules:
Diner:
label: Diner at Living Room
tags:
- Scene
description: "Setup lights, increase temperature, turn on AV receiver, set input & volume"
actions:
- id: "1"
config:
command: "30"
itemName: LivingRoom_CeilingLight
type: SendCommand
- id: "2"
config:
command: "60,0,100"
itemName: LivingRoom_FloorLamp
type: SendCommand
- id: "6"
config:
command: 21 °C
itemName: LivingRoom_HVAC_TemperatureSet
type: SendCommand
- id: "3"
config:
command: "ON"
itemName: LivingRoom_Receiver_Power
type: SendCommand
- id: "4"
config:
command: Server
itemName: LivingRoom_Receiver_Input
type: SendCommand
- id: "5"
config:
command: 25 %
itemName: LivingRoom_Receiver_Volume
type: SendCommand
milo
(M)
October 6, 2026, 10:00am
3
where do i need to store it?