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.

Change trend ga via script
#1
Hello,

recently I've changed a lot of group addresses from humidifier which are the source of trends. How can I update group addresses in Trends via script(trend name correspond with ga name)?

I can update DB but probably it won't be enough like it is with schedulers.

Maybe code would be useful for others in such cases:

Code:
prefix = 'Humidifier 1 - '

-- download trends which contains prefix
query = 'SELECT * FROM trends WHERE name LIKE "' .. prefix .. '%"'
currentRows = db:getall(query)

for _,row in ipairs(currentRows) do
 local id = row.id
 local name = row.name
 local objectId = row.object
 
 local newId = knxlib.encodega(grp.alias(name))
 
 if newId then db:query('UPDATE trends SET object=? WHERE id=?', newId, id) end
end

script.disable(_SCRIPTNAME)
Done is better than perfect
Reply


Forum Jump: