Members T.E. Posted December 5, 2023 Members Posted December 5, 2023 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(); 3 Quote Translate Revert translation? English (American) French German Italian Polish Portuguese (European) Spanish
Dimitar Posted December 6, 2023 Posted December 6, 2023 very good, you can control brightness with num components, 0% can swhich them off, any > 0% can switch them on and set a brightness. 1 Quote Translate Revert translation? English (American) French German Italian Polish Portuguese (European) Spanish
ViX Posted October 11, 2024 Posted October 11, 2024 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" ); } } } Quote Translate Revert translation? English (American) French German Italian Polish Portuguese (European) Spanish
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.