Javascript script

  • Platform information:
    • Hardware: Intel, 16GB RAM
    • OS: Windows 10
    • Java Runtime Environment: Zulu newest LTS
    • openHAB version:
  • Issue of the topic:
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:


I would like to access openhab.variables in my Javascript script:


if (Staubsauger_Kueche == OFF) {
raum = 17;

But the state of the variable is not printed. Could you please help me to find the syntax errors?

Addion to that, is there somehow a documentation how to programm Javascript scripts in Openhab? I just found a very tiny one. Some examples would be great.

Thanks a lot in advance,

Welcome to the openHAB forum :wave:

Read This
The search functionon this forum could be your friend!

Nice, you helped me :slight_smile:

For example:
// Get the state of an Item"The state of ServiceStatuses is " + items.ServiceStatuses);

Thank you!

If I run the following Javascript script:


if (items.Staubsauger_Kueche == ON) {
  var raum = 17;

if (items.Staubsauger_Flur == ON) {
  var raum = raum + ',' + 18;

events.sendCommand(event.EZ_ExecuteCommand, "app_segment_clean[18]");  

I got following error:

23:54:52.508 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘443f42942a’ failed: ReferenceError: “event” is not defined in at line number 28

Does someone have a hint for me to fix the error?

event only exists when the rule is triggered by an Item event. If it was triggered manually (by pressing the play button), from another rule, or via a time based trigger.

And it appears you are misusing event here. To send a command to an Item, pass the name of the Item as a String.

events.sendCommand("EZ_ExecuteCommand", "app_segment_clean[18]");