Call other LUA as subroutine?

Moderator: leecollings

Post Reply
manjh
Posts: 708
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Call other LUA as subroutine?

Post 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?
Hans
User avatar
Varazir
Posts: 360
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Call other LUA as subroutine?

Post by Varazir »

Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
manjh
Posts: 708
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Call other LUA as subroutine?

Post 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...
Hans
User avatar
Varazir
Posts: 360
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Call other LUA as subroutine?

Post 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.
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: Call other LUA as subroutine?

Post 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.
Last edited by erem on Saturday 11 September 2021 13:01, edited 2 times in total.
Regards,

Rob
User avatar
Varazir
Posts: 360
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Call other LUA as subroutine?

Post 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.
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
manjh
Posts: 708
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Call other LUA as subroutine?

Post by manjh »

This method only works for dzVents, right?
Hans
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Call other LUA as subroutine?

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

Who is online

Users browsing this forum: No registered users and 0 guests