Cai Webcontrol as true thermostat

siafu

Active Member
Hello all,

So I've been messing around with this webcontrol, very cool device, appears to be limitless, if you can figure out how to program it.

Below is the programing for one of my devices I use control the temperature and control the front door.

All works great, but would like to take it to the next level of temperature control.

I would like to have it control the temperature at different levels of degree based on different times of day, kind of like a wall mount electronic thermostat.

Can anyone help me out with this?

Thank you very much, greatly appreciate your help.


START
TSTLT T1 670
CALLSUB HEAT_ON
TSTGT T1 680
CALLSUB HEAT_OFF
TSTEQ OP2 1
CALLSUB MAILON
TSTEQ OP2 0
CALLSUB MAILOFF
TSTEQ OP1[1000] 1
SET OP1 0
TSTGT IP1 0 EM1
NOP
END

HEAT_ON:
SET OP2 1
RET

HEAT_OFF:
SET OP2 0
RET

MAILON:
SET VAR2 0
TSTEQ VAR1 0
GOTO MAILON1
RET

MAILON1:
EMAIL EM2
SET VAR1 1
RET

MAILOFF:
SET VAR1 0
TSTEQ VAR2 0
GOTO MAILOFF1
RET

MAILOFF1:
EMAIL EM3
SET VAR2 1
RET
 
write multiple subroutines that check the temperature and turn on the output at various temps you might want. Write additional subroutines that turn the output off at various temps. In the main body of the program test for the times you want the various on/off temps to be active and call the subroutines needed.

Alternatively. You could write one "on" subroutine and on "off" subroutine but instead of using a fixed number, use a variable for the value. Then write some code that sets the varialbes based on time of day. This could then be manually over-ridden by posting to the cai a new variable value (if you have the newer firmware).
 
write multiple subroutines that check the temperature and turn on the output at various temps you might want. Write additional subroutines that turn the output off at various temps. In the main body of the program test for the times you want the various on/off temps to be active and call the subroutines needed.

Alternatively. You could write one "on" subroutine and on "off" subroutine but instead of using a fixed number, use a variable for the value. Then write some code that sets the varialbes based on time of day. This could then be manually over-ridden by posting to the cai a new variable value (if you have the newer firmware).


Hello Lou, nice to her from you,

Would you mind giving me one example, then I could follow for the rest.

Basically one example that would look and see if heat is needed to be turned on at 5:00 AM is below 67 degrees, then at 9:00 AM it would turn switch to 66 degrees for another time period, then later on would witch to 67 degrees.

Basically just need to have different time periods where heat would be higher, like during the night it would be lower and higher during the day.

Thanks again for your help.
 
I haven't tested this.

START
CALLSUB SETTEMP
CALLSUB ONOFF
END

SETTEMP:
TSTEQ CT 06:00:00
SET VAR1 680
TSTEQ CT 09:00:00
SET VAR1 700
TSTEQ CT 13:00:00
SET VAR1 730
RET

ONOFF:
TSTLT T1 VAR1
SET OP1 1
ADD VAR1 20 VAR2
TSTGT T1 VAR2
SET OP1 0
RET

Personally, I don't like much in the main body of the program. I like to do things in subroutines for clarity. It is kind of like using folders.

Anyway, I have it set the var1 to different values as the day progresses in the settemp subroutine. Then, in the onoff routine it checks the temp against var1. If the temp is less than the value, (68.0 degrees) it turns output 1 on. Var2 is just var1 plus 20 (2 degrees). When the temp hits var2 value, it shuts output1 off.

In summary, this program would be to turn a heater at output1 on at various temps as defined by var1 and turn the heat off when the temp becomes 2 degrees warmer.
 
I haven't tested this.

START
CALLSUB SETTEMP
CALLSUB ONOFF
END

SETTEMP:
TSTEQ CT 06:00:00
SET VAR1 680
TSTEQ CT 09:00:00
SET VAR1 700
TSTEQ CT 13:00:00
SET VAR1 730
RET

ONOFF:
TSTLT T1 VAR1
SET OP1 1
ADD VAR1 20 VAR2
TSTGT T1 VAR2
SET OP1 0
RET

Personally, I don't like much in the main body of the program. I like to do things in subroutines for clarity. It is kind of like using folders.

Anyway, I have it set the var1 to different values as the day progresses in the settemp subroutine. Then, in the onoff routine it checks the temp against var1. If the temp is less than the value, (68.0 degrees) it turns output 1 on. Var2 is just var1 plus 20 (2 degrees). When the temp hits var2 value, it shuts output1 off.

In summary, this program would be to turn a heater at output1 on at various temps as defined by var1 and turn the heat off when the temp becomes 2 degrees warmer.

Hello Lou,

Great, thank you very much, will give this a try and let you know.
 
You can manually using wget command to set the VAR1 to a different value, it will act like the thermostat on the wall, to overwrite the programmed temperature.
If you add logic to check VAR3, then you can set VAR3 value to 1 to override the program, make A/C stop manually.

Then if you create a web page running on ipad or iphone, that page can look exactly like the wall thermostat.
 
You can manually using wget command to set the VAR1 to a different value, it will act like the thermostat on the wall, to overwrite the programmed temperature.
If you add logic to check VAR3, then you can set VAR3 value to 1 to override the program, make A/C stop manually.

Then if you create a web page running on ipad or iphone, that page can look exactly like the wall thermostat.


Thank you for the information,

I tried Lou's example but unfortunately it did not work.

I tried it as solo, with no other programing, but it would not trigger anything, any idea why?
 
Might be the name "settemp" try changing it to "tempset". It might be nameing a subroutine name starting with the letters "set" screws things up since it is also a command.

I wrote this program for output 1, it looks like you have your heater on output 2 looking back at your original program. I assume you changed that but it is worth mentioning.

Check to see that it is setting the variable. You can use the "get" command to query the cai for variable or send yourself a test email (it will put all the values at the end of the email, assuming your firmware version does that).

Is t1 actually where you are reading temps? again, querry it to see what it is registering. Make sure it is on fahrenheit.
 
Siafu,

What is your VARs looks like?
In that PLC code, VAR1 when started was zero.
TSTLT T1 VAR1
SET OP1 1

T1 is likely higher than VAR1, so the
SET OP1 1
will be skipped.

Please notice the definition "TSTLT a b c" says "Tests if a is less than b."


Since all VARS will start with zero, you may want to initialize VAR to a value, like
TSTEQ VAR1 0
set VAR1 xyz <- xyz is your default value.

It seems you want to turn heat on when temperature is below 67F and turn heater off when it reaches 68F. Is that true? Because I saw you also have email and checking IP1, as well as set OP2. So I would like to understand what you want to do in a complete picture.
 
Siafu,

What is your VARs looks like?
In that PLC code, VAR1 when started was zero.
TSTLT T1 VAR1
SET OP1 1

T1 is likely higher than VAR1, so the
SET OP1 1
will be skipped.

Please notice the definition "TSTLT a b c" says "Tests if a is less than b."


Since all VARS will start with zero, you may want to initialize VAR to a value, like
TSTEQ VAR1 0
set VAR1 xyz <- xyz is your default value.

It seems you want to turn heat on when temperature is below 67F and turn heater off when it reaches 68F. Is that true? Because I saw you also have email and checking IP1, as well as set OP2. So I would like to understand what you want to do in a complete picture.

Hello Cai, thank you for your help.

I'm not sure about what you mentioned above, but below is what I have programmed now, and would like to see if I can incorporate sime programming so that the heat is set at different temperatures at different times of the day, for example.

at 5:00 AM would like to have it turn on if below 67 degree.

Then at 8:00 AM would like for the heat to turn on if below 65 degree,

Then at 5:00 PM would like to tun on if below 67 degree

Then at midnight would like to turn on if below 64 degree

Pretty much have it set in different time blocks, so when I'm not home during the day hours (8:00 AM and 5:00 PM) heat would only turn on if reading is below 65 degree.

The above examples is what I can set in a wall mounted thermostat, hope you understand what I'm trying to say.

Lou, when i tried your program a while back, i did make sure it was changed to output 1, and everything was in F

Thank you both for your willingness to help me with this.


____________________________________________________________________________________________________________________


START
TSTLT T1 700
CALLSUB HEAT_ON
TSTGT T1 710
CALLSUB HEAT_OFF
TSTEQ OP2 1
CALLSUB MAILON
TSTEQ OP2 0
CALLSUB MAILOFF
TSTEQ OP1[1000] 1
SET OP1 0
TSTGT IP1 0 EM1
NOP
END

HEAT_ON:
SET OP2 1
RET

HEAT_OFF:
SET OP2 0
RET

MAILON:
SET VAR2 0
TSTEQ VAR1 0
GOTO MAILON1
RET

MAILON1:
EMAIL EM2
SET VAR1 1
RET

MAILOFF:
SET VAR1 0
TSTEQ VAR2 0
GOTO MAILOFF1
RET

MAILOFF1:
EMAIL EM3
SET VAR2 1
RET
 
Do you have a range or time to turn off the heat?
If you have clearly defined what time to be on and what time to be off, or what temperature will be off, we can help you to correct it.
 
Do you have a range or time to turn off the heat?
If you have clearly defined what time to be on and what time to be off, or what temperature will be off, we can help you to correct it.

hello

below are the ranges.

midnight to 5am

heat on at 64 degree off at 65 degree

5am to 8am

heat on at 66 degree off at 67 degree

8am to 5pm

heat on at 65 degree off at 66 degree

5pm to midnight

heat on at 66 degree off at 67 degree

the above are just examples of the range of times I would like.

As long as the obove will work, then I can adjust them better later on, I just need the base programming to incorporate with my other things, like the door unlocking and email settings I have now.

thank you again for your help with this.
 
I modified your code slightly, incorporate some code Lou wrote:

START
TSTLT CT 8:0:0
CALLSUB THERMO58
TSTEQ OP2 1
CALLSUB MAILON
TSTEQ OP2 0
CALLSUB MAILOFF
TSTEQ OP1[1000] 1
SET OP1 0
TSTGT IP1 0 EM1
NOP
END

THERMO58:
TSTLT CT 5:0:0
GOTO THE58SKIP
TSTLT T1 640
CALLSUB HEAT_ON
TSTGT T1 650
CALLSUB HEAT_OFF
THE58SKIP:
RET

HEAT_ON:
SET OP2 1
RET

HEAT_OFF:
SET OP2 0
RET

MAILON:
SET VAR2 0
TSTEQ VAR1 0
GOTO MAILON1
RET

MAILON1:
EMAIL EM2
SET VAR1 1
RET

MAILOFF:
SET VAR1 0
TSTEQ VAR2 0
GOTO MAILOFF1
RET

MAILOFF1:
EMAIL EM3
SET VAR2 1
RET


This will start checking the temperature before 8AM, turn on heat at 64F and turn off heat at 65F.
Like Lou pointed out, if the heat is your house heater, this range will result the heater on and off frequently.
This code only take care your 5AM to 8AM time period. I am sure you can expand this to other time periods, too.
 
I modified your code slightly, incorporate some code Lou wrote:

START
TSTLT CT 8:0:0
CALLSUB THERMO58
TSTEQ OP2 1
CALLSUB MAILON
TSTEQ OP2 0
CALLSUB MAILOFF
TSTEQ OP1[1000] 1
SET OP1 0
TSTGT IP1 0 EM1
NOP
END

THERMO58:
TSTLT CT 5:0:0
GOTO THE58SKIP
TSTLT T1 640
CALLSUB HEAT_ON
TSTGT T1 650
CALLSUB HEAT_OFF
THE58SKIP:
RET

HEAT_ON:
SET OP2 1
RET

HEAT_OFF:
SET OP2 0
RET

MAILON:
SET VAR2 0
TSTEQ VAR1 0
GOTO MAILON1
RET

MAILON1:
EMAIL EM2
SET VAR1 1
RET

MAILOFF:
SET VAR1 0
TSTEQ VAR2 0
GOTO MAILOFF1
RET

MAILOFF1:
EMAIL EM3
SET VAR2 1
RET


This will start checking the temperature before 8AM, turn on heat at 64F and turn off heat at 65F.
Like Lou pointed out, if the heat is your house heater, this range will result the heater on and off frequently.
This code only take care your 5AM to 8AM time period. I am sure you can expand this to other time periods, too.


Hello,

Thank you for your help.

OK, I tried this but has no effect what so ever. It's like it does not see the time at all.

I tried several combinations, like TSTGT CT 17:0:0, because I thought it would scan between midnight 0:0:0 and 17:0:0 so the Greater option appears to be more logical, but that didn't work either.

Please see attachment as I followed the example and changed the time period to the time I was working on this, as you can see from the capture that the OP2 should be on from the displayed temp and what the temp was set to.

I deleted all the other from the program, like the door opening feature to keep it simple in case there was some conflicts, but still not triggering op2.

Any ideas why this isn't working?

Maybe something to do with the firmware version I'm using?

Thanks again for your help.
 

Attachments

  • cai-temp.jpg
    cai-temp.jpg
    98.2 KB · Views: 23
Back
Top