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.

Get last 20 minutes average value of object
#2
Log object you want the average from and use this script

Code:
logaddress = '1/2/0'
pastTime   = 1200  --in seconds


addr = grp.find(logaddress)
time= os.time() - pastTime

objects = db:getall('SELECT dataraw, logtime, datahex FROM objectlog WHERE address =' .. addr.id .. ' AND logtime >'.. time )

local result, count, value = 0, 0

    for _, objvalue in ipairs(objects) do
  value = busdatatype.decode(objvalue.datahex, addr.datatype)
      result = result + value
    count = count + 1
    end


  if count > 0 then
    result = math.floor(result / count + 0.5)
      log(result)
  end
Just make sure not to log too many objects as oldest logs are deleted periodically.
------------------------------
Ctrl+F5
Reply


Messages In This Thread
RE: Get last 20 minutes average value of object - by Daniel - 24.06.2020, 13:03

Forum Jump: