I am not sure I know what you mean by runs twice … since you did not include the log … But putting a sleep for 30 seconds will likely cause Vera to restart …
The Log does not match your code … It is printing woken up multiple times between printing the numbers as you increment them. Your code fragment does not show this.
This is probably old code … Since the following is bad code:
i = i +1
luup.log(i)
until i > 10
luup.log(i)
Until is only valid as part of a Repeat construct. Repeat would need to be at the beginning of this fragment.
Vera will “restart” if it sees luup code that takes longer than 60 seconds (UI5) or 30 seconds (UI4) to complete. It restarts the entire engine in order to avoid Vera locking up. You might get lucky, but the lockup detection code is implemented in a variety of the entry points.
Set a timer (call_timer), and have it call you back periodically on a public fn until the “activity” is complete. This avoids Vera ever seeing code running for a long time.
Ok so I now play with luup.call_timer but it’s behaviour is unexpected. The statement gets issued but the program continues and only later does the funtion get executed. This for me makes writing the logic difficult.
I cant figure out how to execute some code 10 times with 30 seconds intervals using the call_timer call. I think I may be missing a key concept here, but exactly what is my program supposed to be doing while it’s waiting for the timer to expire. I don’t want it to do anything, but I do want it to start executing the statement after the call to call_timer.
Your main program returns right away and does NOT block Vera from doing other useful things.
[hr]
Welcome to the world of event driven code … This is the world that most developers on small devices or devices witch interface to a user live.
It is mutch more complicated because you need to know/control the order of events. The current state is often communicated via arguments to the event.
In your case the information is the current count.
Your timer code is the event driven code … and it is called at a timer interval (30 Seconds) from now. You call it first with an argument of 0 (Countup, or 10 for a Countdown)
When the timer runs … it increments/decrements the counter as appropriate … does it’s work for that time interval … in your case log a message … than if it’s not the end of the sequence … it reschedules itself with the new count.
Best Home Automation shopping experience. Shop at Ezlo!