Logic Machine Forum
Too long since last update - Printable Version

+- Logic Machine 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: Too long since last update (/showthread.php?tid=1664)



Too long since last update - chriscroko - 20.10.2018

Hi, 

I would like to do the following: 
- tag all temperature readings
- search up these temperature readings that are tagged
- get the oldest timestamp 
- if timestamp is older than two hours 
= write a boolean 1 on a group address 

This way I could indicate that there is a sensor on my installation that is not sending the current temperature anymore. 

Hope this could be done with a script. In advance thanks.  Cool

-CDG


RE: Too long since last update - Erwin van der Zwart - 20.10.2018

Hi,

I think you need something like this:

Code:
output = false
max_timestamp = os.time() - 7200 -- 2 hours in seconds
for _, object in ipairs(grp.tag('temperature')) do
 if object.updatetime < max_timestamp then
   output = true
   break
 end
end
grp.checkwrite('1/1/1', output)

BR,

Erwin


RE: Too long since last update - chriscroko - 21.10.2018

That did the trick! Thank you very much.  Smile