# Timer in rule

**URL:** <https://community.openhab.org/t/timer-in-rule/90537>\
**Category:** Scripts & Rules\
**Tags:** openhab2\
**Created:** [January 15, 2020, 7:28pm UTC](https://community.openhab.org/t/timer-in-rule/90537 "2020-01-15T19:28:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhauerslev](https://community.openhab.org/letter_avatar_proxy/v4/letter/j/82dd89/32.png) [@jhauerslev](https://community.openhab.org/u/jhauerslev)\
**Post date:** [January 15, 2020, 7:28pm UTC](https://community.openhab.org/t/timer-in-rule/90537/1 "2020-01-15T19:28:14Z")

</div>

Hi.  
I am using openhab2 on a raspberry pi, to interact with my IHC-controller (home automation system).  
I am new with writing code.

I am using Chromecast Audio along with my amplifier.

I wrote this rule to turn on my amplifier when Chromecast changes to PLAY, and to turn the amplifier off, when status is PAUSE.

rule “Tænd for forstærker i køkken, når CCK afspiller”  
when  
Item CCK changed to PLAY  
then  
amp\_k.sendCommand(ON)

end

rule “Sluk for forstærker i køkken, når CCK ikke afspiller”  
when  
Item CCK changed to PAUSE  
then  
amp\_k.sendCommand(OFF)

end

Unfortunately, CC Audio changes to pause during one track stops, and i new one begins…

How can I delay the off-command (pause for more than 2 sec, then sendCommand(OFF)) ? 🙂

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [January 15, 2020, 8:07pm UTC](https://community.openhab.org/t/timer-in-rule/90537/2 "2020-01-15T20:07:40Z")

</div>

Search the forum for “anti-flapping” or “debounce” and you will find lots and lots of examples. At a high level, you set a Timer for two minutes when PAUSE is received to turn off the amp. When PLAY is received, cancel the Timer if it exists.
