[SOLVED] Switch ON and Switch OFF after 20 seconds

  • Platform information:
    • Hardware: Raspberry Pi 3
    • OS: Raspbian
    • Java Runtime Environment: build 1.8.0_65-b17
    • openHAB version: 2.3.0
  • Issue of the topic:

Hello, I just recently started with Openhab for a class project, I’m totally new in this so I apologize in advance if the code is hard to read or if there’s some huge/easy to spot mistakes.

What I’m trying to do is to activate blinders based on luminance. I have a relay with 3 switches, one ups the blinder, one downs it and the other does apparently nothing.

My problem is the following: I’m trying to make it so the switches that activate the blinders, deactivate after 20 seconds (which is approximately the time that it takes the blinder to go full down and full up). My reasoning for this is that if you activate the switch that downs the blinder for example and it stays on, when you try to get up the blinder it won’t work because the “down” switch is already activated, so there’s a conflict. That’s why I want them to be turned off after 20 seconds.

I wrote some rules to make this work, and it works perfectly for the “down” switch, once it’s activated and 20 seconds pass, it deactivates. BUT the same doesn’t happen to the “up” switch, I’ve checked for errors, checked the logs, tried to do a couple of workarounds but couldn’t do it.

I’ll leave the code here, feel free to tell me how to improve it even if it doesn’t directly approach my problem, I’m very interested and invested in this, and please do tell me if you need more info or if something about this post is wrong. Oh, and sorry, some parts of the code are in Spanish since that’s where I’m from. I wrote some comments to try to clear some things up.

//Declaring vars for the timers
var Timer TempBajada = null
var Timer TempSubida = null

// The purpose of this rule is to down a blinder when it's below 50 luminance and to get it up when it's above 50 luminance

rule "Subir y bajar persiana"


    Item ZWaveNode2ZW100Multisensor6_SensorLuminance changed


if (ZWaveNode2ZW100Multisensor6_SensorLuminance.state <50) {


if (ZWaveNode2ZW100Multisensor6_SensorLuminance.state >50) {


//The purpose of this rule is to turn off the switch 20 seconds later of being switched on, so that other orders can be issued later

rule "Apagar switch bajada"

Item ZWaveNode12ZMNHBDFlush2Relays_Switch changed to ON 

if (TempBajada === null) {
    TempBajada = createTimer(now.plusSeconds (20))[  



//Same thing as before but for the get blinder up switch

rule "Apagar switch subida"

Item ZWaveNode12ZMNHBDFlush2Relays_Switch2 changed to ON

if (TempSubida === null) {
    TempSubida = createTimer(now.plusSeconds (20))[


Get rid of the rules and install the expire binding

Then define your items in an *.items folder. For example “blinds.items”

If you have linked your items to the channel in paperUI then remove the link. NOW.

Create the 2 items definition like this:

Switch ZWaveNode12ZMNHBDFlush2Relays_Switch { channel="GET_THAT_FROM_PAPERUI", expire="20s, command=OFF" }
Switch ZWaveNode12ZMNHBDFlush2Relays_Switch2 { channel="GET_THAT_FROM_PAPERUI", expire ="20s, command=OFF" }

Would be better to switch off the second channel when switching on the first one. As the two switches are not independly, you should always ensure to switch both as needed.

Likewise, you should only use one timer for both channels up and down.

1 Like

Thank you both! I’ll get to it this morning and let you know!

Thank you very much! I got it working with the expire binding, such a useful tool, didn’t know I could do that with a binding! Really looking forward to doing more things with openhab!