LogicMachine Forum
Change trend ga via script - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Change trend ga via script (/showthread.php?tid=1714)



Change trend ga via script - buuuudzik - 11.11.2018

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)