Jump to content

Example script: virtual component with HuE Light-Bulb


T.E.

Recommended Posts

  • Members

Thought a good start would be a very minimalistic script .. it is a boolean swtich to control a HuE Light Bulb via HuE-Bridge. to keep it simple currently just on and off.

image.png.55400402bc88b2450d850b9ca890697d.png
 

// CONFIG START
let CONFIG = {
    ip: '192.168.178.168', //Hue Bridge IP
    user: 'Y0NXhTgbfcZYk0dSrTB70Va0XSZKFJdUYJcAj4bp', //Hue Bridge API user
    light: '4', // Hue Light ID
    input1: 200, // Shelly virtual switch ID
};

Shelly.addStatusHandler(function (e) {
    if (e.delta.id === CONFIG.input1 && e.delta.value === false) {
        Toggle("false");
    } else {
        Toggle("true");
    }
});

function Toggle(state) {
    let b = '{"on": ' + state + '}';
    Shelly.call(
        "http.request", {
        method: "PUT",
        url: 'http://' + CONFIG.ip + '/api/' + CONFIG.user + '/lights/' + CONFIG.light + '/state',
        body: b
    },
        function (r, e, m) {},
        null
    );
}

function CheckBridgeState() {
    Timer.set(1000, true, function () {
        Shelly.call(
            "http.request", {
            method: "GET",
            url: 'http://' + CONFIG.ip + '/api/' + CONFIG.user + '/lights/' + CONFIG.light,
        },
            function (res, error_code, error_message, ud) {
                let st = JSON.parse(res.body);

                if (st.state.on === true) {
                    Shelly.call("boolean.set", { id: CONFIG.input1, value: true });
                } else {
                    Shelly.call("boolean.set", { id: CONFIG.input1, value: false });
                }
            },
            null
        );

    }, null);
}
CheckBridgeState();

 

  • Like 2
Link to comment
Share on other sites

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...