Giter VIP home page Giter VIP logo

openhab2-javascript's Introduction

########################## IMPORTANT since 20190526 ##########################

This repository has moved. It is now maintained together with other openHAB helper libraries on openhab-scripters/openhab-helper-libraries.

The development of the different scripting languages for openHAB like

groovy
javascript
Jython (Python)
and many more...

will be combined and will later be an important part of the Next-Generation Rule Engine for openHAB.

########################## IMPORTANT since 20190526 ##########################

openHAB 2.x: JSR223 JavaScript Code since 2.4

This is a repository of very experimental JavaScript code that can be used with openHAB 2.x.

Applications

The JSR223 scripting extensions can be used for general scripting purposes, including defining rules with JavaScript Code for openHAB 2 JSR223 Scripting.

Installation

A) Copy Files into /etc/openhab2/automation/jsr223

B) Go to Paper UI -> Misc and install Binding "Rule Engine"

Defining Rules

Migrating DSL Rules to JSR223/Javascript with a case example

OpenHAB 2 JSR223 Scripting Documentation: JSR223 Scripting and Rule Support.

Further links and information: openHAB 1 Scripted Rule Support.

Rules: Raw ESH API

Simplified with some extra JavaScript Code, found in jslib/JSRule.js:

'use strict';

var OPENHAB_CONF = Java.type("java.lang.System").getenv("OPENHAB_CONF");
load(OPENHAB_CONF+'/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.

openhab2-javascript's People

Contributors

lewie avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.