problem with loop for one-time email notification - 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: problem with loop for one-time email notification (/showthread.php?tid=3645) |
problem with loop for one-time email notification - 123einerlei - 25.10.2021 Hello together, im tying to build a simple "alarm system" with email notification. But i have a little problem with the loop for the email notification. If there is an alarm, i don´t get a one-time email notification, i get endles email notifications. Can somebody show me where the mistake in my thinking is? The objects / variabels (alarm_on; door_1_closed; door_1_locked; door_2_cloded; door_3_closed have the same "Tag" to start a event based script. -- ========================================================================== -- -- alarm system -- © 2021 123einerlei -- -- simple email alarm notification -- -- ========================================================================== --variable declaration------------------------------------------------------- alarm_on = grp.getvalue('1/1/1') -- arm the alarm system garage_armed = grp.getvalue('2/2/2') -- alarm system armed alarm = grp.getvalue('3/3/3') -- alarm door_1_closed = grp.getvalue('4/4/4') -- side entrance door closed door_1_locked = grp.getvalue('5/5/5') -- side entrance door locked door_2_closed = grp.getvalue('6/6/6') -- door street closed door_3_closed = grp.getvalue('7/7/7') -- door garden closed --arm the alarmsystem-------------------------------------------------------- if alarm_on == true then --logic---------------------------------------------------------------------- if door_1_closed == true and door_1_locked == true and door_2_closed == true and door_3_closed == true then grp.write('3/3/3', true) -- no alarm i = 1 else grp.write('3/3/3', false) -- alarm alert('message') --loop for one-time email notification--------------------------------------- repeat Email("user@provider.com", "subject", "message") i, = i+1 until (i > 1) end --status alarmsystem--------------------------------------------------------- grp.write('2/2/2', true) -- status alarmsystem armed else grp.write('2/2/2', false) -- status alarm system disarmed end RE: problem with loop for one-time email notification - admin - 26.10.2021 Why do you have a repeat loop there if you want to send an e-mail only once? RE: problem with loop for one-time email notification - 123einerlei - 26.10.2021 The following signals are sent every minutes: door_1_closed = grp.getvalue('4/4/4') -- side entrance door closed door_1_locked = grp.getvalue('5/5/5') -- side entrance door locked Because of this, the script runs every minutes and sent a e-mail. RE: problem with loop for one-time email notification - admin - 27.10.2021 Replace all grp.write calls with grp.checkwrite and attach a script to 3/3/3 which sends the e-mail. checkwrite will only update the object value if it's different from the current. This way email will only be sent once per every object change. |