(02.07.2019, 05:59)fabiorusco Wrote:(01.07.2019, 10:54)admin Wrote: Do you need to replace group addresses in script source code only or trigger group addresses for event scripts as well?I need change both, groups addresses in the script sand the trigger groups addresses.
Hello, I made alike script for shifting all adresses through db updating today. It shifts all ga with a step in modbus mapping, visualization, trends, object logs and a trigger for event scripts. Also it can change name of ga.
Code:
log('start')
a = grp.all()
step = -( 1 * 2^11 + 2 * 2^8 + 3 ) -- shift for -(1/2/3)
for i = 1, #a, 1 do -- if step < 0
--for i = #a, 1, -1 do -- if step > 0
old_id = a[i].id
id = old_id + step
knx_addr = knxlib.decodega(id)
old_knx = knxlib.decodega(old_id)
old_name = a[i].name
new_name = 'Shifted ' .. old_name
-- change ga
sql_query = "UPDATE objects SET id=?, rowid=?, address=? WHERE id=?"
db:query(sql_query, id, id, id, old_id)
-- update name
sql_query = "UPDATE objects SET name=? WHERE name=?"
db:query(sql_query, new_name, old_name)
--update modbus ga mapping
sql_query = "UPDATE modbus_mapping SET bus_address=? WHERE bus_address=?"
db:query(sql_query, id, old_id)
-- update visualization objects
sql_query = "UPDATE visobjects SET object=? WHERE object=?"
db:query(sql_query, id, old_id)
sql_query = "UPDATE visobjects SET statusobject=? WHERE statusobject=?"
db:query(sql_query, id, old_id)
-- update ga in object logs
sql_query = "UPDATE objectlog SET address=? WHERE address=?"
db:query(sql_query, id, old_id)
-- update ga for trends
sql_query = "UPDATE trends SET object=? WHERE object=?"
db:query(sql_query, id, old_id)
-- I don't think that it's necessary, but update tags for ga
sql_query = "UPDATE objecttags SET object=? WHERE object=?"
db:query(sql_query, id, old_id)
-- update ga in scheluders
sql_query = "UPDATE schedulers SET object=? WHERE object=?"
db:query(sql_query, id, old_id)
-- update trigger ga for event scripts
sql_query = "UPDATE scripting SET params=? WHERE params=?"
db:query(sql_query, knx_addr, old_knx)
end
log('end')
For changing scripts you can try this:
Code:
function shift_knx(addr)
step = 0 * 2^11 + 1 * 2^8 + 0
decode_knx = knxlib.encodega(addr)
new_knx = decode_knx + step
new_addr = knxlib.decodega(new_knx)
return new_addr
end
scripts = db:getall("SELECT script FROM scripting")
for i = 1, #scripts, 1 do
new_script = string.gsub(scripts[i].script, "%d+/%d+/%d+", shift_knx)
db:query("UPDATE scripting SET script=? WHERE script=?", new_script, scripts[i].script)
end
Script was very simple just for testing:
Code:
log(grp.getvalue('0/0/23'))
Both of this scripts were tested on 20180828 LM Firmware. Homelynk can have little difference in db structure.
If you have any questions, I'll try to answer =)