15.10.2024, 13:36
Hello,
I have simple Event-based script (in SL) who sends an email when the status changes in a particular group. This code works pretty well, however I have two questions:
1. Why script works even when the status has not changed. For example, the controller performs a daily scan - and at that time scripts work and send a notification. (status has not changed). How to fix it?
2. How can I put a delay on sending notifications? This means, if the particular group status has switched and is unchanged for 10 seconds, then only send a notification.
Thank you.
I have simple Event-based script (in SL) who sends an email when the status changes in a particular group. This code works pretty well, however I have two questions:
1. Why script works even when the status has not changed. For example, the controller performs a daily scan - and at that time scripts work and send a notification. (status has not changed). How to fix it?
2. How can I put a delay on sending notifications? This means, if the particular group status has switched and is unchanged for 10 seconds, then only send a notification.
Code:
value = event.getvalue()
mydata = storage.get('myobjectdata', 2)
if value then
if value ~= mydata then
--email for ON (1)
subject = 'Main switch = ON'
message = '\nState: Normal'
mail('1234@yyyyyyy.ww', subject, message)
end
else
if value ~= mydata then
--email for OFF (0)
subject = 'Main switch = OFF'
message = '\nState: ALARM!!'
mail(' 1234@yyyyyyy.ww ', subject, message)
end
end
storage.set('myobjectdata', value)
Thank you.