Blocky: Run LUA script with a delay of x seconds

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
Ritmeester
Posts: 53
Joined: Thursday 06 March 2014 18:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Blocky: Run LUA script with a delay of x seconds

Post by Ritmeester »

In Blocky I run a LUA script. I want to run this script with a delay of x seconds.

Is this possible?
leonmoonen
Posts: 20
Joined: Thursday 25 May 2017 23:07
Target OS: Raspberry Pi / ODroid
Domoticz version: current
Contact:

Blocky: Run LUA script with a delay of x seconds

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
leonmoonen
Posts: 20
Joined: Thursday 25 May 2017 23:07
Target OS: Raspberry Pi / ODroid
Domoticz version: current
Contact:

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

Post 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)?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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 &.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Ritmeester
Posts: 53
Joined: Thursday 06 March 2014 18:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest