Page 1 of 1

Call other LUA as subroutine?

Posted: Tuesday 07 September 2021 18:07
by manjh
It would be great if I could call another LUA script as a subroutine somehow. This would allow coding of frequently used logic on one place, and use it in many places.
The only way I can see how to do this, is to write a LUA script and store it on disk or SD card, and call that from the LUA script.
One disadvantage is the fact that I cannot write and update from the normal user interface, but have to go in (e,g, Putty) and use a local editor in the R-Pi.
Another disadvantage is the way I can back this code up: it is not included in the normal backup from the Domoticz settings tab, but has to be done separately.

Am I missing a more simple way?

Re: Call other LUA as subroutine?

Posted: Tuesday 07 September 2021 20:44
by Varazir

Re: Call other LUA as subroutine?

Posted: Wednesday 08 September 2021 16:19
by manjh
Varazir wrote: Tuesday 07 September 2021 20:44 You can use the global_data file to create you own helper functions

https://www.domoticz.com/wiki/DzVents:_ ... _scripting
https://www.domoticz.com/wiki/DzVents:_ ... _functions
I see how this works, but it still has the disadvantage that the code is not included in the Domoticz backup...

Re: Call other LUA as subroutine?

Posted: Wednesday 08 September 2021 16:31
by Varazir
manjh wrote: Wednesday 08 September 2021 16:19
Varazir wrote: Tuesday 07 September 2021 20:44 You can use the global_data file to create you own helper functions

https://www.domoticz.com/wiki/DzVents:_ ... _scripting
https://www.domoticz.com/wiki/DzVents:_ ... _functions
I see how this works, but it still has the disadvantage that the code is not included in the Domoticz backup...
Yes it is. It's stored in the DB as far as I understand.

Re: Call other LUA as subroutine?

Posted: Wednesday 08 September 2021 16:52
by erem

Yes it is. It's stored in the DB as far as I understand.
only if you use the internal events editor. then the script are stored in domoticz.db

from the wiki: Note: there can be only one global_data.lua on your system. Either in /path/to/domoticz/scripts/dzVents/script or in Domoticz’ internal GUI web editor.

if you put global_data.lua in /path/to/domoticz/scripts/dzVents/script, it is your responsibility to back it up.

Re: Call other LUA as subroutine?

Posted: Wednesday 08 September 2021 20:43
by Varazir
erem wrote: Wednesday 08 September 2021 16:52

only if you use the internal events editor. then the script are stored in domoticz.db

fromthe wiki: Note: there can be only one global_data.lua on your system. Either in /path/to/domoticz/scripts/dzVents/script or in Domoticz’ internal GUI web editor.

if you put global_data.lua in /path/to/domoticz/scripts/dzVents/script, it is your responsibility to back it up.
Ahh okay, I only use the internal editor.

Re: Call other LUA as subroutine?

Posted: Monday 13 September 2021 18:57
by manjh
This method only works for dzVents, right?

Re: Call other LUA as subroutine?

Posted: Saturday 18 September 2021 21:49
by EddyG
If you want to automatically backup ALL Domoticz files you could use rsnapshot. I use it for years now to backup to an USB-stick, and it works perfect.
Then global_data.lua is also included.