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:
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