Flexy email Updating System Values Every Time any Alarm is Reached


I would like to configure my eWon to send an email every time ANY alarm state is reached.

This email would reference multiple tag values, so a script in BASIC IDE may be necessary. I would like the email to have the following attributes.

   Email Subject: "Tag_x_Name"

   Email Body:

     Any alarm was struck in your system regarding "Tag_x_Name"
     Current State: "Tag_x_Value"
     Normal State:  Normal Value

     Current System Overview:
      "Tag_A_Value" Units_A
      "Tag_B_Value" Units_B
      "Tag_C_Value" Units_C
      "Tag_x_Value" Units_x

Where “Tag_x” is the tag that sounded the alarm. If “Tag_A” were to sound the alarm, the email would be the same, except the instances of Tag_x would be replaced by Tag_A.

I read through the document ‘Sending Emails with a Flexy.docx’, which was was a great start. However, there are dozens of tags, and I’m hoping to avoid writing a unique function for each tag.


Is there specific information that you need in the email that is requiring you to send the emails through the BASIC IDE? Otherwise you should be able to do this with just the normal alarm setup for tags.

If you do want to do this through the BASIC IDE, I think that should be possible but you would probably need multiple onalarm/onchange statements to act as a trigger to send the email. Then you’d probably need a loop that will iterate through every tag to check which ones are active and write an email telling which tags are in the alarming state.

The reason I was thinking BASIC IDE is necessary is because I want to reference values for multiple tags in a single email. I was under the impression that in order to call tag values in an email body, I needed to use Basic IDE. If it is possible to do this through normal alarm setup, that would be great.

Oh ok I see, in that case this is something that would need to be done through the BASIC IDE. I can give you some example code that will cycle through every tag to give you a starting point for this. You’ll probably want to do an if statement to check if the AlStat value is a 1 and then write in the email body based on that value

i% = 0
//Browse all Tags
For i%=0 To n%-1
name$ = GETSYS TAG, “name” //gets the name of
//print name$ + " " + a$
Next i%

Great, that helped a lot. I Now can send an email out of a summary of the tag values if I manually run the Basic IDE while an alarm is active. How to I automatically run this script to only send an email at the beginning and end of an alarm, similar to the “ALM” and “END” boxes in the alarm tags. If I use a timer to run the script every couple of seconds, the emails will send every time the script runs, I only want to send them once at the beginning and once at the end. This is what I have now, but I am getting an invalid parameter error (5) and I do not know why. The function @tagmail send the email and works, I just need to trigger it correctly.

CLS // clears console screen

TSET 1, 1 // timer 1, runs every 1 second
ONTIMER 1, @checktags

Function checktags()
$i% = 0
//Browse all Tags
For $i%= 0 TO $n%-1
name$ = GETSYS TAG, “name” //gets the name of
//print name$ + " " + a$
IF $i%=95 THEN

IF (a$=“2” OR a$=“5”) THEN
ONALARM, $i%, @tagmail(name$, value$)
Next $i%

I think the issue is that in this line

ONALARM, $i%, @tagmail(name$, value$)

You’re calling “i” which starts with a value of 0, I’m not sure if a tag starts with the value 0 or not, but you might have more luck using the name$ value there instead of i.

If you click on the error that says invalid paramter it should tell you which line of code is causing the issue, but I think the issue might have to do with the onalarm section

That seemed to help, but now I am getting the error code invalid parameter (5). I attached a screenshot below. I tried making name$ and value$ local variables but that did not help. More info, when I debug and step through, the error does not occur until the end of the “tagmail” function. All variables within “tagmail” are local except for those referencing tag values. Note: It is still sending the email, so the function run and works just before the error.

I think you just need quotes around the @tagmail(name$, value$)

That changed it so now it just says invalid parameter(5), but does not reference the line where the error occurs, even when I click on it.


Another update: The error only occurs on the last iteration of the code running. I have 96 tags I am reading through, and the code runs until the 96th tag

Does it seem like the first tag is correct or is one missing? Is there any chance that the loop is going 1 past the number of tags that actually exist?

I rearranged my code so the ONALARM triggered the IF THEN as opposed to vice versa. This is what I have now: It works, the only thing is regardless of which alarm is actually triggered, the ONALARM is not triggered until the final tag. So I have to rerun through every tag and then use the IF THEN. Is there a list I can find everything the GETSYS can access? I cannot find it in the ‘Programming Reference Guide Reference Guide’. I would like to use GETSYS to access the Tag Description. GETSYS, TAG, “TAGDESCRIPTION” did not work. Here’s a screenshot of what I have now.

tag parameters.pdf (107.3 KB)

This should be all of the tag information you can grab from getsys

Hi Tim,

Thanks for all the help! I have been able to get it to work. Is there somewhere I can access all the documentation you provide for BASIC IDE? I would also like to see all the program and system information I can grab from getsys. Specifically, I would like to be able to reference ‘eWon Identification’ and email lists.

To answer my questions from above for future reference to this thread:

ONALARM: This, as well as ONTIMER (And I’m assuming all ONxxxxx functions) will trigger a function, however that function does not run until the current section of code is complete(For loops will run through every value of i%, if statements will continue to evaluate, functions will be completed, etc) After the section of code is complete, the trigger will be initiated, that is why ONALARM errors only occurred on the last iteration of a FOR loop. This is also why I needed to run two FOR loops. one to trigger ONALARM, and one to collect data from tags where ALSTAT was active

Hi Ryan,

Glad to hear all the progress you’ve made so far, I’ve included the BASIC IDE manual below

Programming Reference Guide

Hi Ryan,

Do you have any additional questions or would it be alright for me to close out this ticket?


Hi Tim,

I have no additional questions. Feel free to close out the ticket, thanks!

1 Like

Thanks have a good day Ryan!