24.06.2020, 13:03
Log object you want the average from and use this script
Just make sure not to log too many objects as oldest logs are deleted periodically.
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
------------------------------
Ctrl+F5
Ctrl+F5