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.

Comparing value with average tendence
#5
As Daniel said you need to enable logging for this object and use data from the objects logs. Make sure that the object log size (Utilities > General configuration) is large enough to store data for the last 4 days.

Since you want to check for temperature variation you probably need to find the difference between the minimum and maximum temperature in the given period instead of using average. Here's how you can find min/max:
Code:
logaddress = '32/1/7'
obj = grp.find(logaddress)
time = os.time() - 86400 * 4 -- last 4 days

logs = db:getall('SELECT * FROM objectlog WHERE address=? AND logtime>?', obj.id, time)

for _, item in ipairs(logs) do
  value = busdatatype.decode(item.datahex, obj.datatype)
  min = min and math.min(min, value) or value
  max = max and math.max(max, value) or value
end

log(min, max)
Reply


Messages In This Thread
RE: Comparing value with average tendence - by admin - 26.03.2021, 06:25

Forum Jump: