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.

Mass generating new GAs via script
#1
Here there is a script for mass generate new GAs via script according to specified template and rules. It can save a lot of time and clicking but before do some BACKUP.

Code:
-- GENERATE all group addresses according to specified template and conditions
firstId, lastId = 1, 10 -- e.g. Blind1 to Blind10

canChangeMiddle = true -- if yes can change e.g. 0/0/255 -> 0/1/0
canChangeMain = false -- if yes can change e.g. 0/7/255 -> 1/0/0
offset = 10 -- address offset between first GA in 2 devices e.g. Blind41_up/down - Blind40_up/down = 0/0/20 - 0/0/10 = 10

curMain, curMiddle, curSub = 0, 0, 0 -- initial GA e.g. 1, 2, 3 means 1/2/3
numberOfAddedGAs, numberOfNotAddedGAs = 0, 0 -- init the counters of new or updated objects and not created objects
for curId = firstId, lastId, 1 do
 curSubMax = curSub + 7 -- maximum subaddress in current iteration
 
 if curSubMax > 255 and canChangeMiddle then
   if ((curMiddle + 1) <= 7) then curSub, curMiddle = 0, curMiddle + 1
   else
     if canChangeMain and (curMain + 1) <= 15 then curSub, curMiddle, curMain = 0, curMiddle + 1, curMain + 1
     else log('Cannot increment main group.'); break end
   end
 elseif (curSubMax > 255 and not canChangeMiddle) then log('Cannot increment middle group.'); break end
 
 curMainAndMiddle = curMain .. '/' .. curMiddle .. '/'
 template = {
   {datatype = dt.bool, address = curMainAndMiddle .. curSub + 1, name = 'Blind' .. curId .. '_up/down'},
   {datatype = dt.bool, address = curMainAndMiddle .. curSub + 2, name = 'Blind' .. curId .. '_step/stop'},
   {datatype = dt.uint8, address = curMainAndMiddle .. curSub + 3, name = 'Blind' .. curId .. '_scene'},
   {datatype = dt.scale, address = curMainAndMiddle .. curSub + 4, name = 'Blind' .. curId .. '_height'},
   {datatype = dt.scale, address = curMainAndMiddle .. curSubMax, name = 'Blind' .. curId .. '_height status'} -- Maximum subaddress
 };
 
 for k,v in ipairs(template) do
   res = grp.create(v)
   if res then numberOfAddedGAs = numberOfAddedGAs + 1 else numberOfNotAddedGAs = numberOfNotAddedGAs + 1 end
 end
 
 curSub = curSub + offset
end

message = ''
if numberOfAddedGAs > 0 then message = 'Successfully added or updated ' .. numberOfAddedGAs .. ' new GAs. ' end
if numberOfNotAddedGAs > 0 then message = message .. 'There was ' .. numberOfNotAddedGAs .. ' errors(not added or updated objects).' end
if numberOfAddedGAs > 0 or numberOfNotAddedGAs > 0 then log(message) end

script.disable(_SCRIPTNAME)
Reply


Messages In This Thread
Mass generating new GAs via script - by buuuudzik - 21.02.2018, 16:37

Forum Jump: