Lua scripts (events): order of execution

Moderator: leecollings

Post Reply
Kifo
Posts: 10
Joined: Wednesday 22 March 2017 12:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Lua scripts (events): order of execution

Post by Kifo »

Hi,
I have several time based LUA scripts in the events panel of my project, executed every minute. Some of them depend on the results of others.
Thus the order of execution of these scripts is of importance.

How can I influence the order of execution?

So I found the all time based scripts are executed in the order of creation. Thus I have to save a script under a new name (and delete the old version) for moving it to the end of the queue.

I think there might be an easier way to influence the order of script execution?
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua scripts (events): order of execution

Post by jvdz »

I have one master LUA time script which in which I perform the appropriate scripts with a dofile() statement.
In this way I can control which script runs when and in which sequence.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Kifo
Posts: 10
Joined: Wednesday 22 March 2017 12:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua scripts (events): order of execution

Post by Kifo »

Sounds like an interesting soution.

I assume I would have to transfer all my time based scripts into separate files on my system (e.g. home\pi\domoticz\scripts\lua) and call them using the dofile() command? Mybe you could post a code snippet as exsample.

Looks like with this soution I could no longer use the Domoticz backend scipt editor which I like as I can use it even remotely without direct access to the raspi file system.

Kifo
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua scripts (events): order of execution

Post by jvdz »

I am not using the internal editor and have all my scripts in the tree: /home/pi/domoticz/scripts/lua
when changing from individual scripts to the above approach, I simply moved the time scripts into directory lua/time and device scripts into lua/device. Then renamed them removing _time and _device from its name and commented the "commandArray = {}" and "return commandArray" lines in those scripts.
then created an script_time_all.lua and a script_device_all.lua file for each type of event which are now the only 2 event scripts for these types.
result is that the event system scripts run much faster and much better control.

I doubt you can do this with the internal editor in this way though.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Kifo
Posts: 10
Joined: Wednesday 22 March 2017 12:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Lua scripts (events): order of execution

Post by Kifo »

Got it.

I will give it a try, as this approach seems to provide me with 2 benefits:
- control the order of execution
- faster execution (I did not expect this, but would be welcome)

The price to pay is that I no longer can use the Domoticz backend editor then for a quick script fix while I am away from home having no access to the raspi file system.

Let's see how I like it...
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests