Using one time multiple times within a rule

Hi there,

I am very new to openHab (running version 2 on a synology) and I am trying to get the following working.
I already searched a bunch of topics related to timers incl. how to cancel, reschedule or set them to null, but I just don’t get it working.

What I want:
I want to switch a 2-channel virtual trigger (using ittt) on and off with specified delays inbetween.
I have created 4 ifttt webhook events (upoff, upon, downoff, downon) which are working and used to control a awning (power to move up/downwards and stopping)

The rule consists of the following entries:
(how the rule is triggered, is working fine!)

executeCommandLine(“curl -X POST httxx://maker.ifttt.com/trigger/downoff/with/key/xxxxxxxxxx”)
// this stops any potential downon event (here I’d like to wait 3 seconds)
executeCommandLine(“curl -X POST httxx://maker.ifttt.com/trigger/upon/with/key/xxxxxxxxxx”)
// this moves the awning upwards (here I’d like to wait 30 seconds)
executeCommandLine(“curl -X POST httxx://maker.ifttt.com/trigger/upoff/with/key/xxxxxxxxxx”)
// this stops moving the awning upwards (here I’d like to wait 3 seconds)
executeCommandLine(“curl -X POST https://maker.ifttt.com/trigger/downon/with/key/xxxxxxxxxx”)
// this moves the awning downwards (here I’d like to wait 20 seconds)
executeCommandLine(“curl -X POST https://maker.ifttt.com/trigger/downoff/with/key/xxxxxxxxxx”)
// this stops moving the awning downwards (here I’d like to wait 3 seconds)

Now what I you like to achieve is the following:
1 seconds after “downoff” event, start the “upon” event and let it go for 30 seconds.
This will assure, that a potentially opened awning gets closed completely.
Then, after the 30 seconds, the “upon” event will be followed by “upoff” to stop that movement.

Then I’d like to run the “downon” event for 20 seconds.
Within the 20 seconds, the awning opens as much as I’d like to.
Then, after 20 seconds, I use “downoff” the stop that movement.

Now, could anyone help me with getting the 5 executeCommandlLine into a working syntax with those timers/delays each inbetween?

I was able to get a timer working once, but in no was I was able to reset the timer or reschedule it to use it with the next executeCommandLine Option.

Any help is much appreciated!

Best regards,
thank you!

Christian

The important thing to realize about Timers is that they don’t stop your Rule from running. A Timer will schedule a bit of code to run at some later time. Once a Timer is created the rest of your Rule immediately executes.

So what you need to do is schedule each of these events to take place at the times you want them to. NOTE: please use How to use code fences when posting code or logs.

executeCommandLine(“curl -X POST httxx://maker.ifttt.com/trigger/downoff/with/key/xxxxxxxxxx”)

createTimer(now.plusSeconds(3), [ | executeCommandLine(“curl -X POST httxx://maker.ifttt.com/trigger/upon/with/key/xxxxxxxxxx”) ])

createTimer(now.plusSeconds(3+30), [ | executeCommandLine(“curl -X POST httxx://maker.ifttt.com/trigger/upoff/with/key/xxxxxxxxxx”) ])

createTimer(now.plusSeconds(3+30+3), [ | executeCommandLine(“curl -X POST https://maker.ifttt.com/trigger/downon/with/key/xxxxxxxxxx”) ])

createTimer(now.plusSeconds(3+30+3+20), [ | executeCommandLine(“curl -X POST https://maker.ifttt.com/trigger/downoff/with/key/xxxxxxxxxx”) ])

Notice how I add the previous number of seconds to how long you want to wait between the commands. Notice though that because we don’t hold on to the Timer in a global variable we cannot cancel the commands or reschedule them. They will run no matter what, but that is what you are asking for. It gets more complicated when you want to cancel these scheduled commands or otherwise manage the Timers.

Dear Rich,

wow - thank for the amazing fast answer.
That was really easy, but I didn’t think about adding the times.

Can confirm this is fully working now.
Really happy so far with OpenHab! Great work!

1 Like