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.

Send notification email after change value (delay)
#3
(15.10.2024, 13:47)admin Wrote: 1. Check that you have "Execute on group read" enabled. It might cause the script to run. Enabled logging for the mapped object to see where the value write or read comes from.

2. Set script "Execution mode" to "Last instance only" and use this code:
Code:
curr_value = event.getvalue()
prev_value = storage.get('prev_value')

if curr_value == prev_value then
  return
end

storage.set('prev_value', curr_value)

os.sleep(10)

if curr_value then
  subject = 'Main switch = ON'
  message = '\nState: Normal'
else
  subject = 'Main switch = OFF'
  message = '\nState: ALARM!!'
end

mail('1234@yyyyyyy.ww', subject, message)

1. I already disabled "Execute on group read". In "Object logs" it turns out that the signal from the controller (in this case a very old JUNG unit) is checked and the SL responds ("14/2/188 decoded value 1" and it hasn't changed), and after that script is running.
2. Thanks for the code - everything works. But I probably defined the problem inaccurately - the script should work ONLY if the value of the group has changed and remained for at least 10 seconds. (the script should not work if there is a fast switching ---> from 1 to 0 and back (within 3 sec for example).
Currently, the last value after switching is sent.
Reply


Messages In This Thread
RE: Send notification email after change value (delay) - by Krists - 15.10.2024, 14:16

Forum Jump: