Hi there!
I'm starting the journey converting my LUA scripts to dzVents. I guess it will take a while but it's fun and I believe dzVents has a great potential.
I have a few custom functions that I use heavily throughout my LUA scripts. I feel I'd like to add those functions into the Domoticz.lua module so that they are always easily available. By editing the Domoticz.lua, I'm aware that all my work will be lost when I upgrade dzVents next time and I will have to manually edit them back.
I wonder if there be a better way to achieve what I want to?
Cheers!
Custom functions in dzVents Domoticz.lua
Moderator: leecollings
Re: Custom functions in dzVents Domoticz.lua
Place them in another lua file and use them in your scripts.
Example, place all in a file myfunct.lua
Under the execute statement in your script:
package.path = 'path to scripts/?.lua'
require('MyFunc')
Example, place all in a file myfunct.lua
Under the execute statement in your script:
package.path = 'path to scripts/?.lua'
require('MyFunc')
-
BakSeeDaa
- Posts: 485
- Joined: Thursday 17 September 2015 10:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
Re: Custom functions in dzVents Domoticz.lua
Thanks @joebarjoebar wrote:Place them in another lua file and use them in your scripts.
Example, place all in a file myfunct.lua
Under the execute statement in your script:
package.path = 'path to scripts/?.lua'
require('MyFunc')
That's how I did it before I started to use dzVents.
Of course I can use an additional module (eg. MyFunc) but in that module, I won't be able to access the Domoticz object, right?
Re: Custom functions in dzVents Domoticz.lua
Sorry, bit late to answer. Hmm, no i think you can, or it must be in the dzvents script path because then it is picked up under dzvents control.BakSeeDaa wrote:Thanks @joebarjoebar wrote:Place them in another lua file and use them in your scripts.
Example, place all in a file myfunct.lua
Under the execute statement in your script:
package.path = 'path to scripts/?.lua'
require('MyFunc')
That's how I did it before I started to use dzVents.
Of course I can use an additional module (eg. MyFunc) but in that module, I won't be able to access the Domoticz object, right?
But if you place it in another directory, then it doesn't know about the objects.
-
dannybloe
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: Custom functions in dzVents Domoticz.lua
In the next major release (integration with Domoticz) you can do this:
Plugins
In global_data.lua do this
The helpers are added to the domoticz object passed to each script function:
Plugins
In global_data.lua do this
Code: Select all
return {
data = {},
helpers = {
helper = function(a, b) ... end,
anotherhelper = function(c, d) ... end,
}
}
Code: Select all
local x = domoticz.helpers.anotherhelper('bla', 123)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
-
BakSeeDaa
- Posts: 485
- Joined: Thursday 17 September 2015 10:13
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
Re: Custom functions in dzVents Domoticz.lua
Sounds great! Thanks!dannybloe wrote:In the next major release (integration with Domoticz) you can do this:
Plugins
In global_data.lua do this
The helpers are added to the domoticz object passed to each script function:Code: Select all
return { data = {}, helpers = { helper = function(a, b) ... end, anotherhelper = function(c, d) ... end, } }Code: Select all
local x = domoticz.helpers.anotherhelper('bla', 123)
Who is online
Users browsing this forum: Google [Bot] and 1 guest