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