Logic Machine Forum
Tag value chek function - 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: Tag value chek function (/showthread.php?tid=4319)



Tag value chek function - a455115 - 24.10.2022

Hello,

I need a function that checks objects by tag once a day and if the value of any of the objects is below 50 to send an email with the name of the object and its value. Also if the object has not updated its value for more than 2 hours also send an email.


RE: Tag value chek function - admin - 25.10.2022

Use this:
Code:
objs = grp.tag('mytag')
mindelta = 2 * 60 * 60 -- 2 hours

now = os.time()
errors = {}

for _, obj in ipairs(objs) do
  delta = now - obj.updatetime

  if delta >= mindelta or obj.value < 50 then
    errors[ #errors + 1 ] = string.format('Name: %s, Value: %d, Updated: %s',
      obj.name, obj.value, os.date('%c', obj.updatetime))
  end
end

if #errors > 0 then
  text = table.concat(errors, '\n')
  log(text)
end



RE: Tag value chek function - a455115 - 26.10.2022

Thank you very much! As always it works. I can't just force every event to be on a new line in the email with /n not working.


RE: Tag value chek function - admin - 26.10.2022

Try using <br> instead of \n. mail() function sets html content-type so \n won't work.