Custom functions in dzVents Domoticz.lua

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Custom functions in dzVents Domoticz.lua

Post 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!
joebar
Posts: 35
Joined: Tuesday 24 January 2017 12:19
Target OS: -
Domoticz version:
Contact:

Re: Custom functions in dzVents Domoticz.lua

Post 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')
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: Custom functions in dzVents Domoticz.lua

Post 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?
joebar
Posts: 35
Joined: Tuesday 24 January 2017 12:19
Target OS: -
Domoticz version:
Contact:

Re: Custom functions in dzVents Domoticz.lua

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

Post 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)
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

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

Who is online

Users browsing this forum: No registered users and 1 guest