How do I periodically call a function in my new plugin

I am working on a new plugin and want to do some processing based on time, say, every 5 seconds. So I believe I could:

  1. Use luup.call_timer in to schedule a timer
  2. Use luup.call_delay in then again in the callback to reschedule it
  3. Many other choices I can think of (

My questions are:

  1. how much does luup.call_timer burden my Vera 2 with overhead (memory and processing)
  2. If I wish to cancel a timer before completion, is there a function to do so?
  3. If I have 100 timers, am I asking for trouble

The final case is an alternate way to do it. The plugin will monitor about 5 events and only sees the “on” state. I must time out to generate the “off” state in the plugin, very much like a heartbeat from any of 5 sources. I can recalculate all timeouts every 5 seconds (single timer but higher processing) or set a call_delay for each timeout but cancel it if I get another “on” state in time for that particular event (less processing but potentially lots of outstanding timers — 20 instances of plugin * 5 timers each = 100) and I would want to cancel it rather than set a flag to do nothing in (ignore) the callback.

Basically, I’m not really looking for how to use the timers (mostly covered by docs), I’m looking for optimal use of timers (mostly covered by the expert’s experience!).

[quote=“GeekGoneOld, post:1, topic:193952”]I am working on a new plugin and want to do some processing based on time, say, every 5 seconds. So I believe I could:

  1. Use luup.call_timer in to schedule a timer
  2. Use luup.call_delay in then again in the callback to reschedule it
  3. Many other choices I can think of ([/quote]

Yes, indeed… if by you mean in the plugin’s initialization code.

1) how much does luup.call_timer burden my Vera 2 with overhead (memory and processing) 2) If I have 20 instances of the plugin (20 timers), am I asking for trouble 3) If I wish to cancel a timer before completion, is there a function to do so?

[ol][li]almost nothing[/li]
[li]no, that’s fine for the timers, but 20 instances of a plugin may crash Vera anyway.[/li]
[li]no, you can’t[/li][/ol]

Because of (3), you might prefer to use luup.call_delay(), which has to be rescheduled every time in the callback. That way you can look for a cancel flag and simply not reschedule it.

[quote=“akbooer, post:2, topic:193952”][ol][li]almost nothing[/li]
[li]no, that’s fine for the timers, but 20 instances of a plugin may crash Vera anyway.[/li]
[li]no, you can’t[/li][/ol][/quote]

Chuckle on the crash warning in #2!!!

Thanks for your info. I was expecting almost all of those answers except I knew nothing about the overhead of 100 timers. You’ve eased my mind…