04.03.2017, 23:15
(This post was last modified: 06.03.2017, 06:31 by Erwin van der Zwart.)
Hi,
Use the filters before changing tags on objects that already has tags.
Question : Why don't you want to use script for adding tags to objects? The only extra handling is creating a temp script container. There are very powerfull script commands to do this, do you know them?
Some simple samples:
1) Add tags based on name (partial), existing tags will be untouched
2) Add tags based on DPT, existing tags will be untouched
BR,
Erwin
Use the filters before changing tags on objects that already has tags.
Question : Why don't you want to use script for adding tags to objects? The only extra handling is creating a temp script container. There are very powerfull script commands to do this, do you know them?
Code:
grp.gettags(alias)
grp.addtags(alias, tags)
grp.removetags(alias, tags)
grp.removealltags(alias)
grp.settags(alias, tags) -- methode mass update uses, overwrite all existing tags
Some simple samples:
1) Add tags based on name (partial), existing tags will be untouched
Code:
-- Start address of objects
start_objectaddress = '1/1/1'
-- End address of objects
end_objectaddress = '15/7/255'
-- Set Tag(s)
tags = {'Tag 1' , 'Tag 2' , 'Tag 3'} -- Multiple tags
-- Calculate start address to numeric format
start_objectaddress = knxlib.encodega(start_objectaddress)
-- Calculate end address to numeric format
end_objectaddress = knxlib.encodega(end_objectaddress)
-- Get all objects
result = grp.all()
-- Loop through all objects
for _, object in ipairs(result) do
-- Only update objects within the start - end range
if object.id >= start_objectaddress and object.id <= end_objectaddress then
-- Only add tags when object name partial matches
partial = 'Test'
if string.match(object.name, partial) then
grp.addtags(knxlib.decodega(object.id), tags)
end
end
end
-- Self disable script
script.disable(_SCRIPTNAME)
2) Add tags based on DPT, existing tags will be untouched
Code:
-- Start address of objects
start_objectaddress = '1/1/1'
-- End address of objects
end_objectaddress = '15/7/255'
-- Set Tag(s)
tags = 'Tag 1' -- Single tag
-- Calculate start address to numeric format
start_objectaddress = knxlib.encodega(start_objectaddress)
-- Calculate end address to numeric format
end_objectaddress = knxlib.encodega(end_objectaddress)
-- Get objects by dtp type
result = grp.dpt(dt.float16, false) -- set to true for only exact dpt, now all 2 byte objects matches
-- Loop through all objects
for _, object in ipairs(result) do
-- Only update objects within the start - end range
if object.id >= start_objectaddress and object.id <= end_objectaddress then
grp.addtags(knxlib.decodega(object.id), tags)
end
end
-- Self disable script
script.disable(_SCRIPTNAME)
BR,
Erwin