Page 1 of 1

Feature request: Include

Posted: Wednesday 07 March 2018 12:58
by poudenes
Hi All,

In many scripts i have local variables to define devices.
Maybe its a idea to have 1 lua file that keeps all de local variables collection you use in all your scripts.

Then every script will have only 1 line to have the locals

include "locallist.lua" or include "/home/pi/domoticz/scripts/dzVents/scripts/local.lua"

i tried the include and require but get lot of errors ;)

Cheers,
Peter

Re: Feature request: Include

Posted: Wednesday 07 March 2018 13:48
by dannybloe
Better put it in global_data and add it to the helper section. Then it is available in all your files. See the documentation about global_data and helper functions.

Re: Feature request: Include

Posted: Wednesday 07 March 2018 13:56
by dannybloe
Besides you can also put files in dzVents/scripts/modules and require from there. It's in the package path.

Re: Feature request: Include

Posted: Wednesday 07 March 2018 14:14
by poudenes
hmm ok. only what i want is have this list (original is longer) so i can use them in every script. Instead to add them in every script.

Code: Select all

local SceneDaytime	= domoticz.devices(82)
local SceneEvening = domoticz.devices(83)
local SceneTV = domoticz.devices(84)
local SceneMovie = domoticz.devices(85)
local SceneAppleTV = domoticz.devices(86)
local SceneSexy = domoticz.devices(87)
local SceneMorning = domoticz.devices(88)
local SceneGoodnight = domoticz.devices(89)

Re: Feature request: Include

Posted: Wednesday 07 March 2018 14:34
by poudenes
and there is no dzVents/scripts/modules folder. Doc: /path/to/domoticz/scripts/dzVents/modules or /path/to/domoticz/scripts/dzVents/scripts/modules
both are not there

Re: Feature request: Include

Posted: Thursday 08 March 2018 9:08
by waaren
poudenes wrote: Wednesday 07 March 2018 14:34 and there is no dzVents/scripts/modules folder. Doc: /path/to/domoticz/scripts/dzVents/modules or /path/to/domoticz/scripts/dzVents/scripts/modules
both are not there
Hopefully you realized by now that you have to create that subdirectory yourself ?

Re: Feature request: Include

Posted: Thursday 08 March 2018 9:18
by dannybloe
poudenes wrote: Wednesday 07 March 2018 14:14 hmm ok. only what i want is have this list (original is longer) so i can use them in every script. Instead to add them in every script.

Code: Select all

local SceneDaytime	= domoticz.devices(82)
local SceneEvening = domoticz.devices(83)
local SceneTV = domoticz.devices(84)
local SceneMovie = domoticz.devices(85)
local SceneAppleTV = domoticz.devices(86)
local SceneSexy = domoticz.devices(87)
local SceneMorning = domoticz.devices(88)
local SceneGoodnight = domoticz.devices(89)
This is not going to work as the domoticz object is only locally available inside your execute function (parameter). So if you would require that shared module with these declarations then there is no domoticz object. And.. you declare them local so they would only be local to your module (but that's beside the point).

Re: Feature request: Include

Posted: Thursday 08 March 2018 10:01
by poudenes
waaren wrote: Thursday 08 March 2018 9:08
poudenes wrote: Wednesday 07 March 2018 14:34 and there is no dzVents/scripts/modules folder. Doc: /path/to/domoticz/scripts/dzVents/modules or /path/to/domoticz/scripts/dzVents/scripts/modules
both are not there
Hopefully you realized by now that you have to create that subdirectory yourself ?
yep :)

Re: Feature request: Include

Posted: Thursday 08 March 2018 10:01
by poudenes
dannybloe wrote: Thursday 08 March 2018 9:18
poudenes wrote: Wednesday 07 March 2018 14:14 hmm ok. only what i want is have this list (original is longer) so i can use them in every script. Instead to add them in every script.

Code: Select all

local SceneDaytime	= domoticz.devices(82)
local SceneEvening = domoticz.devices(83)
local SceneTV = domoticz.devices(84)
local SceneMovie = domoticz.devices(85)
local SceneAppleTV = domoticz.devices(86)
local SceneSexy = domoticz.devices(87)
local SceneMorning = domoticz.devices(88)
local SceneGoodnight = domoticz.devices(89)
This is not going to work as the domoticz object is only locally available inside your execute function (parameter). So if you would require that shared module with these declarations then there is no domoticz object. And.. you declare them local so they would only be local to your module (but that's beside the point).
Ah ok. Thanks. Then i'll let it as it is :)