Call another script possible in LUA ?

Moderator: leecollings

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

Call another script possible in LUA ?

Post 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
domoticz on Raspberry Pi + RFXcom LAN moded + wifi
Blyss / DI.O / homemade / ESP / wemos
georgesattali
Posts: 84
Joined: Saturday 05 March 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Call another script possible in LUA ?

Post by georgesattali »

Hello,

to call another script, you can use :

Code: Select all

dofile('/home/pi/domoticz/scripts/lua/anotherscript.lua')
Bye
GD
sebitop
Posts: 69
Joined: Sunday 08 June 2014 20:31
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Toulouse France
Contact:

Re: Call another script possible in LUA ?

Post by sebitop »

will try it

merci georges :)
domoticz on Raspberry Pi + RFXcom LAN moded + wifi
Blyss / DI.O / homemade / ESP / wemos
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Call another script possible in LUA ?

Post 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
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest