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.

Min/Max last 24h
#1
Hi!

I have a copuple of temperature and wind speed sensors attached to my Wiser4KNX and i would like to present min and max temp and wind speed for the last 24 hours. Anyone who can point me in the right direction?
Reply
#2
You can try this way, log your object for a day and then use this script, change logaddress and pastTime as needed. 
Code:
logaddress = '32/1/3'
pastTime   = 60*60*1  --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, value = 0,0

    for _, objvalue in ipairs(objects) do
  value = busdatatype.decode(objvalue.datahex, addr.datatype)
 
        result = math.max(result, value)
   end
log(result) --max



    for _, objvalue in ipairs(objects) do
  value = busdatatype.decode(objvalue.datahex, addr.datatype)
      result = math.min(result, value)
   end
log(result) --min
------------------------------
Ctrl+F5
Reply
#3
Thank you, seems to work fine!

I tried to change to mat.min too, but i didnt get a negative value, just 0,0, even though it has been colder during the last couple of nights. Any ideas?
Reply
#4
Check the logs and see if your sensor actually logged negative value. It works for me with negative.
------------------------------
Ctrl+F5
Reply
#5
Max:
Code:
result = -math.huge

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

log(result) --max

Min:
Code:
result = math.huge

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

log(result) --min
Reply


Forum Jump: