17.01.2019, 12:59
Here's an example of how to create script from another script:
Code:
data = {
-- either event, resident or scheduled
type = 'event',
-- unique script name
name = 'my script',
-- 1 = active, 0 = inactive
active = 1,
-- event script: group address or tag
-- resident script: sleep time in seconds (0..60)
-- scheduled script: execution date/time in CRON format
params = '1/1/1',
-- set to 1 to enable "execute on read" for event scripts
-- not used for resident and scheduled scripts
subparams = 0,
-- script Lua code
script = 'log(123)',
-- optional script category
category = '',
-- optional script description
description = '',
}
-- check for duplicate script with the same name
exists = script.get(data.name)
if not exists then
db:insert('scripting', data)
data.id = db:getlastautoid()
script.save(data, true)
script.reloadsingle(data)
end