-
Notifications
You must be signed in to change notification settings - Fork 781
Scripted Rule Support
While there is no proper documentation yet available, I though it's a good idea to collect some knowledge here as a start.
Further readings with much more advanced examples:
https://github.com/smerschjohann/docker-oh2-jsr223 https://github.com/lewie/openhab2-javascript
This is how I got the scripted rule support running within the IDE.
Include the following bundles in the launch config:
org.eclipse.smarthome.automation.module.core
org.eclipse.smarthome.automation.api
org.eclipse.smarthome.automation.provider.file
org.eclipse.smarthome.automation.rest
org.eclipse.smarthome.automation.module.script.rulesupport
org.eclipse.smarthome.automation.module.timer
org.eclipse.smarthome.automation.providers
org.eclipse.smarthome.automation.parser.gson
org.eclipse.smarthome.automation.core
org.eclipse.smarthome.automation.module.script
Add this as a VM argument in the launch config:
-Dorg.osgi.framework.bundle.parent=ext
Scripts are searched for in conf/automation/jsr223
.
The following example.js
worked for me:
'use strict';
scriptExtension.importPreset("RuleSupport")
scriptExtension.importPreset("RuleSimple")
var sRule = new SimpleRule(){
execute: function( module, input){
print("Hello World from JavaScript");
}
};
sRule.setTriggers([
new Trigger(
"aTimerTrigger",
"timer.GenericCronTrigger",
new Configuration({
"cronExpression": "0/15 * * * * ?"
})
)
]);
automationManager.addRule(sRule);
Download jython-standalone-x.y.z.jar from http://www.jython.org/downloads.html
Add this library to the "Bootstrap entries" on the main page of the launch config by simply putting it's full path there.
The following example.py
worked for me:
scriptExtension.importPreset("RuleSupport")
scriptExtension.importPreset("RuleSimple")
class myRule(SimpleRule):
def execute(self, module, inputs):
print "Hello World from Jython"
sRule = myRule()
sRule.setTriggers([Trigger("aTimerTrigger", "timer.GenericCronTrigger", Configuration({"cronExpression": "0/15 * * * * ?"}))])
automationManager.addRule(sRule)