Function within dzVents script?  [Solved]

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

Moderator: leecollings

Post Reply
doh
Posts: 82
Joined: Monday 01 December 2014 13:28
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: London, UK
Contact:

Function within dzVents script?

Post by doh »

Hi

I have a dzVents script that performs the same tasks 2 or 3 times depending on whether it was triggered by a timer or by one of a number of devices.

Is it possible to define a function within that script which I can call repeatedly for each case?

I know you can create global "helper" functions, but I'd prefer to keep it within the one script file.

Thanks
dlube
Posts: 29
Joined: Tuesday 31 March 2020 19:29
Target OS: -
Domoticz version:
Location: France

Re: Function within dzVents script?  [Solved]

Post by dlube »

For sure :D
Have a look to the example below

Code: Select all

return {
     ...
	execute = function(dz, item)
          local function myFunction(variable)
               ...
               do your stuff
               ...
               return result1, result2
          end

local a, b = myFunction(myVariable)
...
end
}
you can call this function from your code like you do with helpers.
Raspbian Buster on Raspberry pi 3 B+ Domoticz Version: 2023.2 (build 15474)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest