Page 1 of 1
Custom functions in dzVents Domoticz.lua
Posted: Friday 10 March 2017 11:51
by BakSeeDaa
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!
Re: Custom functions in dzVents Domoticz.lua
Posted: Friday 10 March 2017 13:00
by joebar
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')
Re: Custom functions in dzVents Domoticz.lua
Posted: Friday 10 March 2017 16:49
by BakSeeDaa
joebar 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')
Thanks @joebar
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
Posted: Monday 13 March 2017 16:58
by joebar
BakSeeDaa wrote:joebar 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')
Thanks @joebar
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?
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.
But if you place it in another directory, then it doesn't know about the objects.
Re: Custom functions in dzVents Domoticz.lua
Posted: Tuesday 30 May 2017 16:01
by dannybloe
In the next major release (integration with Domoticz) you can do this:
Plugins
In global_data.lua do this
Code: Select all
return {
data = {},
helpers = {
helper = function(a, b) ... end,
anotherhelper = function(c, d) ... end,
}
}
The helpers are added to the domoticz object passed to each script function:
Code: Select all
local x = domoticz.helpers.anotherhelper('bla', 123)
Re: Custom functions in dzVents Domoticz.lua
Posted: Tuesday 30 May 2017 18:05
by BakSeeDaa
dannybloe wrote:In the next major release (integration with Domoticz) you can do this:
Plugins
In global_data.lua do this
Code: Select all
return {
data = {},
helpers = {
helper = function(a, b) ... end,
anotherhelper = function(c, d) ... end,
}
}
The helpers are added to the domoticz object passed to each script function:
Code: Select all
local x = domoticz.helpers.anotherhelper('bla', 123)
Sounds great! Thanks!