Expire Binding

Hi I am trying to do a very simple rule with expire binding using it as a 5-sec delay
but it is never expiring, OP1 stays ON

rule “test1” when
Item SW1 changed from OFF to ON then
sendCommand(OP1, ON)
expire=“5s,sendCommand(OP1, OFF)”
end

I have installed the binding and rebooted the server
Anyone can help, please

i don´t know if expire can be used in rules, as far as i know it is used in *.items file. small example of an item i use:

Switch CheckThings_Timer {expire="30m,command=OFF"}
2 Likes

Thanks for your prompt reply Bastler

Ops now I understand, that must be the reason
I am new to openhub is there another commands I can use
as a delay?

perhaps i don´t understand. my example was for a 30-minutes delay. but of course you can use your “5s” for 5 seconds, too

I mean a delay I can use in .rules file , this is just a simple
code to see it working i might not be using it in this exact contest .

OK i Found this: Thread::sleep(5000)
it seems to work fine

Thanks

It’s bad practice, because you have locked up the rule execution just waiting.
Look instead into the use of timers, which consume no resource while waiting for their time to come.
Introduction here

1 Like

Hi thanks for your advice i will do more research

:+1: +1 for @rossko57 advice.

For your research, :wink: here’s an example rule that checks the condition of a timer and cancels/resets it. The forum is full of examples so enjoy yourself and the community is here for when you hit a snag. :grinning: Also, don’t be shy about clicking the heart icon on a post that you find helpful e.g. rossko57 post. It’s a great way to say thanks for your time and contribution. :smiley:

var Timer myTimer = null
rule "Motion OFF"
when
    Item Motion changed from OFF
then
    if (myTimer === null) {
        if  (Motion.state == ON) {
            myTimer = createTimer(now.plusSeconds(60), [ |
                if (Motion.state == ON){
                //do stuff
                }
            ])   
        }
    }
end

rule "BACK FROM ON"
when
    Item Motion changed from ON
then
    myTimer.cancel
    myTimer = null
end
1 Like

Thanks H102

I ended up using cron for what i had in mind to accomplish.