Page 1 of 1

dzVents global variables

Posted: Sunday 26 November 2017 11:35
by Inso
Hi,

my lua script had some IP adresses as local variables, f.e.

Code: Select all

local IPR1 = {'192.168.178.44', '192.168.178.49', '192.168.178.50', '192.168.178.48'}
PORT = '55443'
       for n, IP in pairs(IPR1) do
               runcommandoff = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":[\"cf\",4,1,\"500,1,16711680,1,    900000,7,0,0, 900000,2,1700,1, 900000,2,1700,100 \"]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."&";;     os.execute(runcommandoff);
On dzVents, within the execute function, it also works fine. Now i´d like to set them as global variables, as they are not changed and used often. Seems they are recognized as floating numbers, I found no way to get 'em to work the same way as in the execute function.

Re: dzVents global variables

Posted: Sunday 26 November 2017 15:02
by dannybloe
Read the documentation about global helper functions. You can use it also for other stuff. In your global_data.lua add this:

Code: Select all

return {
	helpers = {
		IPR1 = {'192.168.178.44', '192.168.178.49', '192.168.178.50', '192.168.178.48'}
	}
}
In another script you can use it like this:

Code: Select all

print(domoticz.helpers.IPR1[1]) -- will print 192.168.178.44