Email notifications

siafu

Active Member
Hello all,

Below is the logic cript I have to run lights on and off and send email alerts to me when lights come on and when lights go off. This has been working great for some time.

What I wanted to add is email notification from Temperature sensor 3. Basically would like an email sent when temp sensor 3 goes below a certain temperature.

I tried adding the same setup as for the lights, but I get continuous email one after the other when temp reaches the setting I've entered.

Any idea why this does not work for the temp sensor?

START
TSTLT AIP1 4
CALLSUB LIGHT_ON
TSTGT AIP1 8
CALLSUB LIGHT_OFF
TSTEQ OP1 1
CALLSUB MAILON
TSTEQ OP1 0
CALLSUB MAILOFF
END

LIGHT_ON:
SET OP1 1
RET

LIGHT_OFF:
SET OP1 0
RET

MAILON:
SET VAR2 0
TSTEQ VAR1 0
GOTO MAILON1
RET

MAILON1:
EMAIL 1
SET VAR1 1
RET

MAILOFF:
SET VAR1 0
TSTEQ VAR2 0
GOTO MAILOFF1
RET

MAILOFF1:
EMAIL 2
SET VAR2 1
RET
 
Here is it with the logic fow what I'm trying to do marked in RED.

START
TSTLT AIP1 4
CALLSUB LIGHT_ON
TSTGT AIP1 8
CALLSUB LIGHT_OFF
TSTEQ OP1 1
CALLSUB MAILON
TSTEQ OP1 0
CALLSUB MAILOFF
TSTLT T3 800
CALLSUB MAILTM
END

LIGHT_ON:
SET OP1 1
RET

LIGHT_OFF:
SET OP1 0
RET

MAILON:
SET VAR2 0
TSTEQ VAR1 0
GOTO MAILON1
RET

MAILON1:
EMAIL 1
SET VAR1 1
RET

MAILOFF:
SET VAR1 0
TSTEQ VAR2 0
GOTO MAILOFF1
RET

MAILOFF1:
EMAIL 2
SET VAR2 1
RET

MAILTM:
SET VAR3 0
TSTEQ VAR4 0
GOTO MAILTM1
RET

MAILTM1:
EMAIL 3
SET VAR4 1
RET
 
From web interface, do you see VAR4 change to 1 then back to 0? It seems only sending one email, even temperature going back up above 80.0 then coming back down, it will no longer send.
 
Yes, VAR4 changed to 1, but did not change back to 0.

But I've added another logic, see below, and Var4 did change to 0, but the emails from Email 4 keep coming one after the other, the emails will not stop.

What I need it to do, is when the temperature in the boiler room drops below a certain temperature, is to send me an email via Email 3. This will give me a good Idea that another Webcontrol device (second WC) controlling the thermostat in another location of the building has frozen, and I need to go reset it.

I'm not sure why this is not working, because it is working fine for when the lights come on and off, I get one email for each. Email1 for ON and Email 2 for Off


START
TSTLT AIP1 4
CALLSUB LIGHT_ON
TSTGT AIP1 8
CALLSUB LIGHT_OFF
TSTEQ OP1 1
CALLSUB MAILON
TSTEQ OP1 0
CALLSUB MAILOFF
TSTLT T3 800
CALLSUB MAILTM
TSTLT T3 880
CALLSUB MAILTM1

END

LIGHT_ON:
SET OP1 1
RET

LIGHT_OFF:
SET OP1 0
RET

MAILON:
SET VAR2 0
TSTEQ VAR1 0
GOTO MAILON1
RET

MAILON1:
EMAIL 1
SET VAR1 1
RET

MAILOFF:
SET VAR1 0
TSTEQ VAR2 0
GOTO MAILOFF1
RET

MAILOFF1:
EMAIL 2
SET VAR2 1
RET

MAILTM:
SET VAR3 0
TSTEQ VAR4 0
GOTO MAILTMY
RET

MAILTMY:
EMAIL 3
SET VAR4 1
RET

MAILTM1:
SET VAR4 0
TSTEQ VAR3 0
GOTO MAILTMN
RET

MAILTMN:
EMAIL 4
SET VAR4 0
RET
 
Hello all,

Below is the logic cript I have to run lights on and off and send email alerts to me when lights come on and when lights go off. This has been working great for some time.

What I wanted to add is email notification from Temperature sensor 3. Basically would like an email sent when temp sensor 3 goes below a certain temperature.

I tried adding the same setup as for the lights, but I get continuous email one after the other when temp reaches the setting I've entered.

Any idea why this does not work for the temp sensor?

Far be it for me to inflict my preferences on others, but this absolute obsession with subroutines for no actual benefit (and a lot of obfuscation of the code) seems rife.

Seems to me that you want a fairly simple task:
* If light level below (x), turn on lights and send email
* If light level above (y), turn off lights and send email
* If temperature transitions below (a), send email

Code:
  start
	 set ram1 var1   # copy current state to working register
	 tstlt aip1 4    # input 1 less than 4?
	 orb ram1 1 ram1     # turn on lights

	 tstgt aip1 8   # input 1 greater than 8?
	 andb ram1 6 ram1    # turn off lights

    tstlt t3 800    # temperature below 80 deg C?
    orb ram1 2 ram1     # turn on heater

    tstgt t3 880  # temperature above 88 deg C?
    andb ram1 5 ram1    # turn off heater

    # ram1 now contains the desired pattern
    # Set the outputs to reflect right state
    andb ram1 1 op1   # have not tested this, presume CAI set output on if argument is non-zero
    andb ram1 2 op2

    # now, email alerts.
    xorb ram1 var1 ram2   # see what has changed states
    and ram2 1	  # if bit1 = 0 no light change, go test temperatur
    bz temptest
    tsteq op1 1	 # if output 1 is now on, light just changed to ON
    email em1
    tsteq op1 0	 # if output1 is now off, light just changed to OFF
    email em2


temptest:
    and ram2 2	  # if bit1=0 no temperature change
    bz done
    tsteq op2 1	 # if output 2 is now on, we just turned the heater on
    email em3
                            # no need to test the other condition aparantly, but if you did it would go here.

done:
    set var1 ram1   # store the current state for next time
end
 
Thank you for your help rossw, but I get this error message for the logic you prepared for me.

Error - assembleing line 3: Invalid opcode: ORB

Below is what I tried to save in the WC.

My version of the device is: Version: v03.01.03

start
set ram1 var1
tstlt aip1 4
orb ram1 1 ram1

tstgt aip1 8
andb ram1 6 ram1

tstlt t3 800
orb ram1 2 ram1

tstgt t3 880
andb ram1 5 ram1



andb ram1 1 op1
andb ram1 2 op2


xorb ram1 var1 ram2
and ram2 1
bz temptest
tsteq op1 1
email em1
tsteq op1 0
email em2


temptest:
and ram2 2
bz done
tsteq op2 1
email em3


done:
set var1 ram1
end
 
Thank you for your help rossw, but I get this error message for the logic you prepared for me.

Error - assembleing line 3: Invalid opcode: ORB

My version of the device is: Version: v03.01.03


Oh. That would have been helpful in the first instance. bitwise or wasn't available in that old version of the code.

Let me finish the job I'm on now and I'll have another quick look with that in mind.
 
Thank you rossw, sorry about that. I'll mention the version numbers of my boards in the future when needing help.

Will await your response in regards the older board.
 
I think this should work similarly. Logic flow is quite different, but then anyone who says there is only "one" right way to write code, is ignorant!

Code:
start
         tstlt aip1 4   # input 1 less than 4?
         set op1 1         # turn on lights

         tstgt aip1 8   # input 1 greater than 8?
         set op1 0       # turn off lights

        tstlt t3 800    # temperature below 80 deg C?
        set op2 1  # turn on heater

        tstgt t3 880  # temperature above 88 deg C?
        set op2 0        # turn off heater


        # now, email alerts.

        xor op1 var1    # op1 changed?
        bz temptest     # zero if op1 is same as var1, so go check temperatures

        tsteq op1 1      # if output 1 is now on, light just changed to ON
        email em1
        tsteq op1 0      # if output1 is now off, light just changed to OFF
        email em2


temptest:
        xor op2 var2        # if op2 is same as var1, no temperature change
        bz done
        tsteq op2 1      # if output 2 is now on, we just turned the heater on
        email em3

done:
        set var1 op1   # store the current state for next time
        set var2 op2
end
 
Thank you, the board took the logic. I did a test and it emailed me the wrong email, send from email2.

I think this was because this version does not understand "em" from what I was told it needs to have "EMAIL" as the command. After making this change I did a test and it sent the correct email.

As for the light , I can't test them right now top see if this logic will work as they are on, but will know in the morning when they need to shut off.

One question. Do I need to have "SET OP2 1" and "SET OP2 0" ? It actually does not control anything via that output.


START
TSTLT AIP1 4
SET OP1 1
TSTGT AIP1 8
SET OP1 0
TSTLT T3 830
SET OP2 1
TSTGT T3 880
SET OP2 0
XOR OP1 VAR1
BZ TEMPTEST
TSTEQ OP1 1
EMAIL 1
TSTEQ OP1 0
EMAIL 2
TEMPTEST:
XOR OP2 VAR2
BZ DONE
TSTEQ OP2 1
EMAIL 3
DONE:
SET VAR1 OP1
SET VAR2 OP2
END
 
Thank you, the board took the logic. I did a test and it emailed me the wrong email, send from email2.

I think this was because this version does not understand "em" from what I was told it needs to have "EMAIL" as the command. After making this change I did a test and it sent the correct email.

As for the light , I can't test them right now top see if this logic will work as they are on, but will know in the morning when they need to shut off.

One question. Do I need to have "SET OP2 1" and "SET OP2 0" ? It actually does not control anything via that output.

OK, I didn't actually load that code into a board, it's "from memory/logic" but apart from obvious errors (like EM!), it should be ok.

I presumed from your sample code you are not using the other outputs, so I chose to use OP2 for several reasons.
1. It's a convenient thing to store a bit.
2. It makes the code "logical" and consistent to read
3. If you do choose to add a heater at some later stage .... it's already implemented!
 
Thank you rossw.

Now if I wanted to send another email, when temp on T3 goes above a certain point, how is that setup, the following didn't work for me.

TEMPTEST:
XOR OP2 VAR2
BZ DONE
TSTEQ OP2 1
EMAIL 3
TSTEQ OP2 0
EMAIL 4
 
What version firmware do you have? We did identify a bug caused by the compiler in firmware version 3.02.16 and 3.02.16a . If you are running firmware in those versions, please send the board to us for free firmware update.
 
Back
Top