Page 1 of 1

Call another script possible in LUA ?

Posted: Sunday 06 August 2017 10:38
by sebitop
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

Re: Call another script possible in LUA ?

Posted: Sunday 06 August 2017 10:45
by georgesattali
Hello,

to call another script, you can use :

Code: Select all

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

Re: Call another script possible in LUA ?

Posted: Sunday 06 August 2017 14:00
by sebitop
will try it

merci georges :)

Re: Call another script possible in LUA ?

Posted: Thursday 10 August 2017 10:01
by zicht
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