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 whether you accept or reject these cookies being set.

Easy and fast way to make many similar Rooms in Visualization. Copy of rooms
#1
Thanks to Daniel Moraczewski, I managed to create this script to Copy Rooms in Visualization, and automatically reorganize the Groupaddresses in the new rooms. This is greatly redusing the timeconsumtion in setup.

Step 1 
is to organize the groupaddress structure. For the example under, we have to use the following structure,
MainGroup = Action --> Like 6 is Temperature, 2 is Light on/Off etc..
MiddleGroup = Floor
SubGroup  = Room
This give us 6/2/3 is Temperature in room 3 in the 2 floor.
and 2/2/3 is light on/off in the same room
4/2/3 is heat-drive, same room

Step 2
Make the Visualization for the first room. 
Use the proper Group-addresses and organize it the way all rooms need to look.
Use this as a default. 
In Vis. Structure, make several copies of this room. 
IMPORTANT Name the Copy: Copy (MiddleGroup)(Subgroup) 
We then have the following rooms in Vis Structure:
Copy 201
Copy 202
Room 203
Copy 204
Copy 213
Copy 240
Copy 201

Step 3
Run the script under from resident. (Note: script will auto-disable itself at the end, since this only need to run once.)
Script will change all objects in all Rooms named: "Copy*" to be linked to the corresponding Middle and subgroup, leaving Main-group unchanged.
This will change hundreds of group-addresses in seconds.

Step 4
After Script, in Vis. Structure, change name to wanted name, and add PIN codes etc. as needed. In Visualization edit all Labels, and texts as wanted (like heading for room-name) 

Script to be inserted in resident:
Code:
--This script will automatically replace middle group and group in KNX addres based on room number.
--For example if room name is Copy 315 then all object on this plan will have addressing X/3/15---
--Script will replace only roome which name will start from 'roomSearch' parameter. This can be modified as many times as it is needed.
--Be carefull, wrongly used can destroy whole project. Always make buckup before running the script
--Script will disable itself after it is finished.

roomSearch = 'Copy' -- set constant name which will be starting plan name.


----------------------------------------------------------------------------------------------------------
-------------------------------DO NOT CHANGE ANYTHING BELOW THIS LINE-------------------------------------

roomSearch = roomSearch..'%'

dbfloors = db:getall('SELECT id, name FROM visfloors WHERE name LIKE '..'"'..roomSearch..'"'..' ')

for _, floorsData in ipairs(dbfloors) do
 floorID  = floorsData.id
 roomName = floorsData.name
 roomNumber = string.match(roomName, "%d+")
 middleGroup = tonumber(string.sub(roomNumber, 1,1))
 group = tonumber(string.sub(roomNumber, 2, 3))
 
 dbobjects = db:getall('SELECT id, type, object, statusobject FROM visobjects WHERE floor = ' .. floorID .. ' AND type < "2"  ')
 
 for _, objectData in ipairs(dbobjects) do
   
   mainGroupControl = bit.rshift(objectData.object, 11)
   mainGroupStatus = bit.rshift(objectData.statusobject, 11)
   
 oldControlAddress = objectData.object
 oldStatusAddress = objectData.statusobject
 currentRow = objectData.id
 newControlAddress = ((mainGroupControl * 2048) + (middleGroup * 256) + group)
 newStatusAddress = ((mainGroupStatus * 2048) + (middleGroup * 256) + group)
 
--  log('oldControlAddress= '..tostring(oldControlAddress)..', currentRow= '..tostring(currentRow)..', newControlAddress= ' ..tostring(newControlAddress)..', newStatusAddress= ' ..tostring(newStatusAddress) )
 db:update('visobjects', { object = newControlAddress }, { id = currentRow })
 if (oldControlAddress == oldStatusAddress) then --if no status object selected main object must be used
 db:update('visobjects', { statusobject = newControlAddress }, { id = currentRow })
    else
 db:update('visobjects', { statusobject = newStatusAddress }, { id = currentRow })
    end
   
 end  
 
 
end  

log('update finished')
script.disable(_SCRIPTNAME)


PS: 
This script is only for Subgroup 0-99 (room X00 to X99)
If 0-255 is needed, change room-names to Copy X001 to X255
And change in script: 
group = tonumber(string.sub(roomNumber, 2, 3)) 
into:
group = tonumber(string.sub(roomNumber, 2, 4))

PPS:
Allthoug I myself have had a lot off fault free success with this:
This scrips is messing with the database in LM, (as always) make sure to Backup before you test it, just in case we screw it up





Never underestimate the dark power of Scripting
Reply
#2
Hi
Isn't there anybody who has scripts that distill objects from json export a window to Excel sheet and another that takes data from Excel (CVS etc) and imports it back to the originally exported json? I think it can be done using powershell etc and I'm planning to do it but it would be nice if someone has already done it.
LM5Lp, firmware: 2018.08.22, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151
Reply
#3
Hi Paul
It took you a while to upload... Wink
BR
Reply
#4
Hi
Is it possible to edit this script to use group adress names instead of adress? Like if object in orginal visu name is 203 office temperature, change this to 201 office temperature and so on. In current project everything is already programmed but the group names are logical
Reply
#5
Hi
It is, line 34-35 has to be corrected. You will need to convert address to KNX format then based on this get object name, convert the name as you need and then get new knx address. As last point you need to convert KNX based address to raw number.
BR
Reply


Forum Jump: