Jump to content
⚠️ Deprecation Notice: Cloud Control API V1 – Switch to V2 ×

Recommended Posts

  • Members
Posted

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();

 

  • 10 months later...
Posted

Hello

Made simple example to boolean switch too

let CONFIG = {
  RelayNumber: [0,2],  // [0,1,2] List here relays that are controlled with this script. Shelly relay numbering starts from 0.
  input1: "boolean:200",       // Shelly virtual switch ID

};
 
Shelly.addStatusHandler(
  function(event) {
    if(event.component === CONFIG.input1 ) {
      if(event.delta.value === true) {
        ToggleOutput("true");
      }
      if(event.delta.value === false) {
        ToggleOutput("false");
      }
    }
  },
  null
);

function ToggleOutput(state) {
  if(state === "true" || state === "false") {
    for (let i = 0; i < CONFIG.RelayNumber.length; i++) {
      Shelly.call( "Switch.Set", "{ id:" + CONFIG.RelayNumber[i] + ", on:" + state + "}, null, null" );
    }
  }
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...