Feature request: Include

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

Moderator: leecollings

Post Reply
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Feature request: Include

Post 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
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Feature request: Include

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Feature request: Include

Post by dannybloe »

Besides you can also put files in dzVents/scripts/modules and require from there. It's in the package path.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Feature request: Include

Post 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)
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Feature request: Include

Post 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
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Feature request: Include

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Feature request: Include

Post 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).
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Feature request: Include

Post 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 :)
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Feature request: Include

Post 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 :)
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest