shelly-script-examples icon indicating copy to clipboard operation
shelly-script-examples copied to clipboard

debounce options for event handler

Open BadgerBadgerAndFox opened this issue 1 year ago • 0 comments

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

BadgerBadgerAndFox avatar Jul 10 '23 23:07 BadgerBadgerAndFox