Page 1 of 1

Blocky: Run LUA script with a delay of x seconds

Posted: Sunday 22 July 2018 8:34
by Ritmeester
In Blocky I run a LUA script. I want to run this script with a delay of x seconds.

Is this possible?

Blocky: Run LUA script with a delay of x seconds

Posted: Sunday 22 July 2018 11:21
by leonmoonen
You could change the lua script so it starts with a delay/sleep. Here are some suggestions on building a sleep function in lua: http://lua-users.org/wiki/SleepFunction

Re: Blocky: Run LUA script with a delay of x seconds

Posted: Sunday 22 July 2018 11:37
by waaren
leonmoonen wrote: Sunday 22 July 2018 11:21
Ritmeester wrote: Sunday 22 July 2018 8:34 In Blocky I run a LUA script. I want to run this script with a delay of x seconds.

Is this possible?
You could change the lua script so it starts with a delay/sleep. Here are some suggestions on building a sleep function in lua: http://lua-users.org/wiki/SleepFunction
Probably not an ideal solution as the event system in domoticz is single threaded. So it will have to wait until the lua script with the delay is finished.
Better to use a workaround by creating a virtual device or variable that you switch / set with the afterSeconds option and let that device / var trigger the next script.

Re: Blocky: Run LUA script with a delay of x seconds

Posted: Sunday 22 July 2018 11:52
by leonmoonen
Wow, I had fully expected that such ‘secondary’ scripts (i.e., started in a event handling script like blockly) would be executed on the background...

Is there a reason not to do so (except if you’d want to get a value back)?

Re: Blocky: Run LUA script with a delay of x seconds

Posted: Sunday 22 July 2018 13:18
by waaren
leonmoonen wrote: Sunday 22 July 2018 11:52 Wow, I had fully expected that such ‘secondary’ scripts (i.e., started in a event handling script like blockly) would be executed on the background...

Is there a reason not to do so (except if you’d want to get a value back)?
If it is external script (so started from os level) you can use the OS mechanism for running it in the background. So in linux you could start it with a trailing &.

Re: Blocky: Run LUA script with a delay of x seconds

Posted: Sunday 22 July 2018 18:25
by Ritmeester
Thank you all for the answers. I didn’t know of this “Single Threaded” so I made a virtual switch and let this switch do the job.

All is working perfect now.

EDIT: Extra info.

The sleep command in LUA wil generate this error message:

Code: Select all

Error: EventSystem: Warning!, lua script Post Box Switch has been running for more than 10 seconds