Email send on different alarms

Hello, I have tried to use this script and it works, but when you send the email it only does it once even when the value of my tag continues to change both maximum and minimum.
I hope to get help about that.
Thank you

Hi Luis,

Can you describe what you want to do with your code for sending emails? Like do you want it to send you an email each time that the value of the tag changes (as long as it’s still in the alarm region) Or are you trying to create different levels of alarms ie. Very Low, Low, High, Very High?

Hi Tim
I currently use the default flexy 205 alarms (LL, L, H, HH);
but I want each alarm to send a different message, so I thought about using a basic script to achieve it. Browsing here in the forum I found something that could work for me:

INIT Section:
ONALARM “Tag”, “GOTO MyRoutine”

MyRoutine:
e$ = “Email To”
c$ = “CC”
s$ = “Subject message”
b$ = “This is a body placeholder”;

IF(Tag@ < 26) THEN
b$ = “Tag is currently at: " + STR$ Tag@ + " the level is at 25%.”
ENDIF

IF(Tag@ < 51) THEN
b$ = “Tag is currently at: " + STR$ Tag@ + " the level is at 50%.”
ENDIF

IF(Tag@ > 74) THEN
b$ = “Tag is currently at: " + STR$ Tag@ + " the level is at 75%.”
ENDIF

IF(Tag@ = 100) THEN
b$ = “Tag is currently at: " + STR$ Tag@ + " the level is at 100%.”
ENDIF

SENDMAIL e$, c$, s$, b$

This little script works, but it only sends a single email, when my variable (tag) changes up or down, nothing happens anymore.
I have dealt with the onchange function and when using it it spam me in my mail.
I would appreciate your help Tim.
Thanks.

you could get around this by using an Onchange instead of an onalarm. I’d also probably create a separate tag just so that we can limit it so it’s not constantly sending emails after each time the tag value changes. For this case I’m just going to say create a tag called alarm_level

Onchange “Tag”, “@MyRoutine()”
Onchange “alarm_level”,"@EmailAlarm()"

Function MyRoutine()
e$ = “Email To”
c$ = “CC”
s$ = “Subject message”
b$ = “This is a body placeholder”;

IF(Tag@ < 26) THEN
alarm_level@ = 1 // low low
b$ = “Tag is currently at: " + STR$ Tag@ + " the level is at 25%.”
ENDIF

IF(Tag@ < 51) THEN
alarm_level@ = 2 // low
b$ = “Tag is currently at: " + STR$ Tag@ + " the level is at 50%.”
ENDIF

IF(Tag@ > 74) THEN
alarm_level@ = 3 // high
b$ = “Tag is currently at: " + STR$ Tag@ + " the level is at 75%.”
ENDIF

IF(Tag@ = 100) THEN
alarm_level@ = 4 // high high
b$ = “Tag is currently at: " + STR$ Tag@ + " the level is at 100%.”
ENDIF

Endfn

Function EmailAlarm() // will only be triggered if alarm_level changes
SENDMAIL e$, c$, s$, b$
Endfn

Thanks for your quick response Tim.
I have a doubt, when creating a new tag “alarm_level” that IO address should have, and how it would be linked to my TAG … or maybe I have a bad idea about this and it is in a different way.

You should just be able to leave it as a memory tag. The idea I had behind it was just to make it so that when “tag” goes into a different range such as going from high to high high that it would make the alarm_level change from 3 to 4. The onchange makes makes it so that each time the alarm_level changes that it will send out an email

Hi Tim. I was testing the script and it works fine, but it only works correctly if I use (=) for example IF MYTAG @ = 20. If I use (<) in all my cases, spam is created and the new tag we create, “alarm_level” no longer changes its value and therefore spam is created. Is there any way I can use in all my alarm cases <and only send a single email?

maybe try something like this?

Onchange “tag”, “@MyRoutine()”
Onchange “alarm_level”,"@EmailAlarm()"
Function MyRoutine()
e$ = “Email To”
c$ = “CC”
s$ = “Subject message”
b$ = “This is a body placeholder”
IF(tag@ > 0 AND tag@ <= 26) THEN
alarm_level@ = 1 // low low
b$ = “tag is currently at: " + STR$ tag@ + " the level is at 25%.”
Print "tag amount " + STR$ tag@ + "alarm_level " + STR$ alarm_level@
ENDIF
IF(tag@ > 26 AND tag@ <= 51) THEN
alarm_level@ = 2 // low
b$ = “tag is currently at: " + STR$ tag@ + " the level is at 50%.”
Print "tag amount " + STR$ tag@ + "alarm_level " + STR$ alarm_level@
ENDIF
IF(tag@ > 51 AND tag@ <= 74) THEN
alarm_level@ = 3 // high
b$ = “tag is currently at: " + STR$ tag@ + " the level is at 75%.”
Print "tag amount " + STR$ tag@ + "alarm_level " + STR$ alarm_level@
ENDIF
IF(tag@ > 74 AND tag@ < 100) THEN
alarm_level@ = 4 // high high
b$ = “tag is currently at: " + STR$ tag@ + " the level is at 100%.”
Print "tag amount " + STR$ tag@ + "alarm_level " + STR$ alarm_level@
ENDIF
Endfn
Function EmailAlarm()
SENDMAIL e$, c$, s$, b$
Print “mailsent”
Endfn

YES, THAT WAS WHAT I DID AND WORK PERFECTLY!
I THANK A LOT OF YOUR TIM SUPPORT.
THANK YOU.

1 Like

You’re welcome,

Glad we could get it up and running!