ALLTERCO / shelly-script-examples

Shelly Scripts for Gen2 Shelly devices
Apache License 2.0
199 stars 55 forks source link

Delay switching off #1

Open antatta opened 2 years ago

antatta commented 2 years ago

On the Shelly 1 plus, a script to switch on relay at the first push of the button and at the second push of the button delay the switching off of the relay after 60 seconds. How to do that?

enesbcs commented 2 years ago

I guess it can be achieved using Detached button mode. Button press can be detected using "NotifyEvent" component "input:0". it has an event parameter which contains "single_push", "btn_up" etc: {"component":"input:0", "id":0, "event":"btn_up", "ts":1656519297.38}]} This kind of event handler can be found in this file: https://github.com/ALLTERCO/shelly-script-examples/blob/main/activation-switch.js

This line switches the relay, this is the place where you have to implement some sort of logic and a timer. Shelly.call("Switch.Set", swParams);