Author Topic: Run my lua code during initialization/reset?  (Read 4352 times)

Offline neilios

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +0/-0
  • Vacation Rental Automation
    • MyVRZone Vacation Rental Management Software
Run my lua code during initialization/reset?
« on: August 17, 2009, 09:48:37 pm »
I have some functions and variables that are currently in an "initialization" scene that I want code in other scenes to be able to use - but the "initialization" scene needs to run first to globalize the functions and variables before the other scene functions can "see" it.

How do I get that initialization code to run whenever the lua engine starts up?

Either I need a way to make the current scene run automatically on startup or I place the code somewhere else?

Thanks,
Neilios
My Network: [Vacation Home #1 - Vera v862, 1x Wayne Dalton], [Vacation Home #2 - Vera v862, 2x Wayne Dalton], Custom device & LUA code on each for remote thermostat operation for occupied/unoccupied and history upload to myvrzone.com DB.

Offline guessed

  • Master Member
  • *******
  • Posts: 5294
  • Karma: +90/-22
  • Release compat is not a bolted-on afterthought
Re: Run my lua code during initialization/reset?
« Reply #1 on: August 18, 2009, 09:40:33 pm »
Neillos,
I was going to recommend that you try editing the Startup Lua under Luup Plugins --> Edit Startup Lua, but then I tried a snippet of code myself in 1.0.862:

    luup.log("Starting custom startup LUA")


and checked the logs after Save and also after rebooting Vera to get the whole startup sequence.  In both cases, there was no output in /var/log/cmh/LuaUPnP.log so either:

a) Startup Lua codeblocks never fire OR;
b) luup.log(...) doesn't work during startup blocks

at any rate, once it can be verified, this seems like the logical "trigger" spot to put the type of code you're writing.

There are other options, like Lua modules, but they're increasing the level of complexity for what you're doing.  I'd like to see the simple ones work first.

MCV: Does the Startup Lua block work under Luup Plugins --> Edit Startup Lua?

Offline micasaverde

  • Administrator
  • Hero Member
  • *****
  • Posts: 1666
  • Karma: +15/-1
Re: Run my lua code during initialization/reset?
« Reply #2 on: August 19, 2009, 10:17:07 pm »
Startup Lua should work.  Let me test it tomorrow and post here.

Offline neilios

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +0/-0
  • Vacation Rental Automation
    • MyVRZone Vacation Rental Management Software
Re: Run my lua code during initialization/reset?
« Reply #3 on: August 20, 2009, 09:38:54 pm »
I've just tried the same thing and got no log message. The actual startup code itself was loaded as is shown in the log file:

Code: [Select]
08      08/20/09 18:34:05.126   JobHandler_LuaUPnP::HandleActionRequest argument inUserData={ "StartupCode": "luup.log(\"START\")" } <0x340e>

... but there was just no display of the log text in my call.

Neilios
My Network: [Vacation Home #1 - Vera v862, 1x Wayne Dalton], [Vacation Home #2 - Vera v862, 2x Wayne Dalton], Custom device & LUA code on each for remote thermostat operation for occupied/unoccupied and history upload to myvrzone.com DB.

Offline neilios

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +0/-0
  • Vacation Rental Automation
    • MyVRZone Vacation Rental Management Software
Re: Run my lua code during initialization/reset?
« Reply #4 on: August 22, 2009, 01:01:11 pm »
@micasaverde,

Did you get to try the luup startup code - any issues found or a workaround/alternative?

Thanks,
Neilios
My Network: [Vacation Home #1 - Vera v862, 1x Wayne Dalton], [Vacation Home #2 - Vera v862, 2x Wayne Dalton], Custom device & LUA code on each for remote thermostat operation for occupied/unoccupied and history upload to myvrzone.com DB.

Offline neilios

  • Jr. Member
  • **
  • Posts: 50
  • Karma: +0/-0
  • Vacation Rental Automation
    • MyVRZone Vacation Rental Management Software
Re: Run my lua code during initialization/reset?
« Reply #5 on: August 22, 2009, 09:39:21 pm »
I've just worked around this by creating a plugin and putting all my functions in there and calling the initialization code in its startup.

I have a different issue now with the UI customization:
http://forum.micasaverde.com/index.php?topic=1784.0

Neilios
My Network: [Vacation Home #1 - Vera v862, 1x Wayne Dalton], [Vacation Home #2 - Vera v862, 2x Wayne Dalton], Custom device & LUA code on each for remote thermostat operation for occupied/unoccupied and history upload to myvrzone.com DB.

Offline waynebrady

  • Full Member
  • ***
  • Posts: 110
  • Karma: +0/-0
Re: Run my lua code during initialization/reset?
« Reply #6 on: October 07, 2011, 06:28:58 pm »
neilios-

Can you give me some details on how you created a plugin where the functions could be accessed directly?

Thanks in advance!!

Offline geoffschultz

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: Run my lua code during initialization/reset?
« Reply #7 on: July 25, 2017, 06:56:07 am »
How does one do this in UI 7?  I can't find any Startup LUA to edit.

-- Geoff

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9741
  • Karma: +737/-136
    • RTS Services Plugins
Re: Run my lua code during initialization/reset?
« Reply #8 on: July 25, 2017, 08:08:39 am »
In APPS -> Develop Apps -> Startup LUA

You can also put Startup LUA code in PLEG and it will run as part of that plugins startup.
 

Offline aa6vh

  • Hero Member
  • *****
  • Posts: 602
  • Karma: +12/-0
Re: Run my lua code during initialization/reset?
« Reply #9 on: July 25, 2017, 10:07:18 am »
I have found that some things do not work when run in the LUA startup code, most likely because the startup code is executed before the environment has been fully brought up.

I solved this by creating a scene (I called "Initialize"), that gets called as the last thing the start up code does. The Initialize scene will not actually run until the environment is ready to go, so things that require that environment can safely run from within that scene.

I did this because I wanted to lock my doors when Vera restarts, but the locking would not work when executed in the Startup code.


Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9741
  • Karma: +737/-136
    • RTS Services Plugins
Re: Run my lua code during initialization/reset?
« Reply #10 on: July 25, 2017, 10:31:53 am »
In startup ... do a luup.call_delay and run your code 30 seconds later.