Logic Machine Forum
Controlling Temp with timer - 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: Controlling Temp with timer (/showthread.php?tid=1967)



Controlling Temp with timer - ajgarcia.reyse - 14.03.2019

Hi all,

I am monitoring water temperature with LM and KNX, but I need send email when current temperature is higher than "max limit" during one period of time (e.g. 60 min).

Anyone could help me? Thanks


RE: Controlling Temp with timer - admin - 15.03.2019

Create an event script mapped to temperature object:
Code:
temp = event.getvalue()

curr = temp > 22
prev = storage.get('temp_over')

if curr ~= prev then
  if curr then
    storage.set('temp_time', os.time())
    storage.set('temp_notified', false)
  end

  storage.set('temp_over', curr)
end

Then create a scheduled script that runs every minute to check whether e-mail needs to be sent. Change delta time if needed (60 * 60 = 1 hour in seconds).
Code:
curr = storage.get('temp_over')
notified = storage.get('temp_notified')
if curr and not notified then
  now = os.time()
  time = storage.get('temp_time', now)

  delta = now - time
  if delta > 60 * 60 then
    -- send email
    storage.set('temp_notified', true)
  end
end



RE: Controlling Temp with timer - ajgarcia.reyse - 21.03.2019

(15.03.2019, 08:05)admin Wrote: Create an event script mapped to temperature object:
Code:
temp = event.getvalue()

curr = temp > 22
prev = storage.get('temp_over')

if curr ~= prev then
 if curr then
   storage.set('temp_time', os.time())
   storage.set('temp_notified', false)
 end

 storage.set('temp_over', curr)
end

Then create a scheduled script that runs every minute to check whether e-mail needs to be sent. Change delta time if needed (60 * 60 = 1 hour in seconds).
Code:
curr = storage.get('temp_over')
notified = storage.get('temp_notified')
if curr and not notified then
 now = os.time()
 time = storage.get('temp_time', now)

 delta = now - time
 if delta > 60 * 60 then
   -- send email
   storage.set('temp_notified', true)
 end
end

Thank you very much!! Script works perfectly on my LM. Is there any handbook or manual to learn advanced scripts in LUA???


RE: Controlling Temp with timer - admin - 21.03.2019

Common LM/Lua functions are documented: http://openrb.com/docs/lua.htm

As for more advanced things, have a look at example in forums and on our website. There are some many possible solutions and approaches that it's just not possible to document them.


RE: Controlling Temp with timer - Gadjoken - 10.09.2019

Hello,
This function is very useful.
I use it to check a temperature for 5 minutes if it goes above 23 ° C so I send an email.
If possible, I would like to send an email when the temperature drops below 23 ° C.
This email must be sent only after a temperature fault and not every time the temperature is below 23 ° C.
thank you. B. R.


RE: Controlling Temp with timer - admin - 10.09.2019

Event script:
Code:
temp = event.getvalue()

curr = temp > 23
prev = storage.get('temp_over')

if curr ~= prev then
  storage.set('temp_time', os.time())
  storage.set('temp_notified', false)
  storage.set('temp_over', curr)
end

Scheduled script:
Code:
notified = storage.get('temp_notified')
if not notified then
  curr = storage.get('temp_over')
  
  now = os.time()
  time = storage.get('temp_time', now)
  delta = now - time
  
  if delta > 5 * 60 then
    if curr then
      text = 'temp over limit'
    else
      text = 'temp under limit'
    end

    -- send email
    storage.set('temp_notified', true)
  end
end