How to program "And" statements into apex

Reefs and Geeks

Well-Known Member
View Badges
Joined
May 2, 2019
Messages
789
Reaction score
800
Location
Transylvania
Rating - 0%
0   0   0
I'm working on programming a secondary heater for my tank that I want to both turn on and off based on the temp reading of the tank (just like the pre-programed heater control) but also only allow the heater to turn on during the night. Does this programming look like it would accomplish that correctly? I have another heater on the tank that is configured normally to allow it to turn on/off 24/7, but has a bit of trouble keeping up with temperature drops at night.

Fallback ON
If Tmp < 77.0 Then ON
If Tmp > 77.8 Then OFF
If Time 11:00 to 23:00 Then OFF

I've read through all of the tutorials a few times, but am still very new to any kind of programming. Looking forward to getting more comfortable with it by setting up and improving my apex programing :)

For future reference, if I want to program an outlet to either turn on or off ONLY if several statements are true or false, how would I do that? An example might be turning the skimmer on only if all 3 of my return pumps are on. I'm sure I'll think of other more complicated situations where I'd want an outlet on or off only if several statements are all true at the same time.
 

homer1475

Figuring out the hobby one coral at a time.
View Badges
Joined
Apr 24, 2018
Messages
11,677
Reaction score
18,662
Location
Way upstate NY
Rating - 0%
0   0   0
if output a = on then on

Output A being the correct name for the skimmer outlet.

For several "and" statements you would probably want to use a virtual outlet.
 

Brett S

Valuable Member
View Badges
Joined
Nov 28, 2016
Messages
1,062
Reaction score
1,373
Location
Orlando
Rating - 0%
0   0   0
I'm working on programming a secondary heater for my tank that I want to both turn on and off based on the temp reading of the tank (just like the pre-programed heater control) but also only allow the heater to turn on during the night. Does this programming look like it would accomplish that correctly? I have another heater on the tank that is configured normally to allow it to turn on/off 24/7, but has a bit of trouble keeping up with temperature drops at night.

Fallback ON
If Tmp < 77.0 Then ON
If Tmp > 77.8 Then OFF
If Time 11:00 to 23:00 Then OFF

Yes, this will do what you want. The lower statements have higher priority, so the if the time is between 11:00 and 23:00 then it will always be off no matter what.

Keep in mind that the Fallback ON means that the heater will have power if the apex brain gets disconnected for any reason. This may be what you want, but it means that you would be relying on the heater’s internal thermostat for temperature control.

I've read through all of the tutorials a few times, but am still very new to any kind of programming. Looking forward to getting more comfortable with it by setting up and improving my apex programing :)

For future reference, if I want to program an outlet to either turn on or off ONLY if several statements are true or false, how would I do that? An example might be turning the skimmer on only if all 3 of my return pumps are on. I'm sure I'll think of other more complicated situations where I'd want an outlet on or off only if several statements are all true at the same time.

The apex language isn’t the most flexible or fully featured language. It can sometimes take a little thought to do what you want. In your example you could set up the program like this:

Fallback ON
Set ON
If Output Return1 = OFF Then OFF
If Output Return2 = OFF Then OFF
If Output Return3 = OFF Then OFF

That would tell the skimmer to be on all the time, but if any of the return pumps are off then the skimmer would be off
 

Brett S

Valuable Member
View Badges
Joined
Nov 28, 2016
Messages
1,062
Reaction score
1,373
Location
Orlando
Rating - 0%
0   0   0
Time statement needs to be first.

Apex evaultaes code line by line and will stop at the first "true" statement it falls on.

Unfortunately this is completely wrong. The apex evaluates code line by line, but each line is evaluated. It doesn’t stop until it gets to the end, so the lower the statement in the program the higher it’s priority. The last ‘true’ statement will be the one that is acted on. If the time statement is first then the temp statements below it will override it.
 

homer1475

Figuring out the hobby one coral at a time.
View Badges
Joined
Apr 24, 2018
Messages
11,677
Reaction score
18,662
Location
Way upstate NY
Rating - 0%
0   0   0
Unfortunately this is completely wrong. The apex evaluates code line by line, but each line is evaluated. It doesn’t stop until it gets to the end, so the lower the statement in the program the higher it’s priority. The last ‘true’ statement will be the one that is acted on. If the time statement is first then the temp statements below it will override it.

Yup I was wrong, (had to go back and read the manual)been a long time since I had to write code for my apex.
 

homer1475

Figuring out the hobby one coral at a time.
View Badges
Joined
Apr 24, 2018
Messages
11,677
Reaction score
18,662
Location
Way upstate NY
Rating - 0%
0   0   0
Fallback ON
Set ON
If Output Return1 = OFF Then OFF
If Output Return2 = OFF Then OFF
If Output Return3 = OFF Then OFF

That would tell the skimmer to be on all the time, but if any of the return pumps are off then the skimmer would be off


Same programming, but I would have used a virtual, so only that virtual had to be referenced in the code. Just how I would have done it, and make my coding page cleaner.
 

Brett S

Valuable Member
View Badges
Joined
Nov 28, 2016
Messages
1,062
Reaction score
1,373
Location
Orlando
Rating - 0%
0   0   0
Same programming, but I would have used a virtual, so only that virtual had to be referenced in the code. Just how I would have done it, and make my coding page cleaner.

Yeah, definitely could be done with a virtual outlet. If it was only going to be referenced once, like for the skimmer then I would probably do it like I had written. But if you had multiple things, like say a skimmer and a reactor and you wanted them all to be off when the return pumps were off then using a virtual outlet could make it a lot easier since you could just reference the same virtual outlet in the program for both the skimmer and the reactor.
 
OP
OP
R

Reefs and Geeks

Well-Known Member
View Badges
Joined
May 2, 2019
Messages
789
Reaction score
800
Location
Transylvania
Rating - 0%
0   0   0
Thanks guys, very useful info :)

I did intend for the fallback to be ON, with the intent that I'd rather both the main and backup heaters be on and rely on their internal thermostats than to turn off and let the tank cool off. Thanks for pointing that out though.

Is there a place where I can just sort of browse through and see what other people have programmed their apex to do to get inspiration for what might be useful for my system? Not that I have an apex, I'm wanting to have it do more and more to make things more automated for me.
 

Brett S

Valuable Member
View Badges
Joined
Nov 28, 2016
Messages
1,062
Reaction score
1,373
Location
Orlando
Rating - 0%
0   0   0
I’m not aware of a place for ideas like that, although it would be kind of interesting. As a bit of a shameless self plug I have done a lot of automation with my apex and it’s all covered in my build thread here:

 
OP
OP
R

Reefs and Geeks

Well-Known Member
View Badges
Joined
May 2, 2019
Messages
789
Reaction score
800
Location
Transylvania
Rating - 0%
0   0   0
I’m not aware of a place for ideas like that, although it would be kind of interesting. As a bit of a shameless self plug I have done a lot of automation with my apex and it’s all covered in my build thread here:

Haha, I'll take it. Thanks! I was always sort of under the impression prior to buying one that the apex was essentially a fancy power outlet with on/off switches on your phone and pH readings. Now that I've had mine for a month or so, I'm seeing the real value in even the more simple programing I have on it. It's one of those things where I just don't know what I don't know.
 
OP
OP
R

Reefs and Geeks

Well-Known Member
View Badges
Joined
May 2, 2019
Messages
789
Reaction score
800
Location
Transylvania
Rating - 0%
0   0   0
In case anyone is wondering, here's a chart of how running the additional heater only at night has worked out. It is keeping my temps more stable for sure. I was manually turning the heater on and off for a bit before getting it programed, but the program seems to be working well.
 

Attachments

  • Temp Chart.PNG
    Temp Chart.PNG
    41.3 KB · Views: 32
Back
Top