This is a repository of very experimental JavaScript code that can be used with the SmartHome platform and openHAB 2.x.
The JSR223 scripting extensions can be used for general scripting purposes, including defining rules with JavaScript Code for openHAB 2 JSR223 Scripting.
Copy Files into /etc/openhab2/automation/jsr223
OpenHAB 2 JSR223 Scripting Documentation: JSR223 Scripting and Rule Support.
Further links and information: openHAB 1 Scripted Rule Support.
Simplified with some extra JavaScript Code, found in jslib/JSRule.js
:
'use strict';
load('/etc/openhab2/automation/jsr223/jslib/JSRule.js');
JSRule({
name: "My JS Rule",
description: "Line:"+__LINE__,
triggers: [
TimerTrigger("0/15 * * * * ?")//Enable/Disable Rule
],
execute: function( module, input){
print("################ module:", module);
postUpdate(getItem("testItemSwitch"), ON);
sendCommand(getItem("testItemSwitch"), OFF);
}
});
jslib/helper.js
contains more simplifying and helping functions.
jslib/PersistenceExtensions.js
contains more simplifying PersistenceExtensions functions.
jslib/triggersAndConditions.js
contains trigger functions.
ActionExamples.js
contains examples for default actions like PersistenceExtensions, HTTP, Ping, Audio, Voice, ThingAction.
itemTest.js
contains examples for testing Items and Groups.