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.

Trends API
#34
Can you try this version, it uses webrequests instead of URL with basic authentication that is not supported anymore in FW 3.0.0 
Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
-- Batch adding trends v1.3 - Created by Erwin van der Zwart - Schneider Electric Netherlands ------------------- -- For spaceLYnk FW 3.0.0 or higher and Wiser for KNX FW 3.0.0 or higher ---------------------------------------- -- Make sure that "Block unsafe functions in scripts" is disbled in General Configuration -- Refresh browser after creation to show the trends ------------------------------------------------------------ ----------------------------------------------- Start Parameters ------------------------------------------------ -- Start address of objects start_objectaddress = '3/0/0' -- Trends for all objects between these range are created -- End address of objects end_objectaddress = '3/0/2' -- Select trend type to create (or multiple types on same object) create_trendtype_counter = false create_trendtype_counter_with_negative_delta = false create_trendtype_absolute_value = true -- Select aggregate function (!Important! Can only be these values: AVERAGE / MIN / MAX / LAST)) trendaggregatefunction = 'AVERAGE' -- Set trend resolution (!Important! Can only be these values: 5 / 10 / 15 / 20 / 30 / 60 minutes)) trendresolution = 5 -- Set trend precicion (!Important! Can only be these values: 0 to 8) decimal places trendprecision = 2 -- Set trend count resolution (!Important! Can only be these values: '30' = 30 days, '180' = 180 days, '365' = 1 year, '730' = 2 years, '1825' = 5 years trendcountresolution = 365 -- Set trend count days (!Important! Can only be these values: '1' = 1 year / '2' = 2 years / '5' = 5 years / '10' = 10 years) trendcountdaily = 10 -- Set show always 0 base line trendshowzero = 0 -- 0 = disabled 1 = enabled ------------------------------------------------ End Parameters ------------------------------------------------- ------------------------------------ DON'T CHANGE ANYTHING UNDER THIS LINE -------------------------------------- -- Calculate start address to DB format start_objectaddress = knxlib.encodega(start_objectaddress) -- Calculate end address to DB format end_objectaddress = knxlib.encodega(end_objectaddress) -- Function to send request (in this case to create a trend) function webrequest(mod, act, vars, data)   require('json')   require('dbenv')   local path   vars = vars or {}   function getvar(v)       return vars[ v ]   end   json.data = function()       return data or {}   end   if mod == 'plugin' then   path = 'plugins/' .. act .. '/web.lua'   else    path = 'web/' .. mod .. '/' .. act .. '.lua'   end   result = dofile('/lib/genohm-scada/' .. path)   -- Calculate results for creation results log   if result.success == true then     number_of_trends = number_of_trends + 1   else     number_failed = number_failed + 1   end end -- Function to create vars function createvars(trend_object, trend_name, trend_type, trend_aggregate_function, trend_resolution, trend_precision, trend_count_resolution, trend_count_daily, trend_show_zero, trend_id)   local vars = {       object = trend_object,       name = trend_name,       type = trend_type,       aggregation = trend_aggregate_function,       resolution = trend_resolution,       precision = trend_precision,     count_resolution = trend_count_resolution * 12 * 24, -- nr of days * nr of points in a hour at min resolution (60/5 = 12) * hours per day     count_daily = trend_count_daily * 365, -- nr of days * 365 days a year       show_zero = trend_show_zero,       id = trend_id,     }   return vars end -- Set counters for creation log number_of_trends = 0 number_failed = 0 -- Loop from startadres to end address to create trends for i = start_objectaddress, end_objectaddress, 1 do     -- Get current group address from loop   current_GA = knxlib.decodega(i)     -- Get current object info   objectinfo = grp.find(current_GA)        -- Check if object excists   if objectinfo ~= nil then            -- Set parameters for request     trendobject = objectinfo.id     trendname = objectinfo.name     trendid = ''         -- Check if trend type 'Counter' should be created     if create_trendtype_counter == true then       -- Call function to create vars       requestdata = createvars(trendobject, trendname, 'C', trendaggregatefunction, trendresolution, trendprecision, trendcountresolution, trendcountdaily, trendshowzero, trendid)       webrequest('trends', 'save', {request = 'save'}, requestdata)     end         -- Check if trend type 'Counter with negative delta' should be created     if create_trendtype_counter_with_negative_delta == true then             -- Call function to send create vars       requestdata = createvars(trendobject, trendname, 'D', trendaggregatefunction, trendresolution, trendprecision, trendcountresolution, trendcountdaily, trendshowzero, trendid)       webrequest('trends', 'save', {request = 'save'}, requestdata)     end         -- Check if trend type 'Absolute value' should be created     if create_trendtype_absolute_value == true then             -- Call function to send create vars       requestdata = createvars(trendobject, trendname, 'G', trendaggregatefunction, trendresolution, trendprecision, trendcountresolution, trendcountdaily, trendshowzero, trendid)       webrequest('trends', 'save', {request = 'save'}, requestdata)     end       end   end     if number_failed == 0 then     log ("Created " .. number_of_trends .. " trends succesfully") else     log ("Created " .. number_of_trends .. " trends succesfully and creation of " .. number_failed .. " trends failed") end -- Disable script when done automaticly script.disable(_SCRIPTNAME)
Reply


Messages In This Thread
Trends API - by buuuudzik - 28.05.2016, 16:52
RE: Trends API - by Habib - 28.05.2016, 17:13
RE: Trends API - by Erwin van der Zwart - 28.05.2016, 22:01
RE: Trends API - by admin - 29.05.2016, 06:12
RE: Trends API - by buuuudzik - 29.05.2016, 11:22
RE: Trends API - by Erwin van der Zwart - 02.09.2016, 18:46
RE: Trends API - by admin - 05.09.2016, 06:01
RE: Trends API - by Erwin van der Zwart - 05.09.2016, 09:29
RE: Trends API - by Pawel - 07.12.2016, 20:15
RE: Trends API - by Domoticatorino - 19.02.2018, 15:39
RE: Trends API - by Erwin van der Zwart - 19.02.2018, 16:32
RE: Trends API - by Domizy - 18.12.2024, 14:24
RE: Trends API - by Domoticatorino - 13.02.2018, 16:52
RE: Trends API - by Daniel - 13.02.2018, 18:49
RE: Trends API - by Domoticatorino - 19.02.2018, 16:33
RE: Trends API - by PassivPluss - 17.09.2019, 21:10
RE: Trends API - by admin - 24.09.2019, 06:53
RE: Trends API - by Trond Hoyem - 17.06.2022, 12:57
RE: Trends API - by admin - 17.06.2022, 13:20
RE: Trends API - by Trond Hoyem - 17.06.2022, 13:23
RE: Trends API - by admin - 17.06.2022, 13:23
RE: Trends API - by Trond Hoyem - 17.06.2022, 13:27
RE: Trends API - by admin - 17.06.2022, 13:30
RE: Trends API - by Trond Hoyem - 17.06.2022, 13:33
RE: Trends API - by admin - 17.06.2022, 13:34
RE: Trends API - by Trond Hoyem - 17.06.2022, 13:36
RE: Trends API - by admin - 17.06.2022, 14:15
RE: Trends API - by Trond Hoyem - 17.06.2022, 14:26
RE: Trends API - by admin - 17.06.2022, 14:32
RE: Trends API - by Daniel - 18.12.2024, 14:51
RE: Trends API - by Domizy - 18.12.2024, 15:06
RE: Trends API - by Daniel - 18.12.2024, 15:29
RE: Trends API - by Domizy - 18.12.2024, 15:39
RE: Trends API - by Erwin van der Zwart - 19.12.2024, 14:57
RE: Trends API - by Domizy - 19.12.2024, 17:30

Forum Jump: