shelly-tools / shelly-script-examples

Shelly mJS Scripting examples
GNU Affero General Public License v3.0
72 stars 21 forks source link

Shelly script addEventHandler #3

Closed gobo-ws closed 2 years ago

gobo-ws commented 2 years ago

Thank you for the examples! Some parts of it helped me to create the following script:

let CONFIG = {
    hostname: '10.50.40.10:9090', // OLA hostname:port
    universe: '1', // Universe
    dmx: '255,255,255', // DMX values
    input1: 0, // Shelly Button ID (not in use yet)
};

Shelly.call(
    "http.request", {
    method: "POST",
    url: 'http://' + CONFIG.hostname + '/set_dmx',
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    body: 'u=' + CONFIG.universe + '&d=' + CONFIG.dmx
},
);

But I am still struggling how to run the script when a momentary switch is triggered (detached mode)
Can you please help me a little bit with the evenHandler part? Thanks in advance.

eurich commented 2 years ago

Should be like this for a single_push event..

possible events: single_push, double_push, long_push, btn_up, btn_down

Shelly.addEventHandler(
    function (event) {
        if (typeof event.info.event !== 'undefined') {
            if (event.info.event === 'single_push' && event.info.id === CONFIG.input1) {
                // Place your Shelly.Call here
            }
        } else {
            return true;
        }
    },
);
eurich commented 2 years ago

feel free to re-open the issue if you need further assistance.

gobo-ws commented 2 years ago

Many thanks @eurich!