Keep off the actions spam

i am trying to write a doorbell rule using my lame programming skills :slight_smile: .I use a xiaomi wireless switch for a doorbell button and when someone short/long/double press it i do things like its playing a sound at the xiaomi gateway and flashing a light,send me an email with a camera photo… etc.All good so far.The one thing i want to know is how can i set a delay at the presses so if an asshole keep spamming the button i wont be flowed by notifications and actions.

Should get you started.

Set the timer like in the example and in your rule that triggers when the door bell button is pressed put:

if(timer !== null) return;

Or if you use Expire based timers:

if(Doorbell_Timer.state == ON) return;

This will cause the Rule to ignore all events until the timer expires and goes away.

thanx mate this is so simple.I did it the hard way using a virtual switch who is triggered to on by the 3 xiaomi button actions and using expire goes to off after 30 seconds.Then i trigger my doorbell actions using that switch when change state from off to on.It works ok but your way is much nicer.i learned something today,Thank you.

Switch doorbell_switch "doorbell_switch" { expire="30s,command=OFF" }
rule "doorbell_switch"
when
        Channel "mihome:sensor_switch:158d0001d8f5d3:button" triggered SHORT_PRESSED
		or
		Channel "mihome:sensor_switch:158d0001d8f5d3:button" triggered DOUBLE_PRESSED
		or
		Channel "mihome:sensor_switch:158d0001d8f5d3:button" triggered LONG_RELEASED
	then
	    if(doorbell_switch.state==OFF) {
          doorbell_switch.sendCommand(ON)
		  }
end
rule "Doorbell"

   when
       Item doorbell_switch changed from OFF to ON

    then
	    if(Alarm_State.state==ON) {
		  sendHttpGetRequest("http://maker.ifttt.com/trigger/doorbell/with/key/IFTTT_API_KEY")
		  }
	else {
		  val Integer currentHour = now.getHourOfDay
          if ((7..21).contains(currentHour)) {
            mihome_gateway_7811dcb24452_volume.sendCommand(20)
		    mihome_gateway_7811dcb24452_sound.sendCommand(10)
		    sendHttpGetRequest("http://maker.ifttt.com/trigger/doorbell/with/key/IFTTT_API_KEY")
		    Flash_Green.sendCommand(ON)
		}
		else {
		    sendHttpGetRequest("http://maker.ifttt.com/trigger/doorbell/with/key/IFTTT_API_KEY")
		    Flash_Green.sendCommand(ON)
			}
	  }	
end