Posts: 236 
	Threads: 48 
	Joined: Nov 2015
	
 Reputation: 
 2
	 
 
	
	
		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?
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 5287 
	Threads: 29 
	Joined: Aug 2017
	
 Reputation: 
 237
	 
 
	
	
		Hi 
Why would you want this?  
BR
	 
	
	
------------------------------ 
Ctrl+F5
 
	
		
	 
 
 
	
	
	
		
	Posts: 411 
	Threads: 103 
	Joined: Oct 2016
	
 Reputation: 
 9
	 
 
	
	
		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
 
	
		
	 
 
 
	
	
	
		
	Posts: 236 
	Threads: 48 
	Joined: Nov 2015
	
 Reputation: 
 2
	 
 
	
		
		
		16.01.2019, 06:28 
(This post was last modified: 16.01.2019, 06:29 by FatMax.)
		
	 
	
		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.
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 112 
	Threads: 39 
	Joined: Jul 2017
	
 Reputation: 
 1
	 
 
	
	
		I like the idea of it, I'm sure it would be very useful.
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 8423 
	Threads: 45 
	Joined: Jun 2015
	
 Reputation: 
 481
	 
 
	
	
		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
  
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 236 
	Threads: 48 
	Joined: Nov 2015
	
 Reputation: 
 2
	 
 
	
		
		
		18.01.2019, 07:31 
(This post was last modified: 18.01.2019, 07:32 by FatMax.)
		
	 
	
		Thanks!
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 19 
	Threads: 8 
	Joined: Jan 2020
	
 Reputation: 
 14
	 
 
	
	
		 (17.01.2019, 12:59)admin Wrote:  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
  Hey guys, 
how can i insert a three or four line code there ?
	  
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 8423 
	Threads: 45 
	Joined: Jun 2015
	
 Reputation: 
 481
	 
 
	
	
		Like this: 
Code: str = [[multi 
line 
string]]
  
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 19 
	Threads: 8 
	Joined: Jan 2020
	
 Reputation: 
 14
	 
 
	
	
		 (19.04.2020, 09:27)admin Wrote:  Like this: 
Code: str = [[multi 
line 
string]]
  Thanks Admin.
	  
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 24 
	Threads: 10 
	Joined: Aug 2017
	
 Reputation: 
 0
	 
 
	
	
		 (17.01.2019, 12:59)admin Wrote:  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
  
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) ?
	  
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 8423 
	Threads: 45 
	Joined: Jun 2015
	
 Reputation: 
 481
	 
 
	
	
		Use this: 
Code: script.checkuserlib(common_functions_code) 
script.reload()
  
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 24 
	Threads: 10 
	Joined: Aug 2017
	
 Reputation: 
 0
	 
 
	
	
		 (18.08.2022, 06:35)admin Wrote:  Use this: 
Code: script.checkuserlib(common_functions_code) 
script.reload()
  
Works great, thanks!
	  
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 236 
	Threads: 48 
	Joined: Nov 2015
	
 Reputation: 
 2
	 
 
	
	
		Onto the next question; 
 
Is it also possible to create user libraries with a script?
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 8423 
	Threads: 45 
	Joined: Jun 2015
	
 Reputation: 
 481
	 
 
	
	
		You can use webrequest library in latest firmware to emulate web UI requests: 
Code: 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)
  
	 
	
	
	
		
	 
 
 
	
	
	
		
	Posts: 236 
	Threads: 48 
	Joined: Nov 2015
	
 Reputation: 
 2
	 
 
	
		
		
		15.09.2023, 12:46 
(This post was last modified: 15.09.2023, 13:14 by FatMax.)
		
	 
	
		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
	 
	
	
	
		
	 
 
 
	 
 |