Vera - Smarter Home Control Forum

Advanced => Programming => General => Topic started by: FiveNines on February 12, 2018, 11:13:09 am

Title: Delayed action and function placement
Post by: FiveNines on February 12, 2018, 11:13:09 am
On this forum, I have read that scenes which have a delayed action may not complete if the Luup engine restarts during the delay period. The postings I found are years old. Is this issue still true in UI7? Does the function luup.call_delay also act the same? My experimenting is that scene delay action has not changed and that the call_delay performs as it should regardless of restarts.

In a Lua program, where should the functions be placed, before or after the main (function calling) program? Some programming languages only allow a function or function declaration before the main program because the complier/interpreter is a single pass. I?ve placed functions before and after the main Lua program, and had it work, but in one particular program, the function must be first in order for the program to execute.

ru6Re

Title: Re: Delayed action and function placement
Post by: rigpapa on February 12, 2018, 12:09:04 pm
Delayed actions in scenes are still lost over a Luup restart, as is any callback from call_timer or call_delay.

Functions usually should be defined (or at least declared) before they are used, so functions come before main. There are exceptions, but if you follow this as a guideline you generally won't get surprised.
Title: Re: Delayed action and function placement
Post by: Don Phillips on February 12, 2018, 08:03:29 pm
Many folks have migrated from scenes to PLEG, which can survive a LUUP restart.
Title: Re: Delayed action and function placement
Post by: aa6vh on February 13, 2018, 10:26:55 am
LUA is also a "Just in Time" type of compiler, which means scene LUA code is not compiled (after a restart) until the scene is run.

The is important to note if one scene contains a global function that is used in another scene. If the second scene is run before the first, then unpleasantness will occur.

I place my global functions in the LUA Start up code section, as that is always run when LUA restarts. So I know the functions are valid when my scenes are run.
Title: Re: Delayed action and function placement
Post by: FiveNines on February 15, 2018, 10:40:25 am
It is unfortunate that the delayed action still does not survive a Luup restart in the current Vera software (UI) version. Surprising since the feature is integrated. If I had not researched, I would have not known that it sometimes does not work. I will continue to use it and the luup.call_delay function as the only time my Luup restarts is when I make changes. And I do not have mission-critical controls ? if a lights stays on, it is no big deal.

Thank you for your responses.
Title: Re: Delayed action and function placement
Post by: michelhamelin on February 15, 2018, 10:19:19 pm
Make first scene that start a timer and a second scene starting when timer complete.
Luup restart survive a timer on my side.