If I use the function call_delay a function will be called in ‘seconds’ seconds. Is it possible to modify the timer before the timer expires? Basically, I would like to have a timer that calls a function in x seconds. If something happens before x seconds elapse I would like to rewind the timer to x seconds again. Possible?

I think no. But you might be able to fake it with some careful programming. The way I do this in the real world is:

  1. Generate a number that is strictly larger than any previous number I’ve generated.
  2. Store it into a global variable.
  3. use call_timer to call a function, and pass the number as a parameter.

Then, later, when the function runs, it looks in the variable, and if its parameter is different, it exits doing nothing.

I think you are in uncharted territory here in Luup. If you try it, let us know how it goes.


It would be nice to get a reference back from calling call_delay so that it is possible to update or delete the timer later on if needed (maybe a unique number pointing to the position in the array storing timers (or whatever structure there is internally).

Cancelling a Luup timer is important but it would be nice as well to be able to update the timer (sure, that could be implemented by deleting and then adding a new one if needed; that however is ugly).

I noticed that when I use call_timer my function only gets called once. I then have to call call_timer again in the called function to get a periodic execution of the function. However, I thought call_timer should result in a periodic timer so that I do not have to re-set it (the wiki says so). I thought that is the main difference between call_delay and call_timer; one being once the other periodic. Anyway, calling call_timer again in the function called by the timer results in a drift as calling the function needs time as well (but its not a realtime system so maybe this slight drift can be ignored here).

For now I use call_timer once a minute to check a global variable. Works but is ugly as the system has to execute the function every minute even if there is nothing to do (The system should be able to handle this unless everyone is using timers like me which would create a performance problem). I can improve this but ultimately there is need for better timer handling.

Does anyone have any code examples they can post that use the call_delay or the call_timer?


Are you looking for generic examples of [tt]luup.call_timer[/tt], or something that specifically handles the mechanism that @futzle uses.

Generic examples exist in the Weather Plugin, and a few others by now also, but they don’t cover the full range of options on the method/functionality exposed.

[quote=“JOD, post:5, topic:168608”]Does anyone have any code examples they can post that use the call_delay or the call_timer?


Just something generic to try to understand how’s it’s implemented to possibly use it as a work around for my Ping Sensor issue?
I was able to find an example of the call_delay in Ap15e’s Blinking Christmas tree code but could find anything on call_timers.


Again, it’s a fairly simplistic example… I’d never really compared [tt]luup.call_timer[/tt] and [tt]luup.call_delay[/tt].

If it weren’t for the thread options, it seems like call_timer is a superset of call_delay… interesting.