Logic Machine Forum
Easy and fast way to make many similar Rooms in Visualization. Copy of rooms - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: Easy and fast way to make many similar Rooms in Visualization. Copy of rooms (/showthread.php?tid=1249)



Easy and fast way to make many similar Rooms in Visualization. Copy of rooms - DarthPaul - 23.02.2018

Thanks to Daniel i, 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


RE: Easy and fast way to make many similar Rooms in Visualization. Copy of rooms - Thomas - 23.02.2018

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.


RE: Easy and fast way to make many similar Rooms in Visualization. Copy of rooms - Daniel - 26.02.2018

Hi Paul
It took you a while to upload... Wink
BR


RE: Easy and fast way to make many similar Rooms in Visualization. Copy of rooms - PassivPluss - 16.10.2019

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


RE: Easy and fast way to make many similar Rooms in Visualization. Copy of rooms - Daniel - 16.10.2019

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


RE: Easy and fast way to make many similar Rooms in Visualization. Copy of rooms - khalil - 07.03.2022

Hello 
How to use it with widgets instead of plans?

Best Regards,


RE: Easy and fast way to make many similar Rooms in Visualization. Copy of rooms - admin - 07.03.2022

Widgets are stored the same way as plans so this script should work as is.


RE: Easy and fast way to make many similar Rooms in Visualization. Copy of rooms - khalil - 08.03.2022

(07.03.2022, 12:11)admin Wrote: Widgets are stored the same way as plans so this script should work as is

Thanks Admin,


RE: Easy and fast way to make many similar Rooms in Visualization. Copy of rooms - Alberto.ricof - 15.09.2023

Hello!!

I have a project with an address scheme already done, and that unfortunately was done before I discovered this post....

The structure is as follows: (it's a hotel)
MainGroup/Middelgroup = room number
Subgroup = Action

For example:
1/1/1 On Off Light bed room 1
1/1/2 Status light bed room 1
1/1/3 Temperature Room 1

So the main group and the intermediate group delimit the room.

The Subgroup addresses are always the same in all rooms:

1/1/1 On Off Bed light room 1
9/8/1 On Off light bed room 98

Would it be possible to modify the scritpt for this type of structure?

Thank you in advance, it would be great to use it.

br.
Alberto


RE: Easy and fast way to make many similar Rooms in Visualization. Copy of rooms - admin - 18.09.2023

Group address formula is X/Y/Z => X * 2048 + Y * 256 + Z. For example, 2305 (1/1/1) + 2048 = 4353 (2/1/1) or 2305 (1/1/1) + 3 * 256 = 3073 (1/4/1).
9/8/1 is not a valid fixed address as the middle part must be between 0 and 7. If rooms go one after another you can simply use ADDR + (ROOM - 1) * 256 to calculate the next address. You can use buslib.encodega(addr) to convert address in 'X/Y/Z' string form to numerical form.


RE: Easy and fast way to make many similar Rooms in Visualization. Copy of rooms - Alberto.ricof - 22.09.2023

(18.09.2023, 09:00)admin Wrote: Group address formula is X/Y/Z => X * 2048 + Y * 256 + Z. For example, 2305 (1/1/1) + 2048 = 4353 (2/1/1) or 2305 (1/1/1) + 3 * 256 = 3073    (1/4/1).
9/8/1 is not a valid fixed address as the middle part must be between 0 and 7. If rooms go one after another you can simply use ADDR + (ROOM - 1) * 256 to calculate the next address. You can use buslib.encodega(addr) to convert address in 'X/Y/Z' string form to numerical form.

Thank you very much for your information,

Best regards,