How to wait for rule commands to complete - Sleep / Wait?

1,822 views
Skip to first unread message

Shawn Mix

unread,
Oct 6, 2014, 9:44:52 PM10/6/14
to ope...@googlegroups.com
I am currently working through some rules that send a bunch of commands to the ZWave gateway being used for control. In short, it doesn't do well when overloaded with commands and I'd like to reduce the overflow of calls made to the device. To do so, what I'm looking to do is break up the calls and how quickly they are made. I'll list below the current code I'm trying to slow down. The idea is I'd like to simply put a timer that waits 5 seconds or so between each line in the rule execution. Which also includes a timer for turning off a set of multiple items in succession with timers. Perhaps there is another timer function I'm not aware of to create the same thing for each line, but I didn't think that was possible since some devices don't just take ON/OFF commands as you'll see below. Any advice on how I can achieve this? I had seen many threads using things like Thread::sleep() but I don't understand the context of doing so and saw a few errors here and there that folks were having using them.

when

       Item Virtual_XHome changed or

       Item Virtual_YHome changed

then

       if(Virtual_XHome.state == OFF && Virtual_YHome.state == OFF){

                       sendCommand(AlarmPanel, "Armed")

                       sendCommand(Lock_FrontDoor, ON)

                               DownstairsLights.members.forEach(item,i|createTimer(now.plusSeconds(2)) [|sendCommand(item, OFF)])

                               UpstairsLights.members.forEach(item,i|createTimer(now.plusSeconds(2)) [|sendCommand(item, OFF)])

                       stateThermo = storeStates(Setpoints)

                       sendCommand(Virtual_ESM, ON)

                       alarmLighting = true

       }
end



karsten.k...@gmail.com

unread,
Oct 9, 2014, 12:48:51 AM10/9/14
to ope...@googlegroups.com
Hi

you can use the sleep option:

       UpstairsLights.members.forEach(item,i|createTimer(now.plusSeconds(2)) [|
                   sendCommand(item, OFF)
                   Thread::sleep(2000)])

Cheers
Karsten

Shawn Mix

unread,
Oct 9, 2014, 2:06:33 PM10/9/14
to ope...@googlegroups.com
Karsten - what is the number in ()? Seconds, milliseconds, something else? Also, can I use this without the timer? My thought is more to use the timer for things like the groups, but use the sleep in between each command that is running as part of the larger 'then' command set.

Martin Klimke

unread,
Oct 9, 2014, 2:15:32 PM10/9/14
to ope...@googlegroups.com
Where are those such language construct documented?
Looking for the secrets of the rule DSL is really very very time consuming.

Is this really only the source code of the DSL definition or is there any written document aside from the example code and the very few lines in the Wiki?

Kai Kreuzer

unread,
Oct 10, 2014, 3:34:38 AM10/10/14
to ope...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/d/optout.

karsten.k...@gmail.com

unread,
Oct 13, 2014, 3:11:19 AM10/13/14
to ope...@googlegroups.com
milliseconds
Reply all
Reply to author
Forward
0 new messages