LogicMachine Forum
Min/Max last 24h - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Min/Max last 24h (/showthread.php?tid=6159)



Min/Max last 24h - erikfluff - 17.10.2025

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?


RE: Min/Max last 24h - Daniel - 17.10.2025

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



RE: Min/Max last 24h - erikfluff - 17.10.2025

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?


RE: Min/Max last 24h - Daniel - 17.10.2025

Check the logs and see if your sensor actually logged negative value. It works for me with negative.


RE: Min/Max last 24h - admin - 17.10.2025

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