This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Script.create?
#1
I’m increasingly reusing different scripts in projects and as some may know, it might be a tedious effort to create the different scripts and group addresses on each project. 

I’m just wondering if there is a plan to create a sort of script.create function in the software in the near term?
Reply
#2
Hi
Why would you want this?
BR
------------------------------
Ctrl+F5
Reply
#3
I think the idea is clear. If you make a new visualisation for block of N buildings where all houses are the same but group addresses differs (because you use a numbering scheme) then you want to create only one visualisation and copy it N times. This tool is heavily missing at LM. What I suggested (unsuccessfully) was a set of scripts which parse the whole project to (many) Excel sheets. A system implementator can bulk modify what he wants and re-create the project back by another script.
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259
Reply
#4
Thomas use case makes sense, but for me personally it would allow me to build one install script for repetitive functions that depends on event and resident/scheduled scripts and different group addresses that needs to be created.

It would also allow me to install functions remotely from a server and perhaps update scripts with a script.insert command.

I’m sure many users would benefit from this sort of functionality.
Reply
#5
I like the idea of it, I'm sure it would be very useful.
Reply
#6
Here's an example of how to create script from another script:
Code:
1234567891011121314151617181920212223242526272829303132
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
Reply
#7
Thanks!
Reply
#8
(17.01.2019, 12:59)admin Wrote: Here's an example of how to create script from another script:
Code:
1234567891011121314151617181920212223242526272829303132
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
Hey guys,
how can i insert a three or four line code there ?
Reply
#9
Like this:
Code:
123
str = [[multi line string]]
Reply
#10
(19.04.2020, 09:27)admin Wrote: Like this:
Code:
123
str = [[multi line string]]
Thanks Admin.
Reply
#11
(17.01.2019, 12:59)admin Wrote: Here's an example of how to create script from another script:
Code:
1234567891011121314151617181920212223242526272829303132
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

Hi,

I am using this for for 'autosetup' LM with a startup (init) script and it has been very useful. 
Is there any simular way to add functions to 'common functions' (or overwrite the file) ?
Reply
#12
Use this:
Code:
12
script.checkuserlib(common_functions_code) script.reload()
Reply
#13
(18.08.2022, 06:35)admin Wrote: Use this:
Code:
12
script.checkuserlib(common_functions_code) script.reload()

Works great, thanks!
Reply
#14
Onto the next question;

Is it also possible to create user libraries with a script?
Reply
#15
You can use webrequest library in latest firmware to emulate web UI requests:
Code:
123456789101112131415161718192021222324252627282930313233
webrequest = require('webrequest') -- user library name libname = 'test' -- create user library params = {   data = {     id = 'user.' .. libname,     name = libname,     type = 'user',     source = true, -- keep source     load = false, -- autoload     description = 'test description',   } } res, err = webrequest('scripting', 'save', params) log(res, err) -- save user library source params = {   data = {     id = 'user.' .. libname,     scriptonly = true,   },   script = [[     log('test user library')   ]] } res, err = webrequest('scripting', 'save', params) log(res, err)
Reply
#16
Thank you again for the great help. Is this web request library documented anywhere? I would like to also create new Modbus-profiles and this would be very helpful.

I guess search is my friend: https://forum.logicmachine.net/showthread.php?tid=4425
Reply


Forum Jump: