Author Topic: Delayed action and function placement  (Read 150 times)

Offline FiveNines

  • Newbie
  • *
  • Posts: 17
  • Karma: +0/-0
Delayed action and function placement
« 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

« Last Edit: February 12, 2018, 11:17:20 am by FiveNines »

Offline rigpapa

  • Sr. Member
  • ****
  • Posts: 268
  • Karma: +33/-0
    • toggledbits.com
Re: Delayed action and function placement
« Reply #1 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.
Author of Rachio, Deus Ex Machina II, Intesis WMP Gateway, SiteSensor, Auto Virtual Thermostat and VirtualSensor plugins. Using Vera Plus (1.7.3232), Vera3 (1.7.1017), 50+ dimmers and 40+ switches (mostly Leviton, some Linear and GE), a dozen sensors, a lot of time and patience.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1100
  • Karma: +25/-25
    • Worthington Engineering, Inc.
Re: Delayed action and function placement
« Reply #2 on: February 12, 2018, 08:03:29 pm »
Many folks have migrated from scenes to PLEG, which can survive a LUUP restart.
Vera 3, UI7 1.7.1017, CT101 t-stat, Everspring motion detector, GE/Jasco switch, Leviton outlet, AeonLabs door sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual & Multi Switch, Weather, Sys. Mon.

Offline aa6vh

  • Hero Member
  • *****
  • Posts: 610
  • Karma: +13/-0
Re: Delayed action and function placement
« Reply #3 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.
« Last Edit: February 13, 2018, 10:28:45 am by aa6vh »

Offline FiveNines

  • Newbie
  • *
  • Posts: 17
  • Karma: +0/-0
Re: Delayed action and function placement
« Reply #4 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.

Offline michelhamelin

  • Full Member
  • ***
  • Posts: 144
  • Karma: +2/-0
Re: Delayed action and function placement
« Reply #5 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.