Timer in rule

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)) ? :slight_smile:

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.

1 Like