shelly-script-examples
shelly-script-examples copied to clipboard
debounce options for event handler
I have a magnetic reed switch that due to its mounting orientation results in the contact bouncing on activation.
How can i script a suppression for the event handler to debounce subsequent events for 2000ms so only the first (or last) event is published?
Shelly.addEventHandler(function (event) { if (event.name === "input" && event.id === 100 && event.info.state === true) { MQTT.publish("shellyplus1-a8032abd2900/doormoving", JSON.stringify(true), 0, false); } if (event.name === "input" && event.id === 0 && event.info.state === true) { MQTT.publish("shellyplus1-a8032abd2900/doormoving", JSON.stringify(true), 0, false); } if (event.name === "input" && event.id === 100 && event.info.state === false) { MQTT.publish("shellyplus1-a8032abd2900/doormoving", JSON.stringify(false), 0, false); } if (event.name === "input" && event.id === 0 && event.info.state === false) { MQTT.publish("shellyplus1-a8032abd2900/doormoving", JSON.stringify(false), 0, false); } });