Call another script possible in LUA ?

Post Reply
sebitop
Posts: 155
Joined: Sunday 08 June 2014 20:31
Target OS: Raspberry Pi
Domoticz version:
Location: Toulouse France
Contact:

Call another script possible in LUA ?

Post by sebitop » Sunday 06 August 2017 10:38

Hi all,

maybe a stupid question I will ask but is it possible to call a LUA script from another ?

why i'm asking this ? simply because on my side I have several time scripts which are activated every minute, if some of them are used to control the state of some devices, others are scripts running once a day (like blind close or one to define new variable everyday).

then my idea was to run a single script testing the current time and then if the time is equal to launch another complex one.

Yes I could try dzvents but I don't have the time yet to convert all my current scripts
Yes I could run everything in a single script (complex to debug)

thanks for your help

seb
domoticz on Raspberry Pi + RFXcom
RSL/ blyss blind / DI.O switches / FOSCAM / + homemade

georgesattali
Posts: 100
Joined: Saturday 05 March 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Re: Call another script possible in LUA ?

Post by georgesattali » Sunday 06 August 2017 10:45

Hello,

to call another script, you can use :

Code: Select all

dofile('/home/pi/domoticz/scripts/lua/anotherscript.lua')
Bye
GD

sebitop
Posts: 155
Joined: Sunday 08 June 2014 20:31
Target OS: Raspberry Pi
Domoticz version:
Location: Toulouse France
Contact:

Re: Call another script possible in LUA ?

Post by sebitop » Sunday 06 August 2017 14:00

will try it

merci georges :)
domoticz on Raspberry Pi + RFXcom
RSL/ blyss blind / DI.O switches / FOSCAM / + homemade

zicht
Posts: 174
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 3.8xxx
Location: NL
Contact:

Re: Call another script possible in LUA ?

Post by zicht » Thursday 10 August 2017 10:01

You could also use functions, put major stuff there and then call that from a device or time script...

Code: Select all

package.path = package.path .. ';' .. 'C:/PROGRA~2/domoticz/scripts/lua/functions.lua;'
local my1 = require ("functions")
example in function.lua

Code: Select all

function round(num, numDecimalPlaces)
  if numDecimalPlaces and numDecimalPlaces>0 and num~=nil and num~=0 then
    local mult = 10^numDecimalPlaces
    return math.floor(num * mult + 0.5) / mult
  end
  return math.floor(num + 0.5)
end
and you can call that in time.lua

Code: Select all

package.path = package.path .. ';' .. 'C:/PROGRA~2/domoticz/scripts/lua/functions.lua;'
local my1 = require ("functions")


commandArray = {}

x=3.141627890876546
y= round(x,2)


.....

return commandArray
y will contain only 3.14
Rpi & Win x64. Using : cam's,Nest,RFXCom,Kaku,LaCrosse,RFY,IsAlive,Dummy,Wether Underground, standard Lua, Curl on windows,Domoticz Android App & Tasker,

"The only source of knowledge is experience (A.Einstein)"

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests