This script replicates the activation_switch profile behavior from Shelly Gen1 devices using Shelly's scripting capabilities. It configures the switch to 'detached' mode and adds an event handler to manage button push events. The script ignores single and double push events, activating the switch with a user-defined timeout when the "btn_up" event is detected. Ideal for users looking to emulate Gen1 behavior on their Shelly devices, the script allows customization of toggle timeout and switch/input IDs.
// Shelly Script example: Replicate activation_switch profile
// Gen1 behavior replicated with scripting
let CONFIG = {
toggleTimeout: 5,
inputId: 0,
switchId: 0,
};
Shelly.call("Switch.SetConfig", {
id: CONFIG.switchId,
config: {
in_mode: "detached",
},
});
Shelly.addEventHandler(function (event) {
if (typeof event.info.event === "undefined") return;
if (event.info.component === "input:" + JSON.stringify(CONFIG.inputId)) {
//ignore single_push and double_push events
if (event.info.event.indexOf("push") >= 0) return;
let swParams = {
id: CONFIG.switchId,
on: true,
};
if (event.info.event === "btn_up") {
swParams.toggle_after = CONFIG.toggleTimeout;
}
Shelly.call("Switch.Set", swParams);
}
});