Double TAP will switch another on/off

Make a double tap on a switch control another one.
exemple with 2 switch and and one switch.
you need the timer when controlling 2 switch with double tap. or you will have an infinite loop.

import org.joda.time.*
import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*

var int tapDelay = 500
var DateTime timeSwitchKitchen = new DateTime().minusMinutes(5)
var boolean sendingDinning = false
var DateTime timeSwitchDinning = new DateTime().minusMinutes(5)
var boolean sendingKitchen = false

var DateTime timeSwitchBed1 = new DateTime().minusMinutes(5)


rule "Double TAP Kitchen"
when
    Item Light_Kitchen received update
then
    if(sendingKitchen==false) {
        if(timeSwitchKitchen.plusMillis(tapDelay).afterNow) {
            sendingDinning = true
            sendCommand(Light_Dinning, (Light_Kitchen.state as OnOffType))
            var Timer timerAlarmDelayKitchen = createTimer(now.plusMillis(tapDelay)) [| 
                sendingDinning=false    
            ]
        }else{
            timeSwitchKitchen = new DateTime()
        }
    }
end

rule "Double TAP Dinning"
when
    Item Light_Dinning received update
then
    if(sendingDinning==false) {
        if(timeSwitchDinning.plusMillis(tapDelay).afterNow) {
            sendingKitchen = true
            sendCommand(Light_Kitchen, (Light_Dinning.state as OnOffType))
            var Timer timerAlarmDelayDinner = createTimer(now.plusMillis(tapDelay)) [| 
                sendingKitchen=false    
            ]
        }else{
            timeSwitchDinning = new DateTime()
        }
    }
end

rule "Double TAP Bed1"
when
    Item Light_Bed1 received update
then
    if(timeSwitchBed1.plusMillis(tapDelay).afterNow) {
        sendCommand(Light_Bed2, (Light_Bed1.state as OnOffType))
    }else{
        timeSwitchBed1 = new DateTime()
    }
end
1 Like

That sounds great!

I think you should post this in the wiki.


or

It only works on switches that send their status pretty quickly. Ones like the GE’s won’t work with this, as they basically send their status when they feel like it.

I have GE switch and it work. You jus need to “time” your tap.
If you double tap really quickly it will not work.

I would think the newer GE models do work, I have a few of the original versions that were available at Lowes, and those will send an update maybe 20-30 seconds after something is done. So it would certainly not work well(unless you want to double tap 30 seconds later).

30 seconds… wow. that’s bad. If you did have some of those i would recommend to move one that work where you need double tap. I don’t think you need to have this feature on all your switch :wink:

Nah, 90% of mine are instant status, but I have a few of the GE’s that I used when I first started automating 2-1/2 years ago floating around.

They do suck with sending updates, but they work for things I don’t care much about. I just wanted to note it in the thread if anyone is going to try it, not to get pissed if they have older GE switches… haha, should work very well for anything else. I’m using something like this on mine, a double tap turns off the “auto turn off” features.